Skip to content

SimpleAudioPlayer: setting volume to 0 not working on iOS #95

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

Closed
KnoxCameron opened this issue Apr 6, 2022 · 3 comments
Closed

SimpleAudioPlayer: setting volume to 0 not working on iOS #95

KnoxCameron opened this issue Apr 6, 2022 · 3 comments

Comments

@KnoxCameron
Copy link

I have a Xamarin Forms app that I originally tested and released on Android, and am now testing and modifying as required for iOS. I use SimpleAudioPlayer as a simple way of playing audio clips (thanks!).

I need to be able to sometimes play an audio clip silently i.e. the app pauses playback from the user's point of view for the time of the audio clip's length. I do this on Android by simply setting the volume to 0, with code something like this:

if (audioToPlay.PlaySilenceFlag) { MyVolume = 0; PlayerSvc.player.Volume = MyVolume; }

This works fine on Android with the clip playing silently. On iOS, the clip plays at normal volume. My code around this is the same on both platforms. FYI my code sets the volume back to 1 in the playback ended event.

Are you aware of any issue setting volume to 0 on iOS? Or can you suggest a possible cause for this behaviour?

Thanks!

@KnoxCameron
Copy link
Author

In my limited testing, it looks like setting the volume has no effect on the player on iOS. When debugging, it always shows the value of the Volume property of the object as 1.

As a workaround, I am using this code to pause execution for the time it would have played the clip silently:

                                PlayerSvc.player.Load(stream);
                                // SimpleAudioPlayer volume setting doesn't work on iOS
                                if (Device.RuntimePlatform == Device.iOS && MyVolume == 0)
                                {
                                    double speechLengthSecs = PlayerSvc.player.Duration;
                                    // convert to millisecs
                                    int speechLengthMillisecs = Convert.ToInt32(speechLengthSecs * 1000);
                                    await Task.Delay(speechLengthMillisecs);
                                    DoMediaEnded();
                                }
                                else
                                {
                                    PlayerSvc.player.Play();
                                }

@BlueRaja
Copy link

BlueRaja commented Jul 4, 2022

I think this is most likely caused by #107. Try setting the volume after calling Load(...)

@KnoxCameron
Copy link
Author

I think this is most likely caused by #107. Try setting the volume after calling Load(...)

Thanks! That does seem to have fixed the issue for me.

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

No branches or pull requests

2 participants