简体   繁体   中英

Windows Phone 8 can play WAV file but not MP3

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
    {
       //....
    }             
}

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM