c# - 在 Windows Phone 8 App 中播放音效

标签 c# windows-phone-8

我正在使用以下代码播放音频文件,但在代码的第二行出现程序崩溃。可能是什么问题?

这是我使用的代码:

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/

相关文章:

c# - 如何使程序集的后续实例共享相同的内存?

c# - 是否有文件字节的 .NET 包装器?

c# - 在另一个线程上运行时为 "Object reference not set to an instance of an object"

Windows phone 7 新 Windows phone 8 操作系统版本中的应用程序

wpf - 正确的 MVVM 设计模式 - ViewModel 和 DataContext

windows-phone-8 - Windows Phone 8 加速度计模拟敲击

c# - 将对象列表转换为类型数组并删除空值

c# - 如何以编程方式禁用 C# 控制台应用程序快速编辑模式?

c# - 如何运行一个 c# WinForm 应用程序实例?

c# - 是否可以在 BackgroundAudioPlayer 中设置开始和结束位置