python - mplayer.py 在交互式 python shell 中工作正常,但在脚本中不工作

标签 python mplayer

<分区>

文件在 python shell 中正常播放。脚本中的相同代码未播放,但持续时间正确。怎么了?

>>> import mplayer
>>> p = mplayer.Player()
>>> p.loadfile('announce_vlad.wav')

脚本:

import mplayer
p = mplayer.Player()
p.loadfile('announce_vlad.wav')
print p.length
print p.is_alive()

脚本输出:

5.955873
True

最佳答案

播放器似乎在后台运行,并在您的脚本退出后立即停止。 (在 Python shell 中,这通常不是问题,因为 shell 会在等待您的输入时保持打开状态。)

为了防止播放器过早停止,您需要以某种方式让脚本一直运行,直到播放器结束。一种方法可以做到这一点,因为您已经知道正在播放的剪辑的持续时间,所以可以只在持续时间内使用 sleep()

(可能有更好的方法来做到这一点,但唉,我对 mplayer 还不够熟悉。您可能需要查看 mplayer 文档,看看是否有某种方法可以让播放器唤醒您的脚本播放完毕。)

关于python - mplayer.py 在交互式 python shell 中工作正常,但在脚本中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34100112/

相关文章:

Python : Most efficient way to count elements of long list 1 in long list 2 ?(列表理解真的很慢)

php - 如何通过mplayer或ffmpeg将视频拍照转php?

linux - MPlayer – 在 mplayer.conf 中更改 ‘ao=’ 编解码器顺序似乎不适用于每个用户配置?

Python:使用 mplayer 解析流标题

python - 求10名学生的平均成绩,并增加学生

python - 如何 : XML-RPC dynamic function registration in python?

c - libcaca - 将 ascii 字形更改为片假名

python - 在Raspberry Pi和Python上流式传输YouTube播放列表

python - Matplotlib.pyplot.hist() 很慢

python - 无法让 IDLE 在 Mac 上运行