-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmediaPlayer.py
More file actions
159 lines (130 loc) · 4.7 KB
/
mediaPlayer.py
File metadata and controls
159 lines (130 loc) · 4.7 KB
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
"""
Program : Media Player Stimulation
Author(s) : 1. Smrity Chaudhary
2. Vipin Kumar
"""
# Import necessary libraries.
from tkinter import *
import pygame
# Import doublyLinkedList file.
from doublyLinkedList import *
# Creating an object of DoublyLinkedList Class.
dlist = Doublylinkedlist()
# Creating object of Tk class.
root = Tk()
pygame.mixer.init()
# -----------------------------------------------------------------------------
# Global Variables for images
backgroundImage = PhotoImage(file="Images/background.png")
stopPhoto = PhotoImage(file="Images/stop.png")
playPhoto = PhotoImage(file="Images/play.png")
pausePhoto = PhotoImage(file="Images/pause.png")
playAgainPhoto = PhotoImage(file="Images/playagain.png")
nextPhoto = PhotoImage(file="Images/next.png")
prevPhoto = PhotoImage(file="Images/prev.png")
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Member Functions
def playMusic():
'''
Objective : Play the music specified by head of dlist.
Input Variables : None
Return Value : None
Approach : Use pygame.mixer.music to load and play the
song.
'''
pygame.mixer.music.load(dlist.head.data)
pygame.mixer.music.play()
def stopMusic():
'''
Objective : Stop the playing music.
Input Variables : None
Return Value : None
Approach : Use pygame.mixer.music to stop the song.
'''
pygame.mixer.music.stop()
def pauseMusic():
'''
Objective : Pause the currently playing song.
Input Variables : None
Return Value : None
Approach : Use pygame.mixer.music to pause the song.
'''
pygame.mixer.music.pause()
def unpauseMusic():
'''
Objective : Unpause the music which is last paused.
Input Variables : None
Return Value : None
Approach : Use pygame.mixer.music to unpause the song.
'''
pygame.mixer.music.unpause()
def prevMusic():
'''
Objective : Play the previous song from the dlist.
Input Variables : None
Return Value : None
Approach : Use pygame.mixer.music to load and play the
song.
'''
pygame.mixer.music.load(dlist.getPrev())
pygame.mixer.music.play()
def nextMusic():
'''
Objective : Play the next song from the dlist.
Input Variables : None
Return Value : None
Approach : Use pygame.mixer.music to load and play the
song.
'''
pygame.mixer.music.load(dlist.getNext())
pygame.mixer.music.play()
def loadMediaPlayer(dirPath):
'''
Objective : Load the name of mp3 file from specified path to dlist.
Input Variables : None
Return Value : None
Approach : Use GetFileName(...) to load mp3 files from specified path.
'''
listFiles = dlist.getFileName(dirPath)
for i in listFiles:
dlist.insert(i)
def mediaPlayerCanvas():
'''
Objective : Draw the media player canvas.
Input Variables : None
Return Value : None
Approach : To draw the canvas, we have used canvas object and
Tkinter objects. Buttons are created using Button(...)
method.
'''
root.title("SV Music")
root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file='Images/mediaPlayer.png'))
canvas = Canvas(root,width = 300,height = 300)
canvas.pack()
canvas.configure(background='black')
canvas.create_image(0,0,image = backgroundImage)
root.configure(background='black')
play = Button(root,image = playPhoto,command = playMusic)
stop = Button(root,image = stopPhoto,command = stopMusic)
pause = Button(root,image = pausePhoto,command = pauseMusic)
unPause = Button(root,image = playAgainPhoto,command = unpauseMusic)
next = Button(root,image = nextPhoto,command = nextMusic)
prev = Button(root,image = prevPhoto,command = prevMusic)
prev.pack(side = LEFT)
play.pack(side = LEFT)
pause.pack(side = LEFT)
stop.pack(side = LEFT)
next.pack(side = LEFT)
unPause.pack(side = RIGHT)
if __name__ == '__main__':
'''
Objective : Main Runner function.
Input Variables : None
Return Value : None
Approach : Invoke the loadMediaPlayer function and mediaPlayerCanvas
funtion.
'''
loadMediaPlayer("C:\\Users\\vkjof\Documents\pythonCodesGitHub")
mediaPlayerCanvas()
root.mainloop()