-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_sound.py
154 lines (96 loc) · 3.67 KB
/
play_sound.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
146
147
148
149
150
151
152
153
154
"""
Created by *Abdullah EL-Yamany*
Channal => alba4mbarmg - الباشميرمج
Video Link ==>> https://youtu.be/Gnq6RQw1Ca4
note => Design and program play sound App useing python language (Tkinter)
"""
#===============================
from tkinter import *
from tkinter import filedialog
from pygame import mixer
#--------------- Add Song ----------------#
def addSongs():
songsSelection = filedialog.askopenfilenames(initialdir="Music/",
title="Chosse Songs",
filetypes=(("mp3 files", "*.mp3"),)
)
for s in songsSelection :
s = s.replace("/storage.emulated/0/Download/git/play_songs/Music/", " ")
listSongs.insert(END, s)
#--------------- Delete Song ----------------#
def delete_song():
currSong = listSongs.curselection()
listSongs.delete(currSong[0])
#---------------- Play Song Btn ---------------#
def play_song():
song = listSongs.get(ACTIVE)
#song = f"{song}"
mixer.music.load(f"{song}")
mixer.music.play()
#---------------- Stop Song Btn ---------------#
def stop_song():
mixer.music.stop()
listSongs.selection_clear(ACTIVE)
#-------------- Pause Song Btn --------------#
def pause_song():
mixer.music.pause()
#-------------- Resume Song Btn --------------#
def resume_song():
mixer.music.unpause()
#-------------- Prev Song Btn --------------#
def prev_song():
prev = listSongs.curselection()
prev = prev[0]-1
song = listSongs.get(prev)
song = f"{song}"
mixer.music.load(song)
mixer.music.play()
listSongs.selection_clear(0, END)
listSongs.activate(prev)
listSongs.selection_set(prev)
#-------------- Next Song Btn--------------#
def next_song():
next = listSongs.curselection()
next = next[0] + 1
song = listSongs.get(next)
mixer.music.load(f"{song}")
mixer.music.play()
listSongs.selection_clear(0, END)
listSongs.activate(next)
listSongs.selection_set(next)
#--------------- GUI Tkinter ----------------#
window = Tk()
window.title('Play Sound')
mixer.init()
my_menu = Menu(window)
window.config(menu=my_menu)
control_song_menu = Menu(my_menu)
my_menu.add_cascade(label="Menu", menu=control_song_menu, font=('arial', 16))
control_song_menu.add_command(label="Add Song", font=('arial', 14), command=addSongs)
control_song_menu.add_command(label="Delete Song", font=('arial', 14), command=delete_song)
#------------- List GUI To Add Music in This ------------------#
listSongs = Listbox(window,
bg='black',
fg='white',
font=('arial', 13),
width=83,
height=18,
selectmode=SINGLE,
selectbackground='gray',
selectforeground='black'
)
listSongs.grid(columnspan=12)
#------------------ Buttons ------------------#
playBtn = Button(window, text='Play', font=('arial', 15), width=10, height=2, command=play_song)
playBtn.grid(row=1, column=0, pady =8)
pauseBtn = Button(window, text='Pause', font=('arial', 15), width=10, height=2, command=pause_song)
pauseBtn.grid(row=1, column=1)
stopBtn = Button(window, text='Stop', font=('arial', 15), width=10, height=2, command=stop_song)
stopBtn.grid(row=1, column=2)
resumeBtn = Button(window, text='Resume', font=('arial', 15), width=10, height=2, command=resume_song)
resumeBtn.grid(row=1, column=3)
prevBtn = Button(window, text='Prev ⏮', font=('arial', 15), width=10, height=2, command=prev_song)
prevBtn.grid(row=1, column=4)
nextBtn = Button(window, text='Next ⏭', font=('arial', 15), width=10, height=2, command=next_song)
nextBtn.grid(row=1, column=5)
window.mainloop()