Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omxplayer-wrapper: Displaying video sequence based on OSC message #182

Open
Garreta11 opened this issue Jun 29, 2019 · 0 comments
Open

omxplayer-wrapper: Displaying video sequence based on OSC message #182

Garreta11 opened this issue Jun 29, 2019 · 0 comments

Comments

@Garreta11
Copy link

Garreta11 commented Jun 29, 2019

Issue Report

Description

Hi there,
I'm quite new using Python & OMXPLAYER-WRAPPER and some help will be awesome! : ))

The project consist on using TouchOSC to send different osc message to the RaspberryPi and then it will display different video sequences based on the OSC message.

In total there are just two videos --> video1 and video2

The TouchOSC layout will be just three buttons --> action, standby and loop:

  • Action --> it will display video1 and then a loop of the video2 --> video1 + loop(video2)

  • Standby --> it will display a loop of the video2 --> loop(video2)

  • Loop --> it will display a loop of video1 and video2 --> loop(video1 + video2)

I have manage to do each interaction separately, but I have problems when I press one button, and then another one. It's showing both video, or just one video slowly...

This is the code that I've made:

from omxplayer.player import OMXPlayer
from pathlib import Path
from time import sleep
import logging
import argparse
import math
import sys
import os
from subprocess import Popen
from pythonosc import dispatcher
from pythonosc import osc_server

movie1 = ("/home/pi/Videos/action.mp4")
movie2 = ("/home/pi/Videos/standby.mp4")

###################  FUNCTIONS

####  action
def playerExit_action1(code):
  playvideo2_action()

def play_action(unused_addr, args, volume):
  if args[0] == "action" and volume == 1.0:
    print("action")
    player = OMXPlayer(movie1, args=['--no-osd', '--no-keys', '-b'])
    player.exitEvent += lambda _, exit_code: playerExit_action1(exit_code)
         
def playvideo2_action():
  player1 = OMXPlayer(movie2, args=['--no-osd', '--no-keys', '-b'])
  player1.exitEvent += lambda _, exit_code: playerExit_action1(exit_code)


####  standby
def play_standby(unused_addr, args, volume):
  if args[0] == "standby" and volume == 1.0:
    print("standby")
    player2 = OMXPlayer(movie2, args=['--no-osd', '--no-keys', '-b'])
    player2.exitEvent += lambda _, exit_code: playerExit_standby(exit_code)

def playvideo2_standby():
  player3 = OMXPlayer(movie2, args=['--no-osd', '--no-keys', '-b'])
  player3.exitEvent += lambda _, exit_code: playerExit_standby(exit_code)

def playerExit_standby(code):
  playvideo2_standby()
      

####  loop
def play_loop(unused_addr, args, volume):
  if args[0] == "loop" and volume == 1.0:
    print("loop")
    player4 = OMXPlayer(movie1, args=['--no-osd', '--no-keys', '-b'])
    player4.exitEvent += lambda _, exit_code: playerExit_loop1(exit_code)
  

def playvideo1_loop():
  player6= OMXPlayer(movie1, args=['--no-osd', '--no-keys', '-b'])
  player6.exitEvent += lambda _, exit_code: playerExit_loop1(exit_code)
  

def playvideo2_loop():
  player5 = OMXPlayer(movie2, args=['--no-osd', '--no-keys', '-b'])
  player5.exitEvent += lambda _, exit_code: playerExit_loop2(exit_code)
  

def playerExit_loop1(code):
  playvideo2_loop()

def playerExit_loop2(code):
  playvideo1_loop()



##  OSC
if __name__== "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip",
                        default="192.168.1.107")
    parser.add_argument("--port",
                        type=int, default=12000, help=12000)
    args = parser.parse_args()

    dispatcher = dispatcher.Dispatcher()
    dispatcher.map("/btn/push5", play_action, "action")
    dispatcher.map("/btn/push2", play_standby, "standby")
    dispatcher.map("/btn/push4", play_loop, "loop")

    server = osc_server.ThreadingOSCUDPServer(
        (args.ip, args.port), dispatcher)
    print("Serving on {}".format(server.server_address))
    server.serve_forever()

THANKS !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant