java.lang.StringIndexOutOfBoundsException while playing video in videoView : Android v 4.2.1
Asked Answered
T

2

17

I am getting this crash when I play video on videoView in Android version 4.2.1. I found this out specifically on Micromax Canvas A210 device. It is not showing any message where the error is occurring. Is this a bug or something wrong in application? The crash log is as below:

09-18 11:05:53.245: E/AndroidRuntime(2323): FATAL EXCEPTION: main
09-18 11:05:53.245: E/AndroidRuntime(2323): java.lang.StringIndexOutOfBoundsException: length=11; regionStart=0; regionLength=-1
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.String.startEndAndLength(String.java:583)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.String.substring(String.java:1464)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.widget.VideoView.openVideo(VideoView.java:407)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.widget.VideoView$6.surfaceCreated(VideoView.java:730)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.SurfaceView.updateWindow(SurfaceView.java:606)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.SurfaceView.access$000(SurfaceView.java:88)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:692)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer.doCallbacks(Choreographer.java:579)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer.doFrame(Choreographer.java:548)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.os.Handler.handleCallback(Handler.java:725)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.os.Looper.loop(Looper.java:153)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.app.ActivityThread.main(ActivityThread.java:5297)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.reflect.Method.invokeNative(Native Method)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.reflect.Method.invoke(Method.java:511)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at dalvik.system.NativeStart.main(Native Method)

Other versions and devices that I have tested my app on and is working fine are:

Android versions: 4.1.2, 4.2.2, 4.3, 2.3.3, 4.0.3, 4.0.4
Devices: Samsung Galaxy s2, Samsung Galaxy Tab 2 (7" and 10"), Samsung Galaxy s plus, Sony Xperia Tipo dual, Samsung Galaxy Grand (Quatro and Mega), Nexus 4
Tishtisha answered 18/9, 2013 at 6:32 Comment(8)
It doesn't look like the AOSP version of VideoView.openVideo() has any calls to String.substring(), so it must be a vendor-specific bug. It is unlikely that there is anything you can do to work around the issue without knowing what they changed to cause the bug.Demijohn
Yes, I feel the same about being the vendor-specific issue, as I have received the same crash logs from my app on Play Store for the exact same device (Micromax Canvas A210). Are the vendors allowed to change these classes and can't Google do anything about it?Tishtisha
There's a suite of tests (CTS) to ensure the APIs all work as documented, but it can't do comprehensive failure testing. If the vendor decides to put in an unsafe call to substring() that crashes on certain inputs but passes CTS, that's their call. You may want to contact Micromax to make them aware of the issue.Demijohn
Okay, I will post the issue in official forum by Micromax if there is any. Thanks for the explanation.Tishtisha
any solution for this crash??Hexateuch
I'm seeing the same bug reported on all Micromax devices... :/Polarity
No solution, I excluded those devices. At least I won't get any more negative ratings from those users.Dendriform
this device Canvas seems have too much bugs, also in my app I've errors and crashes from nothing running on it, so am not supporting this device.Ursas
C
1

Are you a developer and using Video View in you application. If so try to debug and verify that you provide a valid uri/url to the Video View. Though there is a null check in the openVideo() of the android.widget.VideoView class, the uri may be empty string.

Here is the source of the Video View class for the android version you mentioned.

Cornstarch answered 29/1, 2015 at 16:5 Comment(0)
O
0

I had the same problem and found that it is a micromax specific bug while using videoview. here's an alternate way to do it using "TextureView" in android

BackGroundVideo.java

public class BackGroundVideo extends AppCompatActivity implements TextureView.SurfaceTextureListener {
ProfileTracker profileTracker;
private MediaPlayer mMediaPlayer;
private TextureView mTextureView;
private static final String TAG = sus.class.getName();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_layout);

    initView();

}

private void initView() {
    mTextureView = (TextureView) findViewById(R.id.play_video_texture);
    // SurfaceTexture is available only after the TextureView
    // is attached to a window and onAttachedToWindow() has been invoked.
    // We need to use SurfaceTextureListener to be notified when the SurfaceTexture
    // becomes available.
    mTextureView.setSurfaceTextureListener(this);
}







@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
    Surface surface = new Surface(surfaceTexture);


        mMediaPlayer.prepareAsync();

        // Play video when the media source is ready for playback.
        mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
            }
        });

    } catch (IllegalArgumentException e) {
        Log.d(TAG, e.getMessage());
    } catch (SecurityException e) {
        Log.d(TAG, e.getMessage());
    } catch (IllegalStateException e) {
        Log.d(TAG, e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, e.getMessage());
    }

}

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {

}

@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    return false;
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {

}

}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.test.sus">
<TextureView
    android:id="@+id/play_video_texture"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    android:fitsSystemWindows="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"/>



<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button2"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="167dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Small Text"
    android:id="@+id/te"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="122dp" />
</RelativeLayout>

splash_layout.xml

Hope this works for you!

Outturn answered 11/8, 2015 at 13:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.