1
votes

This is driving me bonkers! When trying to play a sound or any media element in a windows phone 8 app I get "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"

And that is all it says. If I look at the stack trace it shows: at Windows.UI.Xaml.Controls.MediaElement.Play()

Example code is:

XAML:

MediaElement x:Name="sndClick" Source="Assets/Sounds/Click.wav" Volume="10" AutoPlay="False"

Code: sndClick.play();

I am trying to port a Windows 8 app to Windows Phone 8. The Windows 8 app works perfectly with the exact same code. This must be some issue with the Windows Phone. Everything else works, it just crashes when the phone trys to play media.

Not all the elements that play sounds crash the program, unless you click them a few times. Some elements always crash on the first click. No sounds ever play, even if the program doesn't crash with the exception it never plays any sounds.

ONE time (and only one time) it played the first couple frames of one of the animation files (.wmv) and then crashed.

It is a weird problem. All the code is copied from the working Windows 8 program and everything works except for the media. If I comment out the sound.play()'s and I disable the media player the program works fine.

At first I thought it might be that the resources weren't copying so I set the "Copy to Output Directory" to "Always Copy". No effect.

I tried the simulators and I tried it on physical hardware, it is the same on everything.

It isn't a resource issue, the simulators and the hardware have more than enough system resources, the whole app is only 22mb's.

It's not a codec issue, the animation is a .wmv file and the sounds are all .wav. Both should be natively supported on any windows device.

I have searched around and seen others with similar problems but I haven't seen any solutions. Does anybody know what is causing this issue and how to fix it? I would very much appreciate it.

I am pulling my hair out on this.

Thanks,

-RW

1
Have you tried using '\' in the Source param?chustar
I set the source with the dropdown box under the properties. The source was populated by visual studio. I am sure it is correct.redwizard000

1 Answers

1
votes

OK I fix it.

Windows Phone 8.1 simply hates it when there is more than one MediaElement in the program... Even just playing one at a time throws the error and wont play any sounds.

It is annoying. It is further annoying that it doesn't seem that XNA works in 8.1 (at least I couldn't get it to work)

The solution was to use SharpDX.

Special Thanks to this post: Multiple audio stream in Universal App(Runtime API), XNA SoundEffect replacement

I removed all but one MediaElement and added installed SharpDX and SharpDX Xaudio2 from the package installer thing. Then:

using SharpDX;
using SharpDX.XAudio2;
using SharpDX.IO;
using SharpDX.Multimedia;

private void PlaySound(string strPath)
{
    XAudio2 xAudio = new XAudio2();
    var masteringVoice = new MasteringVoice(xAudio);
    var nativeFileStream = new NativeFileStream(strPath, NativeFileMode.Open, NativeFileAccess.Read, NativeFileShare.Read);

    SoundStream stream = new SoundStream(nativeFileStream);
    var waveFormat = stream.Format;
    AudioBuffer buffer = new AudioBuffer
    {
        Stream = stream.ToDataStream(),
        AudioBytes = (int)stream.Length,
        Flags = BufferFlags.EndOfStream
    };

    var sourceVoice = new SourceVoice(xAudio, waveFormat, true);


    sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
    sourceVoice.Start();
    }

And then just:

PlaySound("Assets/Sounds/Click.wav");

It works quite well! And the one remaining MediaElement that I need for an animation works now. My hair is even starting to grow back (though it is growing back grey).

If anyone else is having this issue, this is the fix. I hope it helps someone.