Skip to content Skip to sidebar Skip to footer

Play Mp3 Without Default Player

I'm trying play mp3 without default player use, so I want try pyglet, but nothing works import pyglet music = pyglet.resource.media('D:/folder/folder/audio.mp3') music.play() pyg

Solution 1:

It's because of the way you load the resource. Try this code for instance:

import pyglet

music = pyglet.media.load(r'D:\folder\folder\audio.mp3')
music.play()

pyglet.app.run()

The way this works is that it loads a file and places it in a pyglet.resource.media container. Due to namespaces and other things, the code you wrote is only allowed to load resources from the working directory. So instead, you use pyglet.media.load which is able to load the resource you need into the current namespace (Note: I might be missusing the word "namespace" here, for lack of a better term without looking at the source code of pyglet, this is the best description I could come up with).

You could experiment by placing the .mp3 in the script folder and run your code again but with a relative path:

importpygletmusic= pyglet.resource.media('audio.mp3')
music.play()

pyglet.app.run()

But I'd strongly suggest you use pyglet.media.load() and have a look at the documentation

Post a Comment for "Play Mp3 Without Default Player"