Search code examples
androidmedia-playerandroid-mediaplayermonogame

Monogame Android MediaPlayer.GameHasControl always returns true


I am writing a game using Monogame for Android.

In my music manager, I have some code like this:

private void ChangeMusic()
{
    if (!MediaPlayer.GameHasControl)
    {
        return;
    }

    // ... Play music
}

I am finding that MediaPlayer.GameHasControl is always returning true, regardless of what is happening on the phone. I have tried playing music in every music app I have on my phone (including Samsung Music player and Google Play Music), and then starting my app, and MediaPlayer.GameHasControl is still true.

Is this expected? Has anyone seen this work before?


Solution

  • Took a look at the MonoGame source, and GameHasControl just isn't even implemented on Android.

    public static bool GameHasControl
    {
        get
        {
    #if IOS
    ...
    #elif WINDOWS_PHONE
    ...
    #else
            // TODO: Fix me!
            return true;
    #endif
        }
    }
    

    Anyone interested in the subject should check out this article:

    http://developer.android.com/training/managing-audio/index.html