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

会有一股神秘感。 提交于 2019-11-29 09:14:01

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.

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!