35 lines
608 B
C++
35 lines
608 B
C++
#include "Music.h"
|
|
|
|
#include "AudioPlayer.h"
|
|
#include "../util/Files.h"
|
|
|
|
Music::Music() {
|
|
}
|
|
|
|
Music::Music(const char *path) {
|
|
loadFromFile(path);
|
|
}
|
|
|
|
Music::~Music() {
|
|
unload();
|
|
}
|
|
|
|
bool Music::isValid() const {
|
|
return _data != nullptr;
|
|
}
|
|
|
|
void Music::loadFromFile(const char *path) {
|
|
unload();
|
|
_length = Files::allocateBufferAndLoadFromFile(path, &_data);
|
|
}
|
|
|
|
void Music::unload() {
|
|
if (_data) {
|
|
if (audioPlayer.isPlaying(*this)) {
|
|
audioPlayer.stopMusic();
|
|
}
|
|
Files::deleteBuffer(_data);
|
|
_length = 0;
|
|
}
|
|
}
|