0

I'm using os.startfile code to run .mp3 file but there is an error:

my code is

os.system("Warning.mp3") 

but i get an error like this,

sh: Warning.mp3: command not found 

can you help me about starting mp3 file using os.startfile?

1
  • 2
    Are you actually using os.startfile or are you instead using os.system as your post suggests? Commented Aug 7, 2017 at 13:37

1 Answer 1

1

os.system() makes a call to the system shell to execute the argument you pass. Therefore you get an error message from the shell sh saying that Warning.mp3 is not a command. If you want it to play from shell execution you need to pass it a command which can play a file such as this such as mpg123 on ubuntu/debian (make sure its installed). To invoke this from python:

os.system("mpg123 Warning.mp3") 

See the documentation on the os.system() function for more details. https://docs.python.org/2/library/os.html#os.system

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not familiar with mac, however a quick google search revealed that there may be a built in program called afplay which plays mp3 files. So replace mpg123 with that program and give it a shot. By the way you didn't specify what the application is for this, but this may not be the implementation. This will call an external function in the shell to play music, and playback will be controlled by that program, not python. I haven't used it myself, but theres a python package called playsound you might want to check out. pypi.python.org/pypi/playsound/1.2.1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.