-
Notifications
You must be signed in to change notification settings - Fork 1
/
black_player.py
321 lines (281 loc) · 9.35 KB
/
black_player.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# importing required lib
from tkinter import *
import os
from pygame import mixer
import PIL
import stagger
from tkinter import ttk
from PIL import ImageTk
import io
from tkinter.messagebox import showinfo
from tkinter.filedialog import askdirectory
from mutagen.mp3 import MP3
from time import sleep
from pathlib import Path
#functions for opacity
def opacity100():
root.attributes("-alpha", 1)
def opacity90():
root.attributes("-alpha", .9)
def opacity80():
root.attributes("-alpha", .8)
def opacity70():
root.attributes("-alpha", .7)
def opacity60():
root.attributes("-alpha", .6)
def opacity50():
root.attributes("-alpha", .5)
#function to open file
def fileopen():
global st
path =""
try:
path = askdirectory(parent=root,title='Choose directory with mp3')
if path == "":
pass
else:
st = path
playlist.delete(0,'end')
musiclist()
except:
pass
# functions to control volume
def vol():
if scale1.winfo_manager():
scale1.place_forget()
else:
scale1.place(x=110,y=320)
def volume(val):
global currentdir
global st
global vol1
global img1
os.chdir(currentdir)
val1 = float(val)/100
mixer.music.set_volume(val1)
if(val1 == 0.0):
volbutton['image'] = img1
else:
volbutton['image'] = vol1
os.chdir(st)
#function for music list
def musiclist():
global st
os.chdir(st)
# Fetching Songs
songtracks = os.listdir()
# Inserting Songs into Playlist
for track in songtracks:
if track.endswith(".mp3"):
playlist.insert(END,track)
else:
pass
#Buttons
#function for displaying music picture
def musicpic():
global currentdir
global st
global photo
global new_path
try:
mp3 = stagger.read_tag(new_path)
by_data = mp3[stagger.id3.APIC][0].data
im = io.BytesIO(by_data)
imageFile =PIL.Image.open(im)
imageFile = imageFile.resize((260,300 ), PIL.Image.ANTIALIAS)
photo = ImageTk.PhotoImage(imageFile)
label1.image = photo
label1['image'] = photo
except:
os.chdir(currentdir)
photo=PhotoImage(file = "Music-Heart-icon.png")
label1['image'] = photo
os.chdir(st)
#function for play music
def playmusic():
global st
global index
global new_path
global song_
status.set("--playing")
song_ =playlist.get(ACTIVE)
new_path=os.path.join(st , song_)
song.set(song_)
mixer.music.load(song_)
# Playing Selected Song
mixer.music.play()
x = playlist.curselection()
y=()
if(x == y):
x = (0,)
index = x[0]
playbutton.place_forget()
pausebutton.place(x = 110 ,y=15)
musicpic()
#function for pause music
def pausemusic():
status.set("--paused")
mixer.music.pause()
pausebutton.place_forget()
playbutton.place(x = 110 ,y=15)
#function to next the song
def next():
global index
global new_path
playlist.activate(index+1)
song.set(playlist.get(ACTIVE))
song_ = playlist.get(ACTIVE)
new_path=os.path.join(st , song_)
mixer.music.load(playlist.get(ACTIVE))
mixer.music.play()
index = index+1
musicpic()
playbutton.place_forget()
pausebutton.place(x = 110 ,y=15)
#function to play back song
def backcomm():
global index
global new_path
playlist.activate(index-1)
song.set(playlist.get(ACTIVE))
song_ = playlist.get(ACTIVE)
new_path=os.path.join(st , song_)
mixer.music.load(playlist.get(ACTIVE))
mixer.music.play()
index = index-1
musicpic()
playbutton.place_forget()
pausebutton.place(x = 110 ,y=15)
#function for hide the playlist
def hide():
if frame1.winfo_manager():
frame1.place_forget()
root.geometry("600x500")
queuebutton['image'] = arrow2
else :
frame1.place(x=600,y=0,width=400, height = 500)
root.geometry("1000x500")
queuebutton['image'] = arrow1
#funtions for theme-dark,light and grey
def lighttheme():
frame1['bg'] = "white"
musicframe['bg'] = "white"
buttonframe['bg'] = "white"
label1['bg'] = "white"
playbutton['bg'] = "white"
backbutton['bg'] = "white"
pausebutton['bg'] = "white"
forwardbutton['bg'] = "white"
playlist['bg'] = "white"
queuebutton['bg'] ="white"
volbutton['bg'] ="white"
root.configure(background = "white")
def darktheme():
frame1['bg'] = "black"
musicframe['bg'] = "black"
buttonframe['bg'] = "black"
label1['bg'] = "black"
playbutton['bg'] = "black"
backbutton['bg'] = "black"
pausebutton['bg'] = "black"
forwardbutton['bg'] = "black"
playlist['bg'] = "black"
queuebutton['bg'] ="black"
volbutton['bg'] ="black"
root.configure(background = "black")
def greytheme():
frame1['bg'] = "grey"
musicframe['bg'] = "grey"
buttonframe['bg'] = "grey"
label1['bg'] = "grey"
playbutton['bg'] = "grey"
backbutton['bg'] = "grey"
pausebutton['bg'] = "grey"
forwardbutton['bg'] = "grey"
playlist['bg'] = "grey"
queuebutton['bg'] ="grey"
volbutton['bg'] ="grey"
root.configure(background = "grey")
#show about
def about():
showinfo("Music player","by deepanshu tyagi")
#main program
if __name__ == "__main__":
root = Tk()
photo=PhotoImage(file = "images/Music-Heart-icon.png")
root.title("Musicfy")
root.geometry("600x520")
root.iconbitmap('images/music3.ico')
root.resizable(0,0)
root.configure(background= "black")
root.attributes("-alpha", 0.9)
mixer.init()
#buttons images
play = PhotoImage(file = "images/Play.png")
pause = PhotoImage(file = "images/Pause.png")
back = PhotoImage(file = "images/backward.png")
forward =PhotoImage(file = "images/Forward.png")
queuep = PhotoImage(file = "images/interface.png")
arrow1 =PhotoImage(file = "images/arrows(1).png")
arrow2 =PhotoImage(file = "images/arrows.png")
vol1 = PhotoImage(file = "images/vol.png")
img1 = PhotoImage(file = "images/mute1.png")
#variables initialisation
song = StringVar()
song.set("Welcome to Musicfy")
status = StringVar()
index = 0
st = str(os.path.join(Path.home(), "Music"))
currentdir = os.path.abspath(os.getcwd())
new_path = ""
#creating menubar and adding menus
Menu1 = Menu(root)
root.config(menu = Menu1)
filemenu = Menu(root,tearoff = 0)
filemenu.add_command(label="Open",command = fileopen)
Menu1.add_cascade(label="File" ,menu = filemenu)
thememenu = Menu(root,tearoff=0)
thememenu.add_command(label="light",command = lighttheme)
thememenu.add_command(label="dark",command = darktheme)
thememenu.add_command(label="grey",command = greytheme)
filemenu.add_cascade(label="Theme" ,menu = thememenu)
helpmenu = Menu(root, tearoff = 0)
helpmenu.add_command(label="about",command = about)
Menu1.add_cascade(label = "Help",menu = helpmenu)
opacitymenu = Menu(root,tearoff =0)
opacitymenu.add_command(label = "100%",command =opacity100)
opacitymenu.add_command(label = "90%",command =opacity90)
opacitymenu.add_command(label = "80%",command =opacity80)
opacitymenu.add_command(label = "70%",command =opacity70)
opacitymenu.add_command(label = "60%",command =opacity60)
opacitymenu.add_command(label = "50%",command =opacity50)
filemenu.add_cascade(label = "Opacity",menu = opacitymenu)
#creating frame
musicframe = LabelFrame(root,bg = "black" ,relief = GROOVE)
musicframe.place(x=160,y=50,width= 260,height=300)
buttonframe = LabelFrame(root,bg="black",bd =0,relief=GROOVE)
buttonframe.place(x=160,y=400,width=600,height =80)
frame1 = LabelFrame(root,bg ="black", relief = GROOVE)
frame1.place(x=600,y=0,width=400, height = 500)
label1=Label(musicframe,bg = "black",image=photo,bd = 0,relief = GROOVE)
label1.pack(expand = True ,fill = BOTH)
#Label(musicframe ,font = ("times new roman",15,"bold"),bg = "black",fg = "red",bd = 0,relief = GROOVE).grid(row=1,column=2)
label2 =Label(root,text = "Welcome to Musicfy ",textvariable=song,bg = "red",font=("times new roman",11),fg = "black",bd = 0,relief = GROOVE)
label2.pack(side = BOTTOM,fill = BOTH)
#listbox
playlist = Listbox(frame1,selectbackground="gold",selectmode=SINGLE,font=("times new roman",12,"bold"),bg="black",fg="red",bd=5,relief=GROOVE)
playlist.pack(expand =True,fill = BOTH)
musiclist()
playbutton = Button(buttonframe, image =play ,bg = "black" ,bd =0, relief = GROOVE,command =lambda: playmusic())
playbutton.place(x =110 ,y= 15)
pausebutton = Button(buttonframe, image =pause ,bg = "black" ,bd =0, relief = GROOVE,command = pausemusic)
queuebutton = Button(buttonframe,image=queuep,bg = "black",bd=1,relief = GROOVE,command = hide)
queuebutton.place(x=400,y=15)
backbutton = Button(buttonframe, image =back ,bg = "black" ,bd =0, relief = GROOVE,command = backcomm)
backbutton.place(x = 0 ,y = 15)
forwardbutton =Button(buttonframe, image =forward ,bg = "black" ,bd =0, relief = GROOVE,command = next)
forwardbutton.place(x= 215 ,y = 15)
volbutton = Button(root,image = vol1,bg = "black",activebackground = "red",bd = 0,relief = GROOVE,command = vol)
volbutton.place(x=105,y=420)
scale1 = ttk.Scale(root,from_ = 100, to=0 ,orient = VERTICAL , command_ = volume)
root.mainloop()