I have a mp3 file. I have a background sound file like rain sound or some fire sound. I want to play these two files parallel in the app as well as in background. So that it looks like a single music is playing a story with a background. Please provide any guidance to achieve this.
-
There may be a fifth way to play music in WP - thought I've not tried that - in webbrowser. So one music file goes by background audio and one in webbrowser (of course it won't run in background). I cannot say (haven't tried) if they can run paralel. One of the users [just asked if it's possible](http://stackoverflow.com/questions/21797481/playing-multiple-audio-files-simultaneously-in-wp8) and I remembered that you were looking for something similar. – Romasz Feb 15 '14 at 13:34
1 Answers
AFAIK there are four ways to play audio in WP: BackgroundAudioPlayer, MediaElement, SoundEffect, Microsoft Media Foundation. As for your question:
BackgroundAudioPlayer
- it won't work, as there is only one Instance of BAP on the phone. So to play a different file, you have to change Track's Source, so it won't handle two at the same time.MediaElement
- it's also a bad idea (it won't also run with BAP simultanously), because as MSDN says:When a MediaElement control plays audio or video content, any background sounds or media already playing are halted. The app launches the playback experience when the user taps the control. Only one MediaElement control can operate at a time.
you can try to play many sounds using
SoundEffect
(thougt as Documentation says it can be only a wave file), I won't post code here, because there are already many examples: one, two, threeas for Microsoft Media Foundation: Walkthrough, Programming Guide, Supported file formats