-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_functions.py
180 lines (165 loc) · 5.45 KB
/
player_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
import random
import time
from tkinter import *
from tkinter import Tk
from tkinter import filedialog
from pygame import mixer
# Create a function to open a file
def AddMusic():
global songs
path = filedialog.askdirectory()
if path:
os.chdir(path)
songs = os.listdir()
for song in songs:
if song.endswith(".mp3"):
Playlist.insert(END, song)
# print(songs)
return songs
def PlayMusic():
Music_Name = Playlist.get(ACTIVE)
print(Music_Name[0:-4])
pygame.mixer.music.load(Playlist.get(ACTIVE))
pygame.mixer.music.play()
# def ShuffleMusic():
# global songs
# for song in songs:
# Music_Shuffle = random.choice(songs)
# if song == "System Volume Information":
# continue
# if song == "FOUND.000":
# continue
# print(Music_Shuffle[0:-4])
# pygame.mixer.music.load(Music_Shuffle)
# pygame.mixer.music.play()
# pygame.mixer.music.set_endevent(pygame.USEREVENT) # Register end event
# pygame.event.wait() # Wait for the end event
# def ShuffleMusic():
# global songs
# for song in songs:
# Music_Shuffle = random.choice(songs)
# if song == "System Volume Information":
# continue
# if song == "FOUND.000":
# continue
# print(Music_Shuffle[0:-4])
# pygame.mixer.music.load(Music_Shuffle)
# pygame.mixer.music.play()
# while pygame.mixer.music.get_busy():
# time.sleep(1) # Add a short delay between each check
# def ShuffleMusic():
# global songs
# for song in songs:
# Music_Shuffle = random.choice(songs)
# if song == "System Volume Information":
# continue
# if song == "FOUND.000":
# continue
# print(Music_Shuffle[0:-4])
# pygame.mixer.music.load(Music_Shuffle)
# pygame.mixer.music.play()
# end_event = pygame.USEREVENT + 1
# pygame.mixer.music.set_endevent(end_event)
# event_triggered = False
# while not event_triggered:
# for event in pygame.event.get():
# if event.type == end_event:
# event_triggered = True
# break
# time.sleep(0.1)
def ShuffleMusic():
global songs
for song in songs:
Music_Shuffle = random.choice(songs)
if song == "System Volume Information":
continue
if song == "FOUND.000":
continue
try:
print(Music_Shuffle[0:-4])
mixer.music.load(Music_Shuffle)
mixer.music.play()
end_event = pygame.USEREVENT + 1
mixer.music.set_endevent(end_event)
event_triggered = False
while not event_triggered:
for event in pygame.event.get():
if event.type == end_event:
event_triggered = True
break
time.sleep(0.1)
except (pygame.error, FileNotFoundError) as e:
print(f"Error loading audio file: {Music_Shuffle}")
print(str(e))
# def ShuffleMusic():
# global songs
# while True:
# Music_Shuffle = random.choice(songs)
# if Music_Shuffle == "System Volume Information" or Music_Shuffle == "FOUND.000":
# continue
# try:
# print(Music_Shuffle[0:-4])
# mixer.music.load(Music_Shuffle)
# mixer.music.play()
# end_event = pygame.USEREVENT + 1
# mixer.music.set_endevent(end_event)
# event_triggered = False
# while not event_triggered:
# for event in pygame.event.get():
# if event.type == end_event:
# event_triggered = True
# break
# time.sleep(0.1)
# break # Exit the loop after the first song is played
# except (pygame.error, FileNotFoundError) as e:
# print(f"Error loading audio file: {Music_Shuffle}")
# print(str(e))
def ForwardTrack():
current_index = Playlist.curselection()
if current_index:
next_index = current_index[0] + 1
if next_index < Playlist.size():
Playlist.selection_clear(0, END)
Playlist.selection_set(next_index)
PlayMusic()
def ReverseTrack():
current_index = Playlist.curselection()
if current_index:
prev_index = current_index[0] - 1
if prev_index >= 0:
Playlist.selection_clear(0, END)
Playlist.selection_set(prev_index)
PlayMusic()
# Label Choose mp3
Menu = PhotoImage(file="background.png")
Label(root, image=Menu, bg="#0f1a2b").pack(padx=10, pady=50, side=LEFT)
Frame_Music = Frame(root, bd=2, relief=RIDGE)
Frame_Music.place(x=330, y=350, width=560, height=250)
Button(
root,
text="Open Folder",
width=15,
height=2,
font=("times new roman", 12, "bold"),
fg="Black",
bg="#21b3de",
command=AddMusic,
).place(x=330, y=300)
Scroll = Scrollbar(Frame_Music)
Playlist = Listbox(
Frame_Music,
width=100,
font=("Times new roman", 10),
bg="#333333",
fg="grey",
selectbackground="lightblue",
cursor="hand2",
bd=0,
yscrollcommand=Scroll.set,
)
Scroll.config(command=Playlist.yview)
Scroll.pack(side=RIGHT, fill=Y)
Playlist.pack(side=LEFT, fill=BOTH)
# # Entry point of the program
# if __name__ == "__main__":