help with wx.PyTimer

62 views
Skip to first unread message

pytho...@gmail.com

unread,
May 17, 2017, 2:38:07 AM5/17/17
to wxPython-users
Hello.
Can anyone help me with this code.
The idea is to play multiple files with pygame, the play() function work find with single file
I can play, pause, unpause and replay a playback  , but when I try to run a lots of playback the wx do not respond

test2.py

Tim Roberts

unread,
May 17, 2017, 12:54:43 PM5/17/17
to wxpytho...@googlegroups.com
Of course it does. Look at your code in OnOk:

for i in files :
play(i)
while pygame.mixer.music.get_busy():
time.sleep(0.05)

You start playing file #1. Then, you sit in that loop waiting uselessly
until the mixer is idle (meaning until the playback is finished). Then
you start playing file #2, and wait for it to finish. You have
specifically asked for one file at a time here. Further, because this
is in your OnOk handler, your user interface will be totally
non-responsive until ALL the files have finished and this routine
returns. Remember that your message loop cannot handle any messages
until a handler returns.

Pygame is naturally asynchronous, but you are intentionally suppressing
that. If you want to start three files playing at once, then just do that:

for i in files:
play(i)

Don't do any waiting.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

pytho...@gmail.com

unread,
May 18, 2017, 2:40:07 AM5/18/17
to wxPython-users
Thank you for your reply .
But when I did what you said the pygame start directly playing the last file in the list
but the first two files did not play at all
I want to play the three files in a sequence can I do that .

Tim Roberts

unread,
May 18, 2017, 1:53:54 PM5/18/17
to wxpytho...@googlegroups.com
Oh, I thought you wanted to play them all at once. The
pygame.mixer.music interface will only play one file at a time. If you
want to queue up a second file to play after the first one finishes, you
can use pygame.mixer.music.queue, but the queue is only one file deep.
You can try set_endevent to get a callback when the music finishes, but
I don't know if that means "after every file" or "after ALL files".

To get fancier than that, you will have to use the pygame.mixer.Sound
objects instead of the mixer.music interface. That doesn't support MP3,
so you'll have to convert the files to wave files.

pytho...@gmail.com

unread,
May 19, 2017, 3:48:24 AM5/19/17
to wxPython-users
Thank you for your help .
realy I can't use wav I need to use mp3 only .

Tim Roberts

unread,
May 19, 2017, 8:00:13 PM5/19/17
to wxpytho...@googlegroups.com
pytho...@gmail.com wrote:
>
> Thank you for your help .
> realy I can't use wav I need to use mp3 only .

You're not thinking creatively. There are tools available to convert
MP3 to WAV on the fly. You don't have to alter your library of tunes.

As I see it, you have three choices.

1. Convert your MP3s to WAVs on the fly and use pygame.mixer.Sound
2. Decompress the MP3s on your own and feed the buffers to
pygame.mixer.Sound
3. Choose a framework other than pygame

In any case, this no longer has anything to do with wxPython, so your
answers probably lie on another list.
Reply all
Reply to author
Forward
0 new messages