what I want to achieve is this:
- Play background music from the media library
- On a certain trigger, fade out the music, play another mp3 file (of various lengths, seconds up to a minute)
- After that piece of audio is played, resume previous music from the library
Now I run into these constraints:
- In order to access and play music from the user's library, I need to use the MediaPlayer XNA class.
- In order to play an arbitrary mp3 file, I need to use either MediaPlayer or MediaElement, but not SoundEffect or SoundEffectInstance
- If I play anything using the MediaElement, MediaPlayer stops. It completely loses the audio queue so I would need to play the remaining music which would be ok BUT
- MediaPlayer doesn't support seek so I cannot open the previous song and just go the the position before it got paused
So:
- I don't want to use SoundEffect or SoundEffectInstance as the audio would have to be wav files.
- I can't use just MediaPlayer because if I played the audio there to interrupt the song I wouldn't be able to seek to its previous position
- I can't use the combination of MediaPlayer and MediaElement as MediaPlayer stops the MediaPlayer which again prevents me from resuming previous playback
- I can't just use MediaElement because it can't play songs from the library
Do you see anything I missed or is really the only option I have to suck it up and use wav files? (There would be many of these downloaded on the fly and it is just plainly inefficient this way!) Any suggestions?
Thanks!
Unfortunately you've hit a limitation of the platform.
In addition to the alternative you've identified you could play the music streamed from an external source through a MediaElement. By using a timer to keep track of how much has played, when resuming the track start that far through the track by including the start point in your request to the streaming server. This does of course mean you need to provide or find a suitable streaming capability. :(
Neither of these are ideal but for now that's the best we have. The background audio facilites coming in Mango may help but until details are announced we can't say for sure.