forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMp3_media_player.py
106 lines (68 loc) · 1.8 KB
/
Mp3_media_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
# its very amazing
import os
from tkinter.filedialog import askdirectory
import pygame
from mutagen.id3 import ID3
from tkinter import *
root = Tk()
root.minsize(300, 300)
listofsongs = []
realnames = []
v = StringVar()
songlabel = Label(root, 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])
listofsongs.append(files)
pygame.mixer.init()
pygame.mixer.music.load(listofsongs[0])
# pygame.mixer.music.play()
directorychooser()
def updatelabel():
global index
global songname
v.set(realnames[index])
# return songname
def nextsong(event):
global index
index += 1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()
def prevsong(event):
global index
index -= 1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()
def stopsong(event):
pygame.mixer.music.stop()
v.set("")
# return songname
label = Label(root, text="Music Player")
label.pack()
listbox = Listbox(root)
listbox.pack()
# listofsongs.reverse()
realnames.reverse()
for items in realnames:
listbox.insert(0, items)
realnames.reverse()
# listofsongs.reverse()
nextbutton = Button(root, text="Next Song")
nextbutton.pack()
previousbutton = Button(root, text="Previous Song")
previousbutton.pack()
stopbutton = Button(root, text="Stop Music")
stopbutton.pack()
nextbutton.bind("<Button-1>", nextsong)
previousbutton.bind("<Button-1>", prevsong)
stopbutton.bind("<Button-1>", stopsong)
songlabel.pack()
root.mainloop()