mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 16:31:48 +01:00
Init
This commit is contained in:
67
Engine/SoundStream.cpp
Normal file
67
Engine/SoundStream.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "base.h"
|
||||
#include <iostream>
|
||||
#include "SoundStream.h"
|
||||
|
||||
SoundStream::SoundStream( const std::string& path )
|
||||
:m_pMixMusic{ Mix_LoadMUS( path.c_str( )) }
|
||||
{
|
||||
if ( m_pMixMusic == nullptr )
|
||||
{
|
||||
std::string errorMsg = "SoundStream: Failed to load " + path + ",\nSDL_mixer Error: " + Mix_GetError( );
|
||||
std::cerr << errorMsg;
|
||||
}
|
||||
}
|
||||
|
||||
SoundStream::~SoundStream( )
|
||||
{
|
||||
Mix_FreeMusic( m_pMixMusic );
|
||||
m_pMixMusic = nullptr;
|
||||
}
|
||||
|
||||
bool SoundStream::IsLoaded( ) const
|
||||
{
|
||||
return m_pMixMusic != nullptr;
|
||||
}
|
||||
|
||||
bool SoundStream::Play(bool repeat ) const
|
||||
{
|
||||
if ( m_pMixMusic != nullptr )
|
||||
{
|
||||
int result{ Mix_PlayMusic( m_pMixMusic, repeat ? -1 : 1 ) };
|
||||
return result == 0 ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundStream::Stop( )
|
||||
{
|
||||
Mix_HaltMusic( );
|
||||
}
|
||||
void SoundStream::Pause( )
|
||||
{
|
||||
Mix_PauseMusic( );
|
||||
}
|
||||
|
||||
void SoundStream::Resume( )
|
||||
{
|
||||
Mix_ResumeMusic( );
|
||||
}
|
||||
|
||||
int SoundStream::GetVolume( )
|
||||
{
|
||||
return Mix_VolumeMusic( -1 );
|
||||
}
|
||||
|
||||
bool SoundStream::IsPlaying( )
|
||||
{
|
||||
return Mix_PlayingMusic( ) == 0 ? false : true;
|
||||
}
|
||||
|
||||
void SoundStream::SetVolume( int value )
|
||||
{
|
||||
Mix_VolumeMusic( value );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user