Help with threading to control a playback

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with threading to control a playback

pythonist12
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.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

media.rar (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Help with threading to control a playback

Tim Roberts
[hidden email] 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, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

test.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Help with threading to control a playback

pythonist12
Thanks Tim very much for the script I will study it and try to make it work as I want.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help with threading to control a playback

pythonist12
In reply to this post by Tim Roberts
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.

بتاريخ الجمعة، 17 نوفمبر، 2017 9:03:50 م UTC+1، كتب Tim Roberts:
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="O3TFpzPMAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">pytho...@... 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, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="O3TFpzPMAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help with threading to control a playback

Rufus V. Smith
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.



On Nov 20, 2017, at 12:30 PM, [hidden email] wrote:

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.

بتاريخ الجمعة، 17 نوفمبر، 2017 9:03:50 م UTC+1، كتب Tim Roberts:
[hidden email] 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, [hidden email]
Providenza & Boekelheide, Inc.


--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help with threading to control a playback

Tim Roberts
In reply to this post by pythonist12
[hidden email] 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?"

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.