In this Python Pyglet article we are going to talk about How To Play Mp3 Songs In Python Pyglet. if you are interested in Python GUI Development, you can check the below links.
check Python GUI Development Tutorials in the below link.
1: PyQt5 GUI Development Tutorials
2: TKinter GUI Development Tutorials
3: Pyside2 GUI Development Tutorials
4: Kivy GUI Development Tutorials
5: TKinter GUI development Tutorials‘
So now this the complete source code for this article
1 2 3 4 5 6 7 |
import pyglet music = pyglet.resource.media('guitar.mp3', streaming=False) music.play() pyglet.app.run() |
First we have imported our Pyglet library.
1 |
import pyglet |
This line of code is for getting the media from the resource, make sure that you have an Mp3 Song in your project directory. as i have already added a guitar mp3.
1 |
music = pyglet.resource.media('guitar.mp3', streaming=False) |
This line of code is for playing the Mp3 Songs
1 |
music.play() |
And finally
1 |
pyglet.app.run() |
This will enter pyglet’s default event loop, and let pyglet respond to application events such as the mouse and keyboard. Your event handlers will now be called as required, and the run() method will return only when all application windows have been closed.
If you are coming from another library, you may be used to writing your own event loop. This is possible to do with pyglet as well, but it is generally discouraged; see The application event loop for details.
Also you can watch the complete video for How To Play Mp3 Songs In Python Pyglet
Subscribe and Get Free Video Courses & Articles in your Email