MonoGame / MonoGame

One framework for creating powerful cross-platform games.
http://www.monogame.net
Other
11.45k stars 2.91k forks source link

MediaPlayer.IsMuted set to false on Android resume #6220

Open trinith opened 6 years ago

trinith commented 6 years ago

Version: MonoGame 3.6 Platform: Android

Steps to reproduce:

  1. Create a MonoGame Android application
  2. Add any mp3 to your Content file
  3. In your LoadContent method, write the following:
    var song = Content.Load<Song>("yourMP3Name");
    MediaPlayer.IsMuted = true;
    MediaPlayer.Volume = 1f;
    MediaPlayer.Play(song);
  4. Start the application on Android.
  5. When the application button is running, hit the power button on your phone (or emulator, either works).
  6. Hit the power button again to bring it back.

Upon resume, the value of MediaPlayer.IsMuted changes to false and the music is audible.

I suspect there might be a way to work around this by trapping some resume event in the GameActivity. I'll give that a whirl and post back here, but I figured I'd log the issue since it's probably not desired behaviour ;)

Thanks!

trinith commented 6 years ago

As a quick update. I've tried adding code to the AndroidGameActivity OnResume and OnPostResume methods to set MediaPlayer.IsMuted to the value it's supposed to be at. What I've noticed is that the following three scenarios occur, seemingly at random:

This sounds like there might be a bit of a race condition going on in here, which makes it a little difficult to work around. I can detect when MediaPlayer.IsMuted is not the value it's supposed to be in an Update method somewhere, but there exists a possibility that there can be an instant where audio is audible when it should not be.

tomspilman commented 6 years ago

@dellis1972 ?