سؤال

I read and tried all the other posts to that topic, but nothing helped. When I try to play music with Mix_PlayChannel() I don't get an error nor do I hear some sound! I tried for hours now and nothing helps. The program just finishes happily. But no sound! I am using Ubuntu 12.04 64bit.

Thanks!

[EDIT]

Here is the code I use:

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

int main(int argc, char** argv)  {

Mix_Music *music = NULL;
Mix_Chunk *wave = NULL;

SDL_Init(SDL_INIT_AUDIO);

int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
int audio_channels = 1;
int audio_buffers = 4096;

if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
    printf("Unable to open audio!\n");
    exit(1);
}

if(Mix_Init(MIX_INIT_MOD) != MIX_INIT_MOD)
    std::cout << "errer";

Mix_Volume(-1, MIX_MAX_VOLUME);

music = Mix_LoadMUS("1.wav");
wave = Mix_LoadWAV("1.wav");

if (music == NULL) {
    std::cout << "Could not load 1.wav\n";
std::cout << Mix_GetError();
}

if (wave == NULL) {
    std::cout << "Could not load 1.wav\n";
std::cout << Mix_GetError();
}

Mix_VolumeChunk(wave, MIX_MAX_VOLUME);
Mix_VolumeMusic(MIX_MAX_VOLUME);

Mix_PlayMusic(music, 0);
std::cout << Mix_GetError();
Mix_FadeInChannelTimed(-1, wave, 0, 100,1);
std::cout << Mix_GetError();

return 1;
}

I try both PlayMusic() and Mix_FadeInChannelTimed(). Both files are loaded correctly but not played. Sound is not muted, wav-file is playable with aplay or other tools. I check with alsamixer that all channels are open and not too low.

هل كانت مفيدة؟

المحلول

I now found out that the program needs to run until the sound has finished playing! I added a usleep() command after the play command and it plays nicely. So that was really mentioned nowhere that PlayMusic() does not keep running.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top