-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerMain.py
82 lines (70 loc) · 2.2 KB
/
playerMain.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
from tkinter import *
from tkinter import filedialog
import pygame
root = Tk() # Main window
root.minsize(400, 400) # size of window
label = Label(root, text = "Music PLayer") # text label
label.pack()
listbox = Listbox(root) # text box to show list of songs
listbox.pack()
pygame.mixer.init()
fileName = ""
playlist = [] # to store list of songs
index = 0 # global index to handle playlist
pauseFlag = 1 # global flag to check pause
initPlay = 0
def playSong(event):
global pauseFlag
if pauseFlag == 1:
pygame.mixer.music.unpause()
else:
pygame.mixer.music.play()
pygame.mixer.music.set_endevent(type)
def pauseSong(event):
global pauseFlag
pygame.mixer.music.pause()
pauseFlag=1
def stopSong(event):
pygame.mixer.music.stop()
def nextSong(event):
global index, playlist, pauseFlag
pauseFlag = 0
index += 1
pygame.mixer.music.load(playlist[index])
pygame.mixer.music.play()
def prevSong(event):
global index, playlist, pauseFlag
pauseFlag = 0
index -= 1
pygame.mixer.music.load(playlist[index])
pygame.mixer.music.play()
def browseSong(event):
global index, playlist, fileName, initPlay
root.filename = filedialog.askopenfilename(initialdir="/home/toor/Downloads", title="Select file", filetypes=(("wav files", "*.wav"), ("all files", "*.*")))
fileName = root.filename
playlist.append(fileName)
songName=fileName.split("/")
listbox.insert(END, songName[-1])
if index == 0 and initPlay == 0:
pygame.mixer.music.load(playlist[index])
initPlay = 1
pygame.mixer.music.play()
playButton = Button(root, text = "Play")
playButton.pack()
pauseButton = Button(root, text="Pause")
pauseButton.pack()
stopButton = Button(root, text="stop")
stopButton.pack()
nextButton = Button(root, text="Next")
nextButton.pack()
prevButton = Button(root, text="Previous")
prevButton.pack()
browseButton = Button(root, text = "Browse")
browseButton.pack()
playButton.bind("<Button-1>", playSong)
pauseButton.bind("<Button-1>", pauseSong)
stopButton.bind("<Button-1>", stopSong)
nextButton.bind("<Button-1>", nextSong)
prevButton.bind("<Button-1>", prevSong)
browseButton.bind("<Button-1>", browseSong)
root.mainloop()