src/core/android/SDL_android.cpp
changeset 5993 c9cb52d6d864
parent 5982 f324bd81b52c
child 5994 153d15ab3032
     1.1 --- a/src/core/android/SDL_android.cpp	Thu Oct 13 01:30:01 2011 -0400
     1.2 +++ b/src/core/android/SDL_android.cpp	Fri Oct 14 17:29:49 2011 +0100
     1.3 @@ -23,6 +23,8 @@
     1.4  
     1.5  #include "SDL_android.h"
     1.6  
     1.7 +#include <algorithm>
     1.8 +
     1.9  extern "C" {
    1.10  #include "../../events/SDL_events_c.h"
    1.11  #include "../../video/android/SDL_androidkeyboard.h"
    1.12 @@ -346,11 +348,6 @@
    1.13      ctx->hidden.androidio.inputStream = inputStream;
    1.14      ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(inputStream);
    1.15  
    1.16 -    // Store .skip id for seeking purposes
    1.17 -    mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream),
    1.18 -            "skip", "(J)J");
    1.19 -    ctx->hidden.androidio.skipMethod = mid;
    1.20 -
    1.21      // Despite all the visible documentation on [Asset]InputStream claiming
    1.22      // that the .available() method is not guaranteed to return the entire file
    1.23      // size, comments in <sdk>/samples/<ver>/ApiDemos/src/com/example/ ...
    1.24 @@ -518,16 +515,21 @@
    1.25  
    1.26      long movement = newPosition - ctx->hidden.androidio.position;
    1.27      jobject inputStream = (jobject)ctx->hidden.androidio.inputStream;
    1.28 -    jmethodID skipMethod = (jmethodID)ctx->hidden.androidio.skipMethod;
    1.29  
    1.30      if (movement > 0) {
    1.31 +        unsigned char buffer[1024];
    1.32 +
    1.33          // The easy case where we're seeking forwards
    1.34          while (movement > 0) {
    1.35 -            // inputStream.skip(...);
    1.36 -            movement -= mEnv->CallLongMethod(inputStream, skipMethod, movement);
    1.37 -            if (Android_JNI_ExceptionOccurred()) {
    1.38 +            size_t result = Android_JNI_FileRead(ctx, buffer, 1,
    1.39 +                std::min(movement, (long)sizeof(buffer)));
    1.40 +
    1.41 +            if (result <= 0) {
    1.42 +                // Failed to read/skip the required amount, so fail
    1.43                  return -1;
    1.44              }
    1.45 +
    1.46 +            movement -= result;
    1.47          }
    1.48      } else if (movement < 0) {
    1.49          // We can't seek backwards so we have to reopen the file and seek