#include "MusicManager.h"
#include "const.h"
#include "jail_audio.h"
#include "fileManager.h"

JA_Music music = NULL; //= JA_LoadMusic("intro2.ogg");

void music_init() {
    JA_Init(48000, AUDIO_S16, 2);
	//return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
}

void music_quit() {
	if (music != NULL) JA_DeleteMusic(music);
}

void music_load(const char *musicfilename) {
	if (music != NULL) { 
		JA_StopMusic();
		JA_DeleteMusic(music);
	}
	int filesize = 0;
	const char *buffer = file_getBufferFromResource(musicfilename, filesize);
	
	music = JA_LoadMusic((Uint8*)buffer, filesize);
	//free(buffer);
}

void music_play(const int loops) {
	JA_PlayMusic(music, loops);
}

void music_pause() {
	JA_PauseMusic();
}

void music_fadeOut() {
	JA_StopMusic();
}

const bool music_sonant() {
	return JA_GetMusicState() == JA_MUSIC_PLAYING;
}