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

Fix audio source toggle behavior #45

Merged
merged 1 commit into from
Oct 1, 2023
Merged

Fix audio source toggle behavior #45

merged 1 commit into from
Oct 1, 2023

Conversation

GitGhillie
Copy link
Collaborator

Fixes #44

@GitGhillie GitGhillie added the bug Something isn't working label Sep 26, 2023
Comment on lines +57 to +61
if self.event_instance.get_paused().unwrap() {
self.event_instance.set_paused(false).unwrap();
} else {
self.event_instance.start().unwrap();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the if-else is not needed. You can just always set the paused state to false and then start.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the AudioSinkPlayback toggle method should resume the audio if it's paused. toggle calls the AudioSinkPlayback play method when it's currently paused. So if you were to get rid of the if-else you would restart the audio instead of resuming it.

From the Bevy source code:

    /// Toggles the playback of this sink.
    ///
    /// Will pause if playing, and will be resumed if paused.
    fn toggle(&self) {
        if self.is_paused() {
            self.play();
        } else {
            self.pause();
        }
    }

It's a bit of a mismatch between play/start/stop/resume behavior of Bevy Audio and FMOD.
Also they call it play when their intention is to resume the audio:

    /// Resumes playback of a paused sink.
    ///
    /// No effect if not paused.
    fn play(&self);

IMO they should just call it resume then.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I brain farted when writing that comment. You are right.

Copy link
Owner

@Salzian Salzian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it and works as intended.

@GitGhillie GitGhillie merged commit a802636 into main Oct 1, 2023
@GitGhillie GitGhillie deleted the toggle-fix branch October 1, 2023 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toggle stops audio source playback
2 participants