mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-10-11 08:38:15 +03:00
Android: Fix loop parameter handling for CD-DA/MIDI
The semantics of `loop` parameter of start() is very confusing. Added comments in cdrom.h/midi.h to clarify the meaning.
This commit is contained in:
@@ -72,10 +72,10 @@ class GameActivity : SDLActivity() {
|
||||
}
|
||||
|
||||
// These functions are called in the SDL thread by JNI.
|
||||
@Suppress("unused") fun cddaStart(track: Int, loop: Int) = cdda.start(track, loop)
|
||||
@Suppress("unused") fun cddaStart(track: Int, loop: Boolean) = cdda.start(track, loop)
|
||||
@Suppress("unused") fun cddaStop() = cdda.stop()
|
||||
@Suppress("unused") fun cddaCurrentPosition() = cdda.currentPosition()
|
||||
@Suppress("unused") fun midiStart(buf: ByteArray, loop: Int) = midi.start(buf, loop)
|
||||
@Suppress("unused") fun midiStart(buf: ByteArray, loop: Boolean) = midi.start(buf, loop)
|
||||
@Suppress("unused") fun midiStop() = midi.stop()
|
||||
@Suppress("unused") fun midiCurrentPosition() = midi.currentPosition()
|
||||
}
|
||||
@@ -92,18 +92,18 @@ private class CddaPlayer(private val playlistPath: File) {
|
||||
private val player = MediaPlayer()
|
||||
private var playerPaused = false
|
||||
|
||||
fun start(track: Int, loop: Int) {
|
||||
fun start(track: Int, loop: Boolean) {
|
||||
val f = playlist.elementAtOrNull(track)
|
||||
if (f.isNullOrEmpty()) {
|
||||
Log.w("cddaStart", "No playlist entry for track $track")
|
||||
return
|
||||
}
|
||||
Log.v("cddaStart", f)
|
||||
Log.v("cddaStart", "$f Loop:$loop")
|
||||
try {
|
||||
player.apply {
|
||||
reset()
|
||||
setDataSource(File(playlistPath.parent, f).path)
|
||||
isLooping = loop == 0
|
||||
isLooping = loop
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
@@ -148,13 +148,13 @@ private class MidiPlayer {
|
||||
private var playing = false
|
||||
private var playerPaused = false
|
||||
|
||||
fun start(buf: ByteArray, loop: Int) {
|
||||
fun start(buf: ByteArray, loop: Boolean) {
|
||||
val url = "data:audio/midi;base64," + Base64.encodeToString(buf, Base64.DEFAULT)
|
||||
try {
|
||||
player.apply {
|
||||
reset()
|
||||
setDataSource(url)
|
||||
isLooping = loop == 0
|
||||
isLooping = loop
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
|
||||
+2
-2
@@ -57,8 +57,8 @@ int cdrom_start(int trk, int loop) {
|
||||
}
|
||||
jobject context = SDL_AndroidGetActivity();
|
||||
jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
|
||||
"cddaStart", "(II)V");
|
||||
(*env)->CallVoidMethod(env, context, mid, trk, loop);
|
||||
"cddaStart", "(IZ)V");
|
||||
(*env)->CallVoidMethod(env, context, mid, trk, loop == 0);
|
||||
(*env)->PopLocalFrame(env, NULL);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ typedef struct {
|
||||
struct _cdromdevice {
|
||||
int (* init)(char *);
|
||||
int (* exit)(void);
|
||||
// Play through the track loop times. If loop == 0, loops forever.
|
||||
int (* start)(int trk, int loop);
|
||||
int (* stop)(void);
|
||||
int (* getpos)(cd_time *);
|
||||
|
||||
+2
-2
@@ -87,8 +87,8 @@ static int midi_start(int no, int loop, char *data, int datalen) {
|
||||
|
||||
jobject context = SDL_AndroidGetActivity();
|
||||
jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
|
||||
"midiStart", "([BI)V");
|
||||
(*env)->CallVoidMethod(env, context, mid, array, loop);
|
||||
"midiStart", "([BZ)V");
|
||||
(*env)->CallVoidMethod(env, context, mid, array, loop == 0);
|
||||
(*env)->PopLocalFrame(env, NULL);
|
||||
|
||||
midino = no;
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@ typedef struct mididevice mididevice_t;
|
||||
struct mididevice {
|
||||
int (* init)(char *, int);
|
||||
int (* exit)(void);
|
||||
int (* start)(int, int, char*, int);
|
||||
// Play through the music loop times. If loop == 0, loops forever.
|
||||
int (* start)(int no, int loop, char *data, int datalen);
|
||||
int (* stop)(void);
|
||||
int (* pause)(void);
|
||||
int (* unpause)(void);
|
||||
|
||||
Reference in New Issue
Block a user