Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayUntilFinishedAction #310

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

anodium
Copy link

@anodium anodium commented Jan 18, 2018

This PR adds PlayUntilFinishedAction to the cocos.audio.actions package. As the name states, it's an IntervalAction that doesn't report itself to be done until the sound actually finishes. This is extremely useful for doing actions upon the end of a sound effect.

A real-world example of its utility is in my own project, cinche, where it's already being used here to transition to a new scene the moment the sound effect stops playing.

Additionally, this also makes Effects from cocos.audio.effect exposes a few more properties of the wrapped cocos.audio.SDL.mixer.Sound in order for this to work properly.

@ccanepa
Copy link
Contributor

ccanepa commented Jan 19, 2018

Hi Andrea,
I can see the utility for such an action.
Code seems reasonable for your use case, if using the SDL sound backend

I'm not so sure about if it should be an IntervalAction:

IntervalActions have a deterministic duration, known at instantiation time, and are very well behaved with respect to time: in particular if two actions that are sum of interval actions have same total duration, if they start at the same tick they will end in a future same tick.

This is important in some cases to have specific alignments.

If the play action does not respect the duration, a composite may not be precise.

And the play action can not respect the get_lenght duration, because

  • the authoritative end comes from the player, not the duration
  • get_lenght may be not totally reliable, because start latency and because some audio formats are not so precise about estimating the duration

So maybe it should be an Action, not an IntervalAction

A note for future: From the cocos's API point of view it would be nice to have

  • the same action for the ffmpeg audio/video backend (available from pyglet repo, see announcement at https://groups.google.com/forum/#!topic/pyglet-users/ah2I54BSrZg )

  • when the app selects which audio backend will be used, make available the correct actions / functions etc, ideally with the same signatures. The idea being that user code calls generic apis that will correctly resolve to the selected backend, without need to conditionals ( if SDL...) in user code.

@anodium
Copy link
Author

anodium commented Jan 19, 2018

Claudio,

I had decided not to bother with adding AVbin support for the same reason I'm using the SDL backend in my personal project: last stable release for AVbin was on 23 Aug 2012, which led me to believe that it's been abandoned.

I originally intended to subclass Action, but found that IntervalAction's base implementations of step(self, dt) and done(self) were exactly what I needed for PlayUntilFinishedAction. So, I just subclassed IntervalAction to cut down on duplicated code. I was aware of IntervalAction's promises for timing, but I hadn't realized how strict they were.

I wasn't aware that an ffmpeg backend even existed, since documentation never references it. I might switch to that backend on my personal project once it reaches a stable release. For now, I'll look into adding support for it in this PR, along with AVbin.

@Neon22
Copy link

Neon22 commented Jul 18, 2018

upcoming pyglet 1.4 will move to ffmpeg4 support, abandoning ffmpeg3.x and AVbin.
Working as of now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants