-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (50 loc) · 1.83 KB
/
main.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
import tkinter as tk
from tkinter import filedialog
import pygame
import os
# Initialize pygame
pygame.init()
# Create the main window
window = tk.Tk()
window.title("Audio Player")
# Create a label to display the current audio file
label = tk.Label(window, text="No file selected")
label.pack()
def play_audio(file_path):
# Load the specified audio file
pygame.mixer.music.load(file_path)
# Play the audio file
pygame.mixer.music.play()
def create_play_button(file_path, parent):
# Extract the file name from the file path
file_name = os.path.basename(file_path)
# Create a button to play the audio file
button = tk.Button(parent, text=file_name, command=lambda: play_audio(file_path))
button.pack()
def stop_audio():
# Fade out the audio over 1000 milliseconds (1 second)
pygame.mixer.music.fadeout(1000)
def browse_audio():
# Open a file dialog to select multiple audio files
file_paths = filedialog.askopenfilenames(filetypes=[("Audio files", "*.mp3;*.wav")])
# Update the label with the selected file names
label.config(text=", ".join(file_paths))
# Create a frame to hold the buttons
frame = tk.Frame(window)
frame.pack()
# Create a button for each selected audio file
for file_path in file_paths:
create_play_button(file_path, frame)
def set_volume(value):
# Set the volume of the currently playing audio file
pygame.mixer.music.set_volume(float(value) / 100)
browse_button = tk.Button(window, text="Browse", command=browse_audio)
browse_button.pack()
stop_button = tk.Button(window, text="Stop", command=stop_audio)
stop_button.pack()
# Create a scale widget to control the volume
volume_scale = tk.Scale(window, from_=0, to=100, orient=tk.HORIZONTAL, command=set_volume)
volume_scale.set(100)
volume_scale.pack()
# Run the main loop
window.mainloop()