Background music delayed when looping

Hey,

I had in my game sounds and background music played with SoundEffectInstance, but sometimes weird bugs appeared, specially when using SoundEffects.Play and SoundEffects.Stop combined immediately, step-by-step. So, I decided to play my long music with Media Player, as recommended. Unfortunatelly, when I loop my background music, there is delay about 1 second between repeats. This is not acceptable.

Song song = CACHED_MUSIC[musicName];
            MediaPlayer.Play(song);
            MediaPlayer.IsRepeating = isLooped;

I set in MGCB processor Song for music and SoundEffect for sounds. Any solutions ? Maybe I should go back with SoundEffects - there was no delay on looping but other tricky bugs…

2 Likes

Up. Anybody ? How you used to play looped background music ?

I too would like to know the answer to this question.

There are threads like the below that seem to suggest that there is no way to remove the delay:

If this is true, I would strongly recommend that future implementations of Monogame look to fix this; this is a major limitation.

If there is a way to remove the delay or a potential workaround, I will be very grateful to hear the answer :slight_smile:

the Song system also skips the end of the song sometimes which I thought it was the actual song but was the MediaPlayer song thingy. I fixed the issue by making all my songs soundfx, settting them to loop, and making them an instance.

Sorry for the topic revive, but I figured it would be better than making a duplicate post.

The cutting off of the end of ogg songs seems to be fixed but the delay between loops appears to still be an issue in 3.7.1

Is just using a SoundEffectInstance to play background music the officially recommended way to go, or are there plans to further improve the MediaPlayer?

There are always plans to fix bugs and improve the library and MediaPlayer definitely needs some work, but there’s only so much we can get done with a small team of core contributors.

Contributions are welcome :slight_smile:

1 Like

That’s understandable! I apologize if my post at all read as snippy - I honestly just wasn’t sure if the MediaPlayer class was meant more to be used as something for a user’s custom playlist (since it looks like it has some functionality for that) or actual baked in background music.

I really appreciate the efforts of all the Monogame developers and how far the framework has come; thank you all for your hard work!!

No worries, it didn’t :slight_smile:

MediaPlayer is meant to be a good way for users to play background music. The difference between MediaPlayer and SoundEffects is that MediaPlayer doesn’t load audio data into memory, but streams from file. Other than that ideally they would be equivalent in terms of features. Of course the API would have to change a lot for that to happen and we’ll have to get a lot of things done to get there. But that’s the end goal.

I’ve been using SoundEffect for playing music and it works okay, but there’s a problem: the generated content files are enormous! My android apk ends up being huge.

I will have to switch back to using Songs and just have a three or four loops baked in and live with the gap.

e: Also considering using this for music instead of monogame: https://www.nuget.org/packages/Xam.Plugin.SimpleAudioPlayer/