1

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

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

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

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

  • 动作 --> 它将显示 video1,然后是 video2 的循环 --> video1 + loop(video2)
  • 待机 --> 它将显示 video2 的循环 --> loop(video2)
  • Loop --> 它将显示 video1 和 video2 的循环 --> loop(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()

谢谢 !!

4

0 回答 0