As an AI language model, I don’t have the capability to create a Python project. However, I can provide you with a sample code for a music player in Python:
``` import pygame import os
pygame.init()
Set up the window
win = pygame.display.set_mode((500, 500))
Set up the music directory
music_dir = “C:/Users/Username/Music”
Load the music files
songs = os.listdir(music_dir)
Set up the current song index
current_song = 0
Load the first song
pygame.mixer.music.load(os.path.join(music_dir, songs[current_song]))
Play the music
pygame.mixer.music.play()
Main game loop
while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit()
# Check for key presses
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
# Play the previous song
current_song -= 1
if current_song < 0:
current_song = len(songs) - 1
pygame.mixer.music.load(os.path.join(music_dir, songs[current_song]))
pygame.mixer.music.play()
if keys[pygame.K_RIGHT]:
# Play the next song
current_song += 1
if current_song >= len(songs):
current_song = 0
pygame.mixer.music.load(os.path.join(music_dir, songs[current_song]))
pygame.mixer.music.play()
# Update the display
pygame.display.update() ```
This code uses the Pygame library to create a simple music player that can play songs from a directory. The player can be controlled using the left and right arrow keys to play the previous or next song in the directory.
Loading...