1

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.

Chris Lavan
  • 23
  • 1
  • 4

2 Answers2

1

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()
Deerenaros
  • 30
  • 7
  • I have no idea what that code is doing, but it looks like it's working. Thank you. – Chris Lavan Feb 23 '15 at 00:48
  • @ChrisLavan this code open new process and pipeline input and output to existing python interpreter. – Deerenaros Feb 23 '15 at 10:00
  • Could you please tell me what is the meaning of **pipes? Also, I'd like to know when mplayer is done playing, and I understand that I can monitor the data going through the pipe, but I have no idea how to achieve this. – Chris Lavan Mar 09 '15 at 16:40
  • @ChrisLavan **pipes mean [unpacking](https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists) – Deerenaros Mar 12 '15 at 15:44
0

Try using the absolute path to the file. If you are running this script in an IDE or debugger, sometimes it can mess up the relative path.

I would try:

import os
from mplayer import Player

player = Player()
abspath = os.path.join(os.path.dirname(__file__), 'asdf.m4a')
player.loadfile(abspath)
Isa Hassen
  • 300
  • 1
  • 9