diff --git a/config.py b/config.py index 6b24255..bebe8b8 100644 --- a/config.py +++ b/config.py @@ -7,7 +7,7 @@ MP3_FOLDER_PATH = getenv('MP3_FOLDER_PATH') TITLE = 'MP3 Player by ManHinnn0509' -WINDOW_SIZE = "600x300" +WINDOW_SIZE = "600x350" # Allow resize or not RESIZE_H = False diff --git a/controlmenu.py b/controlmenu.py index 0c1dc44..b9879ba 100644 --- a/controlmenu.py +++ b/controlmenu.py @@ -1,3 +1,5 @@ +import random + import tkinter as tk from tkinter import * @@ -7,11 +9,13 @@ class ControlMenu: - PAUSE_TEXT = 'Pause ⏸' - RESUME_TEXT = 'Resume ▶️' + PAUSE_TEXT = "Pause ⏸" + RESUME_TEXT = "Resume ▶️" + + LOOP_ENABLED_TEXT = "Loop 🔁\n(Enabled)" + LOOP_DISABLED_TEXT = "Loop 🔁\n(Disabled)" - LOOP_ENABLED_TEXT = 'Loop 🔁\n(Enabled)' - LOOP_DISABLED_TEXT = 'Loop 🔁\n(Disabled)' + RANDOM_TEXT = "Random" def __init__(self, mp3Player: MP3Player) -> None: self.mp3Player = mp3Player @@ -60,6 +64,14 @@ def __init__(self, mp3Player: MP3Player) -> None: self.loopButton = loopButton self.loopButton.grid(row=4, column=0) + randomButton = Button( + menuFrame, text=self.RANDOM_TEXT, + width=self.buttonWidth, height=self.buttonHeight, + command=self.__playRandomSong + ) + self.randomButton = randomButton + self.randomButton.grid(row=5, column=0) + # Volume slider volumeSlider = Scale( self.menuFrame, @@ -73,7 +85,7 @@ def __init__(self, mp3Player: MP3Player) -> None: volumeSlider.set(int(self.mp3Player.volume * 100)) self.volumeSlider = volumeSlider - self.volumeSlider.grid(row=5, column=0) + self.volumeSlider.grid(row=6, column=0) # Pack the frame self.menuFrame.pack(fill=tk.Y, side='right') @@ -128,4 +140,12 @@ def __changeVolume(self, event): self.mp3Player.volume = volume # CHANGE VOLUME CODE HERE - self.mp3Player.mixer.music.set_volume(volume) \ No newline at end of file + self.mp3Player.mixer.music.set_volume(volume) + + def __playRandomSong(self): + # 0 <= i < len(songList) + i = int(random.randrange(0, len(self.mp3Player.songs))) + + self.mp3Player.songIndex = i + self.mp3Player.playSong() + \ No newline at end of file