出于某种原因,我不能让Monogame通过SoundEffect或SoundEffectInstance播放任何声音。
通过解决方法,我可以播放歌曲,但仍然不是SoundEffects或SoundEffectInstances。
如果我通过“原生XNA”运行我的示例,一切正常。
我正在使用:
Monogame 3.2 for Windows Desktop(DirectX)
Windows 7
Visual Studio Express 2013
示例:
SoundEffect effect;
SoundEffectInstance instance;
Song song;
protected override void LoadContent()
{
// Load sound, no errors and the objects get filled with data.
effect = Content.Load<SoundEffect>("myWavFileAsSoundEffect"); // Loaded with ContentProcessor = "Sound Effect - XNA Framework"
song = Content.Load<Song>("myWavFileAsSong"); // Loaded with ContentProcessor = "Song - XNA Framework"
instance = effect.CreateInstance();
// Set volume to 100%, just in case
SoundEffect.MasterVolume = 1.0f;
MediaPlayer.Volume = 1.0f;
instance.Volume = 1.0f;
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
// Play instance. Nothing happens.
instance.Play();
// Play effect. Nothing happens.
bool success = effect.Play(1.0f, 0.0f, 0.0f);
// success is true
// Play song.
try
{
// Error
// HRESULT: [0x80004002], Module: [General], ApiCode: [E_NOINTERFACE/No such interface supported]
MediaPlayer.Play(song);
}
catch (Exception)
{
// Play the song again
// Plays fine
MediaPlayer.Play(song);
}
}
base.Update(gameTime);
}
有谁知道可能出错了什么?为什么我不能播放任何SoundEffects或SoundEffectInstances?
答案 0 :(得分:1)
我在Windows 10上遇到了完全相同的问题。我的解决方案是重新安装Directx。 Webinstaller:https://www.microsoft.com/en-us/download/details.aspx?id=35&84e4d527-1a2f-c70a-8906-a877ec4baada=1
希望这有帮助
答案 1 :(得分:0)
即使我在添加.wav文件时遇到问题。但是当我添加.xnb文件是在构建XNA项目后生成的(文件在bin \ content文件夹中)时,错误消失了。请你试试xnb文件