mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-09-28 01:48:09 +03:00
Fix MAKO::check_music()
This fixes infinite loop in the opening demo of Only You, waiting for the end of the music.
This commit is contained in:
@@ -195,6 +195,10 @@ private class CddaPlayer(private val playlistPath: File) {
|
||||
private val player = MediaPlayer()
|
||||
private var playerPaused = false
|
||||
|
||||
init {
|
||||
player.setOnCompletionListener { currentTrack = 0 }
|
||||
}
|
||||
|
||||
fun start(track: Int, loop: Boolean) {
|
||||
val f = playlist.elementAtOrNull(track - 1)
|
||||
if (f.isNullOrEmpty()) {
|
||||
@@ -251,6 +255,10 @@ private class MidiPlayer {
|
||||
private var playing = false
|
||||
private var playerPaused = false
|
||||
|
||||
init {
|
||||
player.setOnCompletionListener { playing = false }
|
||||
}
|
||||
|
||||
fun start(path: String, loop: Boolean) {
|
||||
try {
|
||||
player.apply {
|
||||
|
||||
+33
-11
@@ -123,25 +123,47 @@ void MAKO::stop_music()
|
||||
return;
|
||||
|
||||
JNILocalFrame jni(16);
|
||||
if (!jni.env())
|
||||
return;
|
||||
|
||||
if (current_music < 100 && cd_track[current_music]) {
|
||||
jmethodID mid = jni.GetMethodID("cddaStop", "()V");
|
||||
jni.env()->CallVoidMethod(jni.context(), mid);
|
||||
} else {
|
||||
jmethodID mid = jni.GetMethodID("midiStop", "()V");
|
||||
jni.env()->CallVoidMethod(jni.context(), mid);
|
||||
if (jni.env()) {
|
||||
if (current_music < 100 && cd_track[current_music]) {
|
||||
jmethodID cdda = jni.GetMethodID("cddaStop", "()V");
|
||||
jni.env()->CallVoidMethod(jni.context(), cdda);
|
||||
} else {
|
||||
jmethodID mid = jni.GetMethodID("midiStop", "()V");
|
||||
jni.env()->CallVoidMethod(jni.context(), mid);
|
||||
}
|
||||
}
|
||||
|
||||
if (use_fm)
|
||||
if (fm) {
|
||||
SDL_PauseAudio(1);
|
||||
SDL_LockMutex(fm_mutex);
|
||||
fm = nullptr;
|
||||
SDL_UnlockMutex(fm_mutex);
|
||||
}
|
||||
current_music = 0;
|
||||
}
|
||||
|
||||
bool MAKO::check_music()
|
||||
{
|
||||
return current_music != 0;
|
||||
if (!current_music)
|
||||
return false;
|
||||
if (fm) {
|
||||
int mark, loop;
|
||||
SDL_LockMutex(fm_mutex);
|
||||
fm->get_mark(&mark, &loop);
|
||||
SDL_UnlockMutex(fm_mutex);
|
||||
return !loop;
|
||||
}
|
||||
|
||||
JNILocalFrame jni(16);
|
||||
if (!jni.env())
|
||||
return false;
|
||||
if (current_music < 100 && cd_track[current_music]) {
|
||||
jmethodID cdda = jni.GetMethodID("cddaCurrentPosition", "()I");
|
||||
return jni.env()->CallIntMethod(jni.context(), cdda) != 0;
|
||||
} else {
|
||||
jmethodID mid = jni.GetMethodID("midiCurrentPosition", "()I");
|
||||
return jni.env()->CallIntMethod(jni.context(), mid) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MAKO::get_mark(int* mark, int* loop)
|
||||
|
||||
@@ -70,7 +70,15 @@ void MAKO::stop_music()
|
||||
|
||||
bool MAKO::check_music()
|
||||
{
|
||||
return current_music != 0;
|
||||
if (!current_music)
|
||||
return false;
|
||||
if (fm) {
|
||||
int mark, loop;
|
||||
fm->get_mark(&mark, &loop);
|
||||
return !loop;
|
||||
}
|
||||
|
||||
return EM_ASM_INT_V( return xsystem35.cdPlayer.getPosition(); ) != 0;
|
||||
}
|
||||
|
||||
void MAKO::get_mark(int* mark, int* loop)
|
||||
|
||||
+13
-1
@@ -150,12 +150,24 @@ void MAKO::stop_music()
|
||||
mix_music = NULL;
|
||||
smf.clear();
|
||||
}
|
||||
Mix_HookMusic(NULL, NULL);
|
||||
if (fm) {
|
||||
Mix_HookMusic(NULL, NULL);
|
||||
SDL_LockMutex(fm_mutex);
|
||||
fm = nullptr;
|
||||
SDL_UnlockMutex(fm_mutex);
|
||||
}
|
||||
current_music = 0;
|
||||
}
|
||||
|
||||
bool MAKO::check_music()
|
||||
{
|
||||
if (fm) {
|
||||
int mark, loop;
|
||||
SDL_LockMutex(fm_mutex);
|
||||
fm->get_mark(&mark, &loop);
|
||||
SDL_UnlockMutex(fm_mutex);
|
||||
return !loop;
|
||||
}
|
||||
return Mix_PlayingMusic();
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -353,12 +353,24 @@ void MAKO::stop_music()
|
||||
delete music;
|
||||
music = nullptr;
|
||||
}
|
||||
SDL_PauseAudio(1);
|
||||
if (fm) {
|
||||
SDL_PauseAudio(1);
|
||||
SDL_LockMutex(fm_mutex);
|
||||
fm = nullptr;
|
||||
SDL_UnlockMutex(fm_mutex);
|
||||
}
|
||||
current_music = 0;
|
||||
}
|
||||
|
||||
bool MAKO::check_music()
|
||||
{
|
||||
if (fm) {
|
||||
int mark, loop;
|
||||
SDL_LockMutex(fm_mutex);
|
||||
fm->get_mark(&mark, &loop);
|
||||
SDL_UnlockMutex(fm_mutex);
|
||||
return !loop;
|
||||
}
|
||||
return music && music->is_playing();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user