ads

Simple Music Player advance project Using Python 2024

 Simple Music Player Using Python

Hello friends, do you know that there are many ways to make music players from simple to advanced levels?

Here, we are presenting you with two very very basic music player in python.

One of them is a simple program and the other one is a GUI program.

For the simple program, we have used pygame which is a famous gaming module in python and its use is very simple.

So, you need to install pygame inside your system if you don’t have it.

To install pygame type "pip install pygame" inside cmd.

For the GUI one, you should have tkinter and pygame both.

There are so many small tkinter projects which you can see if you have any problem with tkinter.

So, now let’s see the codes for both programs.

Code for the GUI program

from pygame import mixer

from tkinter import *

root = Tk()

root.geometry("600x300")

mixer.init()

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

def pause():

mixer.music.pause()

def play():

 mixer.music.play()

def resume():

 mixer.music.unpause()

Label(root, text="Welcome to music player", font="lucidia 30 bold").pack()

Button(text="Play", command=play).place(x=200, y=100)

Button(text="Pause", command=pause).place(x=250, y=100)

Button(text="Resume", command=resume).place(x=310, y=100)

Button(text="Quit", command=quit).place(x=380, y=100)

root.mainloop()

Code for simple program

import pygame

from pygame import mixer

 

pygame.init()

mixer.init()

screen = pygame.display.set_mode((600, 400))

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

mixer.music.play()

 

print("Press 'p' to pause 'r' to resume")

print("Press 'q' to quit")

running = True

while running:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            running = False

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_p:

                mixer.music.pause()

            if event.key == pygame.K_r:

                mixer.music.unpause()

            if event.key == pygame.K_q:

                running = False

quit()

Post a Comment

0 Comments