views:

85

answers:

2

Is it possible to open a mp3 file in python (possible using POPEN) and i dont mean to run it in the program i mean as a separate window in media player or whatever just for it to open it when i call the function and if so how. thanks a lot.

+5  A: 

Opening a file with its associated application (Windows only):

import os
os.startfile('my_mp3.mp3')

A link to the documentation can be found here.

ChristopheD
Cool. Wasn't aware of that.
James Roth
it threw an error it said : Traceback (most recent call last): File "C:\Users\matt\Desktop\1.py", line 3, in <module> os.startfile('C:\Users\matt\Desktop\test.mp3')WindowsError: [Error 2] The system cannot find the file specified: 'C:\\Users\\matt\\Desktop\test.mp3'
Matthew Carter
here is the script import os os.startfile('C:\Users\matt\Desktop\test.mp3')
Matthew Carter
@Matthew Carter: you probably need to double your backslashes (`import os ; os.startfile('C:\\Users\\matt\\Desktop\\test.mp3')` or use forward slash...
ChristopheD
wait never mind it worked i thought i needed to put the full path i guess not.
Matthew Carter
In the documentation I linked to it states `os.startfile` by default expects paths starting from the current working directory, although you *can* use absolute paths (the previous comment about the need to double your backslashes still holds true though).
ChristopheD
+1  A: 

Here is the Python docs for Python in Music: http://wiki.python.org/moin/PythonInMusic

Listed there are libraries for opening and playing mp3, amongst other formats.

kobrien