SFML 音频问题 - 无法打开文件

问题描述 投票:0回答:0

每次我尝试使用 sfml 播放音乐时,我都会遇到一个

Failed to open sound file "" (couldn't open stream)
Failed to play audio stream: sound parameters have not been initialized (call initialize() first)
error. 

我试过将我的音频放在多个地方。目前,我的代码看起来像这样

void PlaySound()
{

    sf::Music music;
    music.openFromFile("fullBattleTheme.wav");
        
    music.play();
}

在这个代码实例中,我在解决方案的根目录中有 wav 文件。

但我也让 openFromFile 尝试不同的目录,以及同一目录的不同实现。

我尝试过的:

music.openFromFile("C:/Users/Angel/source/repos/RockTheStick/fullBattleTheme.wav");
music.openFromFile("C:\\Users\\Angel\\source\\repos\\Rockthestick\\sounds\\fullBattleTheme.wav");
music.openFromFile("C:\\Users\\Angel\\source\\repos\\Rockthestick\\fullBattleTheme.wav");
  • 将 wav 更改为 ogg.
  • 使用声音而不是音乐。
  • 将 wav 文件粘贴到构建应用程序的调试文件夹中。
  • 确保文件不受权限或类似限制

编辑:我尝试在 wmp.h 中使用 PlaySound 函数并使用它工作正常的相同目录。我想继续前进如果我要使用 wmp

,我真的不需要 sfml
c++ windows audio sfml
© www.soinside.com 2019 - 2024. All rights reserved.