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

后端 未结 2 1475
长发绾君心
长发绾君心 2020-12-18 20:18

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

2条回答
  •  悲&欢浪女
    2020-12-18 20:51

    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) {
    
    }
    

    }

    
    
    
    
    
    

    splash_layout.xml

    Hope this works for you!

提交回复
热议问题