树莓派 omxplayer 包装器 + Gpio

Posted

技术标签:

【中文标题】树莓派 omxplayer 包装器 + Gpio【英文标题】:Raspberry pi omxplayer wrapper + Gpio 【发布时间】:2017-10-25 06:43:07 【问题描述】:

按下按钮后 Omxplayer 崩溃 我喜欢用按钮改变电影,这是我到目前为止的代码,但是在按下几个按钮后 Omxplayer 崩溃了! 我是树莓派的新手,python 一直在寻找修复但找不到任何东西。欢迎任何帮助。

我得到的错误是:

Traceback (most recent call last):
  File "mygpio.py", line 34, in <module>
    player.load(vida)
  File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 162, in load
  File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 88, in _load_source
  File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 134, in _setup_dbus_connection
SystemError: DBus cannot connect to the OMXPlayer process
#!/usr/bin/env python2
import os.path
from time import sleep
import subprocess
import os
from omxplayer import OMXPlayer
vida = '/home/pi/Videos/testvids/6.mov'
vidb = '/home/pi/Videos/testvids/3.mov'
vidc = '/home/pi/Videos/testvids/t2.mp4'
default = '/home/pi/Videos/testvids/t1.mp4'

import RPi.GPIO as GPIO



#set up GPIO using BCM numbering

GPIO.setmode(GPIO.BCM)
#All Gpio's as input and pull up

GPIO.setup(2, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_UP)


player = OMXPlayer(default,args=['--no-osd','--blank'],)

while True:

      if GPIO.input(2) ==0:

           player.load(vida)
           print("gpio 2")
           player.play()
           #sleep(5)

      if (GPIO.input(3) == 0):

            player.load(vidb)
            print("gpio 3")
            player.play()
           # sleep(5)



      if (GPIO.input(4) == 0):
            player.load(vidc)
            print("gpio 4")
            player.play()
            #sleep(5)



GPIO.cleanup()

【问题讨论】:

我也有同样的问题 - 你解决了吗? 【参考方案1】:

看起来这是包装器中的错误

https://github.com/willprice/python-omxplayer-wrapper/issues/85

【讨论】:

以上是关于树莓派 omxplayer 包装器 + Gpio的主要内容,如果未能解决你的问题,请参考以下文章

树莓派播放视频的播放器omxplayer

用树莓派3B+播放音乐

如何在不使用终端的情况下退出 omxplayer?

树莓派:最好的安排

用树莓派Raspberry Pi和Micro:bit做一个自拍器

设置树莓派屏幕常亮,禁止树莓派屏幕休眠