void SoundManager::PlaySound(const std::string& filename, Player* p, SoundType type) { if (p->getPlayingSound()==true && type == PRIMARY) return; Mix_Chunk* sound = Mix_LoadWAV(filename.c_str()); if (sound == NULL) { printf( "Failed to load Sound: SDL_mixer Error: %s\n", Mix_GetError() ); return; } Mix_VolumeMusic(14); Mix_Fading(MIX_FADING_IN); int channel = Mix_PlayChannel(-1, sound, 0); if (channel == -1) { printf("Unable to play Ogg file: %s\n", Mix_GetError()); return; } if (type==PRIMARY) p->setPlayingSound(true); SoundInfo info; info.chunk = sound; info.type = type; sounds[channel] = info; }
void SoundManager::PlayMusic(const std::string& filename) { if (music!=nullptr) { Mix_FreeMusic(music); music = nullptr; } music = Mix_LoadMUS(filename.c_str()); if (music == NULL) { printf( "Failed to load Music: SDL_mixer Error: %s\n", Mix_GetError() ); return; } Mix_VolumeMusic(14); Mix_Fading(MIX_FADING_IN); if (Mix_PlayMusic(music, 0) == -1) { printf("Unable to play Ogg file: %s\n", Mix_GetError()); return; } }
void AudioPlayer::play() { Mix_VolumeMusic(14); Mix_Fading(MIX_FADING_IN); if(Mix_PlayMusic(music, 0) == -1) { printf("Unable to play Ogg file: %s\n", Mix_GetError()); } }
//is fading in bool CChannel::IsFadingIn() { //return return(Mix_Fading(m_Channel)==MIX_FADING_IN); }
//is fading bool CChannel::IsFading() { //return return(Mix_Fading(m_Channel)==MIX_NO_FADING); }
//is fading out bool CChannel::IsFadingOut() { //return return(Mix_Fading(m_Channel)==MIX_FADING_OUT); }