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