2

On Windows Phone 8, I am able to play WAV files with the below code, but not MP3 files. Is there anything special I have to do?

My requirement is to play MP3s one after per user's choice, one after another. I play them all one after another on the same xaml Page. The MP3s are included as Content (copy always).

private void PlayAudioTrack(string audiofilename)
{
    try
    {
        using (var stream = TitleContainer.OpenStream(@"Audio/" + audiofilename))
        {
            var effect = SoundEffect.FromStream(stream);
            FrameworkDispatcher.Update();
            effect.Play();
        }
    }
    catch
    {
       //....
    }             
}
Ry-
  • 218,210
  • 55
  • 464
  • 476
techtinkerer
  • 1,280
  • 2
  • 15
  • 26

3 Answers3

4

I guess the one who originally asked the question has found his workaround. Still I wanted to add this note for other people looking for the same answer.

Here is a detailed walk-through on how to play audio (including mp3) on windoes phone 8:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx

And a list of supported formats:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff462087(v=vs.105).aspx

Playing mp3 worked out fine for me. On both the emulator and device.

Hope this helps someone.

Sayem Shafayet
  • 159
  • 1
  • 10
  • Please summarize the contents of the link in your answer — it makes the answer more useful and protects against link rot. – Ry- Sep 16 '13 at 00:40
2

The XNA SoundEffect class doesn't support MP3, only WAV unfortunately. You'll need to convert your MP3 to WAV first if you want to use this.

James Mundy
  • 4,180
  • 6
  • 35
  • 58
0

I found a cheeky way to play wav files in wp8.1, my app saves wav files.Plus it can share them via email,etc..

While testing, I noticed in onenote,if I send the wav file through the share function of my app, it attaches it. Plus you can play the file back, before sending it,lol.

marcusdev
  • 11
  • 3