使用mplayer在python脚本中播放m4a [英] Play m4a in python script with mplayer

查看:757
本文介绍了使用mplayer在python脚本中播放m4a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在发布到URL,下载音频文件(m4a),并尝试使用Python脚本从终端播放它.当我输入

I'm posting to a URL, downloading an audio file (m4a) and trying to play it from the terminal with a Python script. When I type

mplayer asdf.m4a 

在终端上可以正常播放.但是当我执行以下代码

in the terminal it plays fine. But when I execute the following code

from mplayer import Player

player = Player()
player.loadfile('asdf.m4a')

如mplayer指南中所示,出现以下错误:

as shown in the mplayer guide, I get the following errors:

mplayer: could not connect to socket
mplayer: No such file or directory

我已经尝试了好几天了,看来它应该真的很简单.我不知道怎么了我能够使用pygame播放mp3和ogg,但我需要播放m4a,但似乎无法让mplayer为我工作.

I've been trying to figure this out for a couple days now and it seems like it should be real simple. I don't know what's wrong. I was able to use pygame to play mp3's and ogg's but I need to play m4a and I just can't seem to get mplayer to work for me.

我见过的唯一相关问题是建议在mplayer配置文件中添加nolirc = yes.没有帮助.

The only related issues I've seen suggested adding nolirc=yes to the mplayer config file. Didn't help.

任何帮助将不胜感激.

推荐答案

最糟糕的方法,但可能有用:

Worst way, but could be usefull:

from subprocess import Popen, PIPE

pipes = dict(stdin=PIPE, stdout=PIPE, stderr=PIPE)
mplayer = Popen(["mplayer", "asdf.m4a"], **pipes)

# to control u can use Popen.communicate
mplayer.communicate(input=b">")
sys.stdout.flush()

这篇关于使用mplayer在python脚本中播放m4a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆