MediaPlayer.Pause() bug?

MediaPlayer.Pause() seems to work the first time only. Subsequent calls to Pause() after a call to Resume() are ignored. Anyone has experienced this?

Which Platform? It works fine for me on Windows GL.

Windows UWP / DirectX

I’m using latest development build by the way

Hi Arcadenut,
You’re right. I tested it in windows desktop / DirectX and works fine. So, the problem is in UWP apps.

I just ran into this and found a bug report here (UWP only): https://github.com/MonoGame/MonoGame/issues/7113

One workaround is instead of trying to use MediaPlayer.Pause(), take the current Position in the current track before calling MediaPlayer.Stop() to simply stop the music from playing at all.

Then when you’re ready to resume the music, instead of MediaPlayer.Resume(), call MediaPlayer.Play(YOUR_SONG, _savedPausePosition).

This is amazing… Thank you! -Also, I wonder if doing this really really fast could be used to slow down music, if it could be done fast enough to over-come the stuttering.

Wow, I am also just realizing this could be used to switch tracks, but keeping position, so that you could have like 5 variants of the same track, and jump between them, depending on game state…

For my new project (Vlad Circus: Descend into Madness) I gave up MediaPlayer. I’m using all sounds as sound effects. I can mix songs an will avoid all the MediaPlayer troubles.

Moreover, in the Windows version MediaPlayer can play only one song at a time. This is a problem we faced when porting (Nine Witches: Family Disruption) to consoles where the MediaPlayer behaves different as it can play several songs.

The only drawback with using all SoundEffects is that you must start sounds always from the beginning and for songs streaming is not allowed. But, today machines have enogh memory and works fine for me.

I don’t know about the stuttering or performance of setting a start position really fast but the track switching idea to different “mood” versions or something sounds like a good idea.

I also found that the currently playing song can be found in MediaPlayer.Queue.ActiveSong;

So I wrote a class to handle Pause and Resume for UWP:

/// <summary>
/// Due to a Bug with MonoGame and UWP
/// Bug: Detail here: https://github.com/MonoGame/MonoGame/issues/7113
/// This class takes over the control of MediaPlayer Pause and Resume.
/// </summary>
public static class MediaPlayerUWP
{
    static TimeSpan _startPosition = TimeSpan.Zero;
    static Song _lastSong;

    public static void Pause()
    {
        _startPosition = MediaPlayer.PlayPosition;
        _lastSong = MediaPlayer.Queue.ActiveSong;
        MediaPlayer.Stop();
    }

    public static void Resume()
    {
        if (_lastSong == null)
            return;

        MediaPlayer.Play(_lastSong, _startPosition);
    }
}