Play MP3 from UI doesn't work, sound module
cook last edited by
I have a UI with a buttonitem like this:
play_b = ui.ButtonItem(title='play',action=playmp3,enabled=True)
And then it calls to this function:
def playmp3(sender): player = sound.Player('filename') player.play()
Anyway- it won't play.
If I write the same code without a function it does play. But inside a function (UI or no UI) it won't play.
What can I do differently to get this working?
Webmaster4o last edited by
Are there errors? Also, this might require the
omz last edited by
Try declaring the
player = sound.Player('filename') def playmp3(sender): player.play()
In your code,
playeris a local variable in the
playmp3function that gets garbage-collected as soon as the function returns. When the player's memory is deallocated, it also stops playing of course.