-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmp3Player.py
95 lines (64 loc) · 1.74 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
import os
from tkinter import *
from tkinter.filedialog import askdirectory
import pygame
from mutagen.id3 import ID3
frameWindow = Tk()
frameWindow.minsize(300, 300)
# info song
listOfSong = []
realNames = []
v = StringVar()
songLabel = Label(frameWindow, textvariable=v, width=35)
index = 0
def directoryChooser():
directory = askdirectory()
os.chdir(directory)
for files in os.listdir(directory):
if files.endswith(".mp3"):
realdir = os.path.realpath(files)
audio = ID3(realdir)
realNames.append(audio["TIT2"].text[0])
listOfSong.append(files)
pygame.mixer.init()
pygame.mixer.music.load(listOfSong[0])
directoryChooser()
def updateLabel():
global index
v.set(realNames[index])
# return songName
def nextSong(event):
global index
index += 1
pygame.mixer.music.load(listOfSong[index])
pygame.mixer.music.play()
updateLabel()
def prevSong(event):
global index
index -= 1
pygame.mixer.music.load(listOfSong[index])
pygame.mixer.music.play()
updateLabel()
def stopSong(event):
pygame.mixer.music.stop()
v.set("")
# return songName
label = Label(frameWindow, text="music player")
label.pack()
listBox = Listbox(frameWindow)
listBox.pack()
realNames.reverse()
for items in realNames:
listBox.insert(0, items)
realNames.reverse()
nextButton = Button(frameWindow, text="next Song")
nextButton.pack()
previousButton = Button(frameWindow, text="previous song")
previousButton.pack()
stopButton = Button(frameWindow, text="stop")
stopButton.pack()
nextButton.bind("<Button-1>", nextSong)
previousButton.bind("<Button-1>", prevSong)
stopButton.bind("<Button-1>", stopSong)
songLabel.pack()
frameWindow.mainloop()