问题
I want play a wav file with XAudio2, I have searched on the internet and have some example projects like this: C# XAudio2 Sound Playback for Windows Phone or this: Play wav example but all those playing special wav files, if I replace my wav (converted to MS ADPCM, mono) then CreateSourceVoice
return HRESULT 0x88960001. So what are specials of those wav files? or any other methods to play Wav file with xaudio2 (I'm working on windows phone 8)
回答1:
According to this article, the XAudio2 only supports a subset of the MS ADPCM format: http://msdn.microsoft.com/en-us/library/windows/desktop/ee415711(v=vs.85).aspx
You have to use the adpcmencode tool in the Windows 8 SDK to compress it into something useable
回答2:
So the standard way of playing both sound effects and background music is using the XNA library.
I wrote a blog post on playing async sound in the windows phone that is pretty straight forward
Basically it says this
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework;
static Stream stream1 = TitleContainer.OpenStream("soundeffect.wav");
static SoundEffect sfx = SoundEffect.FromStream(stream1);
static SoundEffectInstance soundEffect = sfx.CreateInstance();
public void playSound(){
FrameworkDispatcher.Update();
soundEffect.Play();
}
Doesn't get any easier than that. To get specific wav requirements look at the MSDN page for supported formats
I also posted a working solution for download on my blog post.
Good luck!
来源:https://stackoverflow.com/questions/20124685/windows-phone-8-xaudio2-wav-file-issue