我正在使用以下代码播放音频文件,但在代码的第二行出现程序崩溃。可能是什么问题?
这是我使用的代码:
Stream stream = TitleContainer.OpenStream("sounds/bonk.mp3");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
运行这段代码时出现的错误是:
An exception of type 'System.ArgumentException' occurred in Microsoft.Xna.Framework.ni.dll but was not handled in user code
最佳答案
您是否尝试过使用 .wav
文件而不是 .mp3
文件作为音效?
documentation SoundEffect.FromStream
有一条关于声音文件要求的说明:
The Stream object must point to the head of a valid PCM wave file. Also, this wave file must be in the RIFF bitstream format.
The audio format has the following restrictions:
- Must be a PCM wave file
- Can only be mono or stereo
- Must be 8 or 16 bit
- Sample rate must be between 8,000 Hz and 48,000 Hz
关于c# - 在 Windows Phone 8 App 中播放音效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17079414/