-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp3player.py
145 lines (127 loc) · 4.79 KB
/
mp3player.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
import os
import webbrowser
from tkinter import *
from tkinter import Tk
from tkinter import filedialog
import winsound
import pygame
#---------Making the Window and Frames----------
root = Tk()#defining the window and storing in the variable roo7t
frame1 = Frame(root)
menu = Menu(frame1)
root.config(menu=menu)
# ---------Various Functions-------------
root.filename=""
root.playlist = []
root.pauseFlag = False
root.songAdded = False
root.i = 0
def newFile():
winsound.Beep(2000,1000) #('frequency','duration')
def openFile():
try:
root.songAdded = True
root.filename = filedialog.askopenfilename(initialdir = "/",title = "Select your cool music track",filetypes = (("mp3 Music Files","*.mp3"),("m4a Music Files","*.m4a")))
root.playlist.append(root.filename)
print(" Added " + root.filename)
root.screenMessage.set("Good! Now Press on the Play Button")
except:
print("Cannot load the music")
def savePlaylist():
print("save Playlist not defined yet")
def playMusic():
if(root.songAdded == False):
root.screenMessage.set("First add some Music Bitch!")
else:
try:
if(root.pauseFlag == True):
pygame.mixer.music.unpause()
else:
print("Playing")
pygame.mixer.init()
pygame.mixer.music.load(root.playlist[root.i])
pygame.mixer.music.play()
root.screenMessage.set("Playing " + root.playlist[root.i])
except:
print("Could not play the music")
def pauseMusic():
if(root.songAdded == False):
root.screenMessage.set("First add some Music Bitch!")
else:
try:
pygame.mixer.music.pause()
root.pauseFlag = True
root.screenMessage.set("Paused")
except:
print("Cannot Pause the Music")
def stopMusic():
if(root.songAdded == False):
root.screenMessage.set("First add some Music Bitch!")
else:
pygame.mixer.music.fadeout(600)
root.screenMessage.set("End of Playback!")
def prevMusic():
if(root.songAdded == False):
root.screenMessage.set("First add some Music Bitch!")
else:
try:
if(root.playlist[root.i - 1]):
root.i -= 1
playMusic()
else:
print("No previous songs")
root.screenMessage.set("No previous songs")
except:
stopMusic()
print("No previous songs")
def nextMusic():
if(root.songAdded == False):
root.screenMessage.set("First add some Music Bitch!")
else:
try:
if(root.playlist[root.i]):
root.i += 1
playMusic()
else:
root.i -= 1
except:
root.screenMessage.set("End of Playback, Please add more songs")
def end():
exit()
#---------Creating Menus----------
subMenu = Menu(menu)
menu.add_cascade(label="Media", menu=subMenu)#Cascading Options on the ToolBar Such as: File Edit
subMenu.add_command(label="Open File", command=openFile)
subMenu.add_separator()
subMenu.add_command(label="Save PlayList", command=savePlaylist)
subMenu.add_separator()
subMenu.add_command(label="exit", command=exit)
contactMenu = Menu(menu)
#---------Creating Tri-color Labels----------
one = Label(root, text="Welcome", bg="orange",fg="white")
one.pack(fill=X)
two = Label(root, text="To Lame Music Player", bg="white",fg="blue")
two.pack(fill=X)
three = Label(root, text="Created By Prajwal", bg="green",fg="white")
three.pack(fill=X)
topFrame = Frame(root)#definig a frame that will contain the Widgets
topFrame.pack()
bottomFrame = Frame(root) #Similarly, definging the next Frame
bottomFrame.pack(side=BOTTOM)
#---------Various Buttons----------
button1 = Button(topFrame, text="Previous", fg="red", command=prevMusic) #Positioning Button as (<FrameName>,<Text to Appear>,<Text Color>)
button1.pack(side=LEFT,padx=5,pady=20)
button2 = Button(topFrame, text="Play",fg="green", command=playMusic)
button2.pack(side=LEFT,padx=5,pady=20)
button3 = Button(topFrame, text="Pause",fg="black", command=pauseMusic)
button3.pack(side=LEFT,padx=5,pady=20)
button5 = Button(topFrame, text="Stop",fg="red", command=stopMusic)
button5.pack(side=LEFT,padx=5,pady=20)
button4 = Button(topFrame, text="Next",fg="blue", command=nextMusic)
button4.pack(side=LEFT,padx=5,pady=20)
#-----------The status Bar--------------
root.screenMessage = StringVar()
label = Message( root, textvariable=root.screenMessage, relief=RAISED )
root.screenMessage.set("Welcome, to Lame Music Player")
label.pack(side=BOTTOM,fill=X)
root.mainloop()#refreshing the window so that it stays on the screen