2017-06-18 17:36:13 +08:00
|
|
|
#include "Music.h"
|
2017-07-04 22:38:33 +08:00
|
|
|
#include "_caster.h"
|
2017-06-18 17:36:13 +08:00
|
|
|
#include "begin_code.h"
|
2017-06-23 13:17:55 +08:00
|
|
|
//private
|
|
|
|
void Music::_set(Mix_Music* p)
|
2017-06-18 17:36:13 +08:00
|
|
|
{
|
|
|
|
_music.reset(p,Mix_FreeMusic);
|
|
|
|
}
|
2017-06-23 13:17:55 +08:00
|
|
|
//private
|
|
|
|
void Music::_clear()
|
2017-06-18 17:36:13 +08:00
|
|
|
{
|
|
|
|
_music.reset();
|
|
|
|
}
|
2017-06-23 13:17:55 +08:00
|
|
|
//private
|
|
|
|
Mix_Music* Music::_get() const
|
2017-06-18 17:36:13 +08:00
|
|
|
{
|
|
|
|
return _music.get();
|
|
|
|
}
|
|
|
|
|
2017-06-23 13:17:55 +08:00
|
|
|
Music::Music(const std::string& Filename)
|
|
|
|
{
|
|
|
|
_set(Mix_LoadMUS(Filename.c_str()));
|
|
|
|
}
|
|
|
|
|
2017-07-04 22:38:33 +08:00
|
|
|
Music::Music(const RWOP& rwop,MusicType musicType)
|
|
|
|
{
|
|
|
|
_set(Mix_LoadMUSType_RW(rwop._get(),_internal::getMixMusicTypeFromMusicType(musicType),0));
|
|
|
|
}
|
|
|
|
|
2017-06-23 13:17:55 +08:00
|
|
|
bool Music::isReady() const
|
|
|
|
{
|
|
|
|
return (_get()!=nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Music::release()
|
|
|
|
{
|
|
|
|
_clear();
|
|
|
|
}
|
|
|
|
|
2017-06-18 17:36:13 +08:00
|
|
|
//static
|
|
|
|
int MusicPlayer::GetDecoderNum()
|
|
|
|
{
|
|
|
|
return Mix_GetNumMusicDecoders();
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::string MusicPlayer::GetDecoderName(int index)
|
|
|
|
{
|
|
|
|
return std::string(Mix_GetMusicDecoder(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::play(Music music, int loops)
|
|
|
|
{
|
|
|
|
m = music;
|
|
|
|
return Mix_PlayMusic(m._get(), loops);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusicPlayer::pause()
|
|
|
|
{
|
|
|
|
Mix_PauseMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusicPlayer::resume()
|
|
|
|
{
|
|
|
|
Mix_ResumeMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusicPlayer::rewind()
|
|
|
|
{
|
|
|
|
Mix_RewindMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::stop()
|
|
|
|
{
|
|
|
|
return Mix_HaltMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::fadeIn(int loops, int ms)
|
|
|
|
{
|
|
|
|
return Mix_FadeInMusic(m._get(), loops, ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MusicPlayer::fadeOut(int ms)
|
|
|
|
{
|
|
|
|
return Mix_FadeOutMusic(ms);
|
|
|
|
}
|
|
|
|
|
2017-06-23 13:17:55 +08:00
|
|
|
bool MusicPlayer::isPlaying() const
|
2017-06-18 17:36:13 +08:00
|
|
|
{
|
|
|
|
return (Mix_PlayingMusic() == 1);
|
|
|
|
}
|
|
|
|
|
2017-06-23 13:17:55 +08:00
|
|
|
bool MusicPlayer::isPaused() const
|
2017-06-18 17:36:13 +08:00
|
|
|
{
|
|
|
|
return (Mix_PausedMusic() == 1);
|
|
|
|
}
|
|
|
|
|
2017-06-23 13:17:55 +08:00
|
|
|
int MusicPlayer::isFading() const
|
2017-06-18 17:36:13 +08:00
|
|
|
{
|
|
|
|
switch (Mix_FadingMusic())
|
|
|
|
{
|
|
|
|
case MIX_NO_FADING:
|
|
|
|
return 0;
|
|
|
|
case MIX_FADING_IN:
|
|
|
|
return 1;
|
|
|
|
case MIX_FADING_OUT:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 13:17:55 +08:00
|
|
|
int MusicPlayer::setPosition(double second)
|
2017-06-18 17:36:13 +08:00
|
|
|
{
|
2017-06-23 13:17:55 +08:00
|
|
|
return Mix_SetMusicPosition(second);
|
2017-06-18 17:36:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "end_code.h"
|