omxplayer-wrapper:根据OSC消息显示视频序列

时间:2019-06-29 17:08:57

标签: python raspberry-pi3 omxplayer

我是使用Python和OMXPLAYER-WRAPPER的新手,有些帮助真棒! :))

该项目包括使用TouchOSC向RaspberryPi发送不同的osc消息,然后根据OSC消息显示不同的视频序列。

总共只有两个视频-> video1和video2

TouchOSC布局将只有三个按钮->操作,待机和循环:

  • 操作->它将显示video1,然后显示video2的循环-> video1 +循环(video2)
  • 待机->它将显示video2的循环-> loop(video2)
  • 循环->它将显示video1和video2的循环->循环(video1 + video2)

我设法分别进行每种交互,但是按一个按钮然后按另一个按钮时遇到问题。它正在显示两个视频,或仅缓慢显示一个视频...

这是我编写的代码:

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()

谢谢!!

0 个答案:

没有答案