Help with threading to control a playback

45 views
Skip to first unread message

pytho...@gmail.com

unread,
Nov 17, 2017, 4:26:49 AM11/17/17
to wxPython-users
Hello.
I'm stuck again.And I need your help with this script.
When I run a single song it works no problems I can
play pause unpause and replay with no problems , but
when I run more then one song the songs played one after the other but the GUI block and I can't control the playback as the single song.
I fixe that with the threading but it didn't work as I want
what I want is playing more then one song one after the other and in the same time I want to control the playback playing pausing unpausing and replaying
as we can do in the media players .
I tryed a lot and no luck and the pygame.queue didn't work with me
I'm learning to build a media player so I need your help
I hope that I make myself clear and there is no mestakes in writing.
media.rar

Tim Roberts

unread,
Nov 17, 2017, 3:03:50 PM11/17/17
to wxpytho...@googlegroups.com
pytho...@gmail.com wrote:
>
> I'm stuck again.And I need your help with this script.
> When I run a single song it works no problems I can
> play pause unpause and replay with no problems , but
> when I run more then one song the songs played one after the other but
> the GUI block and I can't control the playback as the single song.
...
> I fixe that with the threading but it didn't work as I want
> what I want is playing more then one song one after the other and in
> the same time I want to control the playback playing pausing unpausing
> and replaying
> as we can do in the media players .

If you are just starting out,"pygame is not the right choice.  In order
to do what you want, you need to be able to handle events from your
media player, but pygame doesn't follow the wxPython rules.  Pygame
expects to be in control of your application,  and wxPython also expects
to be in control of your application.  The two modules fight with each
other.

wxPython contains its own media player, wx.media, and it sends normal wx
events.  Attached is a version of your app that uses wx.media to do the
playing.

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

test.py

pytho...@gmail.com

unread,
Nov 19, 2017, 4:14:34 AM11/19/17
to wxPython-users
Thanks Tim very much for the script I will study it and try to make it work as I want.

pytho...@gmail.com

unread,
Nov 20, 2017, 12:30:31 PM11/20/17
to wxPython-users
Hi Tim.
I want to make the onPlay() method to do playing and pausing and resume playing after pausing and replay after finishing playing all in one button
so in the first click on the play button the song start playing.
in the second click the song pause and in the third click the song resume playing
and after finish playing when I click the play button the song start again , how can I do it.
and thank you very much for helpping me.

Rufus Smith

unread,
Nov 20, 2017, 1:48:27 PM11/20/17
to wxpytho...@googlegroups.com
PMBI...

Usually, in an application such as yours, you would save the current "state" of the playback device, for example:
state = 0 # idle/stopped/not playing
state = 1 # playing
state = 2 # fast forward ... etc.

But in your case, you could actually create two overlapping buttons, one being the "play" button and one being the "pause" button.
with one hidden and one shown at any given time.
Each one could show the other and hide itself in the bound routine.
That would simplify the redrawing of whatever graphic you have on the button top.



--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Roberts

unread,
Nov 20, 2017, 2:04:05 PM11/20/17
to wxpytho...@googlegroups.com
pytho...@gmail.com wrote:
>
> I want to make the onPlay() method to do playing and pausing and
> resume playing after pausing and replay after finishing playing all in
> one button
> so in the first click on the play button the song start playing.
> in the second click the song pause and in the third click the song
> resume playing
> and after finish playing when I click the play button the song start
> again , how can I do it.

Just ask yourself, if I as a human being were asked to do this task,
knowing only what the computer knows, how would I do it?  As Rufus said,
you need some way to keep track of what your current "state" is.  Then,
in your button click handler, you just need to make the changes
necessary to move from one state to another.

As a crude example:

IDLE, PLAYING, PAUSED = range(3)

    def __init__(...)
        state = IDLE

    def onButtonClick(...):
        if state == IDLE:
            # Do whatever is necessary to start playing
            state = PLAYING
        elif state == PLAYING:
            # Tell the media control to pause playback
            state = PAUSED
        elif state == PAUSED:
            # Tell the media control to resume playback
            state = PLAYING

When handling an event, you just need to think "what information do I
have that can help me get from where I am to where I need to be?"
Reply all
Reply to author
Forward
0 new messages