Closed nLaykon closed 2 years ago
im using Tkinter as GUI building purely because its built in with python 3 and I don't know any alternatives
The first thing I noticed was that you are calling AudioPlayer() in each of the playm(), pausem() and resumem() functions. That will create a separate AudioPlayer object in each function, instead of all of them working on the same object. You need to save a reference to a single global AudioPlayer object in the playm() function and have the pausem() and resumem() functions use that same reference, instead of creating their own AudioPlayer objects.
Secondly, setting block=True will block the rest of the program from working (including the HCI controls) until the music file has finished playing.
There is an example of a Tkinter music player included with the AudioPlayer source code, see: https://github.com/mjbrusso/AudioPlayer/blob/master/example/playerGUI.py
The first thing I noticed was that you are calling AudioPlayer() in each of the playm(), pausem() and resumem() functions. That will create a separate AudioPlayer object in each function, instead of all of them working on the same object. You need to save a reference to a single global AudioPlayer object in the playm() function and have the pausem() and resumem() functions use that same reference, instead of creating their own AudioPlayer objects.
Secondly, setting block=True will block the rest of the program from working (including the HCI controls) until the music file has finished playing.
There is an example of a Tkinter music player included with the AudioPlayer source code, see: https://github.com/mjbrusso/AudioPlayer/blob/master/example/playerGUI.py
thank you for the reply, unfortunately the music doesn't play in the 1st place if i have block false, i will take the other points and test them out, thanks for the help :)
@reticulatus editing my script to the following fixed my issue, thank you on the input of the global audio player 😄
rom tkinter import filedialog from tkinter import * import math import tkinter.messagebox import audioplayer from audioplayer import AudioPlayer
root = Tk() root.title("Mp3 Player") root.configure(background = 'grey') root.resizable(width=True, height=True) root.geometry("720x480") musicMp3 = filedialog.askopenfilename(parent=root, initialdir="/", title='Please Select a file') aud = audioplayer.AudioPlayer(musicMp3) def pickm(): musicMp3 = filedialog.askopenfilename(parent=root, initialdir="/", title='Please Select a file')
def playm(): aud.play()
def pausem(): aud.stop()
def resumem(): aud.resume()
pickbutton = Button(master=root, text="Pick Song", command=pickm, height=4, width=8, bg='aqua') pickbutton.pack()
playbutton = Button(master=root, text="Play Song", command=playm, height=4, width=8, bg='aqua') playbutton.pack()
pausebutton = Button(master=root, text="Pause", command=pausem, height=4, width=8, bg='aqua') pausebutton.pack()
resumebutton = Button(master=root, text="Resume", command=resumem, height=4, width=8, bg='aqua') resumebutton.pack()
root.mainloop()
Happy to help.
One other thing I noticed was that you call aud.stop() in the pausem() function. This causes the track to start from the beginning when you call resume().
To get it do proper pause/resume, your pausem() function should call aud.pause().
Happy to help.
One other thing I noticed was that you call aud.stop() in the pausem() function. This causes the track to start from the beginning when you call resume().
To get it do proper pause/resume, your pausem() function should call aud.pause().
I'm not having that issue, the pause and resume buttons work as intended. one of us may not have an up to date module
Happy to help. One other thing I noticed was that you call aud.stop() in the pausem() function. This causes the track to start from the beginning when you call resume(). To get it do proper pause/resume, your pausem() function should call aud.pause().
I'm not having that issue, the pause and resume buttons work as intended. one of us may not have an up to date module
that said, I updated it to use aud.pause() anyway
So i'm a student learning Python and i was trying to practice a bit and thought to make a GUI audio player, im having issues with the stop and pause buttons, they dont work at all when i use block=True on play and the music doesnt play when i use block=False
My code is the following: from tkinter import filedialog from tkinter import * import math import tkinter.messagebox import audioplayer from audioplayer import AudioPlayer
root = Tk() root.title("Mp3 Player") root.configure(background = 'grey') root.resizable(width=True, height=True) root.geometry("720x480") musicMp3 = filedialog.askopenfilename(parent=root, initialdir="/", title='Please Select a file') def pickm(): musicMp3 = filedialog.askopenfilename(parent=root, initialdir="/", title='Please Select a file')
def playm(): AudioPlayer(musicMp3).play(block=True)
def pausem(): AudioPlayer(musicMp3).stop()
def resumem(): AudioPlayer(musicMp3).resume()
pickbutton = Button(master=root, text="Pick Song", command=pickm, height=4, width=8, bg='aqua') pickbutton.pack()
playbutton = Button(master=root, text="Play Song", command=playm, height=4, width=8, bg='aqua') playbutton.pack()
pausebutton = Button(master=root, text="Pause", command=pausem, height=4, width=8, bg='aqua') pausebutton.pack()
resumebutton = Button(master=root, text="Resume", command=resumem, height=4, width=8, bg='aqua') resumebutton.pack()
root.mainloop()