* Android's InputStream::skip is apparently buggy, so instead read into a dummy buffer
1.1 --- a/include/SDL_rwops.h Thu Oct 13 01:30:01 2011 -0400
1.2 +++ b/include/SDL_rwops.h Fri Oct 14 17:29:49 2011 +0100
1.3 @@ -89,7 +89,6 @@
1.4 void *fileNameRef;
1.5 void *inputStream;
1.6 void *inputStreamRef;
1.7 - void *skipMethod;
1.8 void *readableByteChannel;
1.9 void *readableByteChannelRef;
1.10 void *readMethod;
2.1 --- a/src/core/android/SDL_android.cpp Thu Oct 13 01:30:01 2011 -0400
2.2 +++ b/src/core/android/SDL_android.cpp Fri Oct 14 17:29:49 2011 +0100
2.3 @@ -23,6 +23,8 @@
2.4
2.5 #include "SDL_android.h"
2.6
2.7 +#include <algorithm>
2.8 +
2.9 extern "C" {
2.10 #include "../../events/SDL_events_c.h"
2.11 #include "../../video/android/SDL_androidkeyboard.h"
2.12 @@ -346,11 +348,6 @@
2.13 ctx->hidden.androidio.inputStream = inputStream;
2.14 ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(inputStream);
2.15
2.16 - // Store .skip id for seeking purposes
2.17 - mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream),
2.18 - "skip", "(J)J");
2.19 - ctx->hidden.androidio.skipMethod = mid;
2.20 -
2.21 // Despite all the visible documentation on [Asset]InputStream claiming
2.22 // that the .available() method is not guaranteed to return the entire file
2.23 // size, comments in <sdk>/samples/<ver>/ApiDemos/src/com/example/ ...
2.24 @@ -518,16 +515,21 @@
2.25
2.26 long movement = newPosition - ctx->hidden.androidio.position;
2.27 jobject inputStream = (jobject)ctx->hidden.androidio.inputStream;
2.28 - jmethodID skipMethod = (jmethodID)ctx->hidden.androidio.skipMethod;
2.29
2.30 if (movement > 0) {
2.31 + unsigned char buffer[1024];
2.32 +
2.33 // The easy case where we're seeking forwards
2.34 while (movement > 0) {
2.35 - // inputStream.skip(...);
2.36 - movement -= mEnv->CallLongMethod(inputStream, skipMethod, movement);
2.37 - if (Android_JNI_ExceptionOccurred()) {
2.38 + size_t result = Android_JNI_FileRead(ctx, buffer, 1,
2.39 + std::min(movement, (long)sizeof(buffer)));
2.40 +
2.41 + if (result <= 0) {
2.42 + // Failed to read/skip the required amount, so fail
2.43 return -1;
2.44 }
2.45 +
2.46 + movement -= result;
2.47 }
2.48 } else if (movement < 0) {
2.49 // We can't seek backwards so we have to reopen the file and seek