【问题标题】:How can I kill omxplayer by Python Subprocess如何通过 Python 子进程杀死 omxplayer
【发布时间】:2014-01-01 18:11:33
【问题描述】:

我正在使用我的 Raspberry Pi GPIO。我将 4 个开关连接到 GPIO。

我要实现的功能是

按住开关1.停止当前电影,播放M01.mp4。

按住开关2.停止当前电影,播放M02.mp4。

...

如果没有按住开关,播放器 M00.mp4 将进入循环。

我刚学了 3 天的 Python。非常感谢您能帮助我提供详细代码。

Popen.Terminate() 或 Kill() 可以杀scratch,为什么不能杀omxplayer?

#!/usr/bin/env python2.7
import subprocess,time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(22, GPIO.IN)
while True:
    if GPIO.input(25) == True:
        time.sleep(1)
        playProcess=subprocess.Popen(['scratch'],stdout=True)
        #Terminate() or Kill() can kill scratch.
        playProcess=subprocess.Popen(['omxplayer','/home/pi/pyStudy/DSCF4021.MP4'],stdout=True)
        #Terminate() or Kill() CAN NOT kill scratch.
        time.sleep(5)
        playProcess.terminate()

【问题讨论】:

    标签: python subprocess raspberry-pi gpio


    【解决方案1】:

    你可以做的最好的事情是通过管道发送命令见下面的例子

    global playProcess
    playProcess=subprocess.Popen(['omxplayer','/home/pi/pyStudy/DSCF4021.MP4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, close_fds=True)
    time.sleep(10)
    playProcess.stdin.write('q')
    

    有时这不起作用,那么您必须进行刷新

    playProcess.stdin.flush()
    

    【讨论】:

      【解决方案2】:

      感谢您提供有关使用 Python 关闭 omxplayer 的提示等。

      使用下面的代码我得到了列出的错误

        streamVideo = subprocess.Popen(['omxplayer', '-o', 'local', 'Media/TestA.mp4'],   stdin=subprocess.PIPE, stdout=subprocess.PIPE,      stderr=subprocess.PIPE, close_fds=True)
        time.sleep(10)
        streamVideo.stdin.write('q')
        streamVideo.stdin.flush()
      

      错误: streamVideo.stdin.write('q') IOError:[Errno 32] 管道损坏

      我如何在 Python 中杀死 omxplayer

      streamVideo = Popen(['omxplayer', '-o', 'local', 'Media/TestA.mp4'])
      time.sleep(10)  # Time for the clip to play
      streamVideo = Popen(['omxplayer', '-i', 'Media/TestA.mp4'])  # Kills the Display
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-22
        • 2010-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-26
        • 2013-06-28
        • 2014-06-19
        相关资源
        最近更新 更多