python怎么播放m4a音乐,使用mplayer在python脚本中播放m4a

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')

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

mplayer: could not connect to socket

mplayer: No such file or directory

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.

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

Any help would be greatly appreciated.

解决方案

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值