Ticker

6/recent/ticker-posts

Advertisement

Create a android music player app using python

 


In this tutorial we're going to learn how to create or build a simple music player by using python tkinter and pygame mixer modules. Pygame is most popular library to build game and bunch of other apps. Pygame has an inbuilt feature called mixer which provide us intuitive syntax on dealing with sounds flies. In other hand tkinter is a versatile and easy to use library  for creating graphical user interface desktop based applications.


 

If you don't have  pygame and tkinter libraries install  on your python. You can simply install by typing "pip install pygame" and "pip install tkinter". So, lets get started.


Source code:

# Import libraries and modules.

from tkinter import *

from pygame import mixer

# Initialize the Mixer

mixer.init()

mixer.music.load("Moonlight.mp3")

# create a function to perform specific tasks:

def play():

mixer.music.play()



def pause():

mixer.music.pause()

def resume():

mixer.music.unpause()

def stop():

mixer.music.stop()



def exit():

app.destroy()

# create a window. change geometry size depending on your window

app = Tk()

app.geometry("1300x2960")

app.title("Beast Music Player")

# import images from directory for icons or you can you own image files.

#Note : images must be in png format.

coverart = PhotoImage(file = "Xxxtentacion.png")

playbtn = PhotoImage(file = "Playbutton.png")

pausebtn = PhotoImage(file = "Pausebtn.png")

forwardbtn = PhotoImage( file = "forward-button.png")

resumebtn= PhotoImage(file = "Resume.png")

rewindbtn = PhotoImage(file ="rewind-button.png")

stopbtn = PhotoImage(file ="stop.png")

favbtn = PhotoImage(file = "fav.png")

shufflebtn = PhotoImage(file ="shuffle.png")

playlist = PhotoImage(file = "playlist.png")

exit = PhotoImage(file = "Back.png")

# create a label for cover art

cover= Label(app, image = coverart, bg = "ghost white").place( x = 400, y = 300)

# create for label for track info .

#Note: given x and y stand for width and height of window. so please change this value depending upon your window size.

Track_info = Label(text = "Moonlight - Xxxtentacion♡", font = "Times 12 bold",bg = "snow", fg = "navy").place(x = 40, y = 1000)

#create a buttons to store comman and images.

Play =Button(image = playbtn, command = play, borderwidth = 0).place(x = 450, y = 1680)

Pause = Button(image = pausebtn, command = pause, borderwidth = 0).place(x = 450, y = 2040)

Stop = Button(image = stopbtn, command = stop, borderwidth = 0).place(x = 130, y = 2040)

forwarButton = Button(image = forwardbtn, borderwidth = 0, ).place(x= 850, y = 1680)

Resume = Button(image = resumebtn, borderwidth = 0, command = resume).place( x = 780, y = 2040)

rewind = Button(image = rewindbtn, borderwidth = 0).place(x = 0, y = 1680)

favorite = Button(image = favbtn, borderwidth = 0).place(x = 900, y = 1320)

shuffle = Button(image = shufflebtn, borderwidth = 0).place(x = -100, y = 1320)

Playlist = Button(image = playlist, borderwidth = 0).place(x = -150, y = 2500)

back = Button(image = exit, borderwidth = 0, command = exit).place(x = 950, y = 2500)

# start the app window

app.mainloop()

Output:



You can also download complete source code :

Music player.py download link


If you finds this tutorial helpful for you then please share with your friends and if you face any problem with  this source code then please let me know in the comment box so I can help you to solve problem as soon as possible.



















Post a Comment

0 Comments