2

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.

beseder
  • 1,352
  • 2
  • 15
  • 25
  • And the channel is not muted? The volume is turned up? Or the output set to headphones while you expect it through speakers, or something similar? – Some programmer dude Jul 04 '13 at 14:15
  • 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. – beseder Jul 08 '13 at 12:33
  • So did you answer your own question? If so, maybe post an answer? .................. I missed this comment. I tried it myself. My compiler warned me that Mix_PlayMusic doesn't take 3 arguments. I threw out the last one, and the sound played fine. – Topological Sort Sep 24 '14 at 15:11

1 Answers1

3

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.

beseder
  • 1,352
  • 2
  • 15
  • 25