简体   繁体   English

SDL_mixer不会播放Raspberry Pi的声音

[英]SDL_mixer wont play sound Raspberry Pi

I can't get SDL_Mixer to play sound on the raspberry. 我无法让SDL_Mixer在树莓上播放声音。 The program compiles and builds OK, but all I hear is a short squeak (like static) and nothing. 该程序可以编译并生成OK,但是我听到的只是一阵吱吱声(像静态的一样),什么也没有。

Any ideas? 有任何想法吗?

#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;
}

Solved it. 解决了。 The program terminated before the sound was playing. 程序在声音播放之前终止。

When testing a simple: 测试简单时:

while(Mix_playing(sound)); 

fixed it. 修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM