【问题标题】:SDL_mixer wont play sound Raspberry PiSDL_mixer 不会播放声音 Raspberry Pi
【发布时间】:2015-08-30 17:32:40
【问题描述】:

我无法让SDL_Mixer 在树莓派上播放声音。该程序可以编译并构建,但我听到的只是一声短促的吱吱声(像静态的),什么也没有。

有什么想法吗?

#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdio.h>
#include <string>
#include <iostream>

int main()
{
    Mix_Chunk *snd1 = NULL;
    Mix_Music *m = NULL;

    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
        std::cout << "Something went wrong";
    }

    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) < 0) {
        std::cout << "Kunne ikke loade musikk";
    }

    snd1 = Mix_LoadWAV("bicycle_bell.wav");

    if(snd1 == NULL) {
        std::cout << "Fant ikke filen";
    }

    Mix_PlayChannel(-1, snd1, 0);

    Mix_FreeChunk(snd1);
    Mix_Quit();

    return 1;
}

【问题讨论】:

  • 您应该在每次流写入后添加std::endlstd::flush。你的程序可能想告诉你一些事情。
  • 完成,但没有消息。

标签: c++ raspberry-pi sdl sdl-mixer


【解决方案1】:

解决了。程序在声音播放之前终止。

测试简单时:

while(Mix_playing(sound)); 

修复它。

【讨论】:

    猜你喜欢
    • 2016-08-31
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 2011-08-12
    相关资源
    最近更新 更多