-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
119 lines (95 loc) · 3.29 KB
/
app.py
File metadata and controls
119 lines (95 loc) · 3.29 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
import tkinter as tk
from tkinter import *
from tkinter import ttk
import pygame
from pygame import mixer
mixer.init()
root = tk.Tk()
root.title('Mp3 Player')
root.geometry('350x400')
canvas = tk.Canvas(root, bg="gray55")
canvas.place(relwidth=1, relheight=1)
frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.80, relheight=0.80, relx=0.1, rely=0.1)
picture = PhotoImage(file = "image_files/music_notes_PNG75.png")
pictureCanvas = Label(frame, image=picture)
pictureCanvas.place(relwidth=0.50, relheight=0.50, relx=0.23, rely=0.15)
#Global variable for play/pause button looping
buttonCounter = 0
playlist = ["mp3_files/song1.mp3","mp3_files/song2.mp3","mp3_files/song3.mp3"]
song = 0
#Play button group
playImage = PhotoImage(file='image_files/play.png')
def playAudio():
global buttonCounter, song, playlist
if buttonCounter == 0:
mixer.music.load(playlist[song])
mixer.music.play()
buttonCounter += 2
playNext()
elif buttonCounter == 1:
mixer.music.unpause()
buttonCounter += 1
playButton = Button(frame, image=playImage, command = playAudio, highlightthickness = 0)
playButton.place(relwidth=.25, relheight=0.10, relx=.25, rely=.9)
#Pause button group
pauseImage = PhotoImage(file='image_files/music-player.png')
def pauseAudio():
global buttonCounter
if buttonCounter == 2:
mixer.music.pause()
buttonCounter -= 1
pauseButton = Button(frame, image=pauseImage, command = pauseAudio, highlightthickness = 0)
pauseButton.place(relwidth=.25, relheight=0.10, relx=.5, rely=.9)
#Skip button group
skipImage = PhotoImage(file='image_files/next.png')
def skipAudio():
global buttonCounter, song
buttonCounter *= 0
song += 1
if(song == len(playlist)):
song = 0
playAudio()
skipButton = Button(frame, image=skipImage, command = skipAudio, highlightthickness = 0)
skipButton.place(relwidth=.25, relheight=0.10, relx=.75, rely=.9)
#Previous button group
previousImage = PhotoImage(file='image_files/previous.png')
def previousAudio():
global buttonCounter, song
buttonCounter *= 0
if(song > 0):
song -= 1
playAudio()
else:
song = len(playlist) - 1
playAudio()
previousButton = Button(frame, image=previousImage, command = previousAudio, highlightthickness = 0)
previousButton.place(relwidth=.25, relheight=0.10, relx=0, rely=.9)
#Queue song (auto)
def playNext():
global buttonCounter, song
pos = pygame.mixer.music.get_pos()
if int(pos) == -1:
buttonCounter *= 0
song += 1
if(song == len(playlist)):
song = 0
playAudio()
root.after(1, playNext)
#Volume slider group
def changeVolume(vol):
volume = float(vol)/100
mixer.music.set_volume(volume)
volumeSlider = ttk.Scale(frame, from_ = 100, to = 0, command = changeVolume, orient=VERTICAL)
style = ttk.Style()
style.theme_use('clam')
style.configure("TScale", gripcount=0,
background="black", darkcolor="grey90", lightcolor="Lightgrey",
troughcolor="white", bordercolor="grey70", arrowcolor="white")
volumeSlider.set(25)
mixer.music.set_volume(25)
volumeSlider.place(relwidth=.05, relheight=0.29, relx=.94, rely=.60)
#Prevent window resizing
root.resizable(False, False)
#Keep program running
root.mainloop()