Is it possible to play 2 songs at the same time?

Hello everyone.
I’ve been wondering about this question since I started to use monogame. I’m currently porting my game engine build on top of libGDX to MonoGame, and one feature I’m missing is the ability to play two different songs with independent volume at the same time.
Now I’ve done some googleing about this and some people say that the Android media player doesn’t allow two songs to be played at the same time, so that’s why MonoGame has this limitation, but I was wondering if there’s a method to overcome this, either by changing the monogame source code or anything.
For example, libGDX doesn’t support 3D audio on the core project, but if you’re inside the desktop project you can perform OpenAL calls and implement it yourself without too much work.
This souldn’t be a problem on PC, because I actually have my own implementation for this feature using a library to read ogg files and DynamicSoundEffectInstance.

Any help would be appreciated.

There currently is no support for playing multiple songs from the MediaPlayer at the moment (to my understanding). Of course anything is possible by changing the source code. The good news is that this feature is on the MG 3.9 wishlist, though I don’t expect 3.9 to be released in quite some time.

Ability for playback of multiple MediaPlayer songs

1 Like

Your options are to write custom code for every target platform or to load the music as sound effects which keeps the whole file in memory instead of streaming it.

Here’s a link to how I did this for Windows builds
https://www.hernblog.com/blogs/replacingMonogameSongsWithDirectX.html

1 Like

Oh, that seems interesting.
I’m doing something similar with nVorbis and DynamicSoundEffectInstance, but I couldn’t figure out a metohd to obtain the current playing position.

Since there was access to OpenAL in libGDX, I remember you could obtain the current playing position by doing someting like this.

public float position() {
return AudioStream.position() + AL11.alGetSourcef(sourceID, AL11.AL_SEC_OFFSET);
}

Do you think I could find an equivalent for this method in XAudio?

Curious why no one uses: Content.Load<SoundEffect>(...).Createinstance() ?

or

var instance = sound.CreateInstance()

From there you can loop your audio, play up to maximum of audio effects or music based on your computer hardware which is usually around 128 sound effects up to 256 sound effects.

Songs use OGG files which can be streamed with OggVorbis, so the song isn’t loaded into memory when it’s played. SoundEffects use the WAV file format and are not streamed, so the entire WAV file is loaded into memory. For a song, this is a lot of memory.