danylovolokh/VideoPlayerManager

java.lang.IllegalStateException

Opened this issue · 11 comments

When i'm try the demo with play videos when scroll in recycle-view android some time it crash
this is the log file
02-15 14:45:13.910 23491-23530/? E/MediaPlayerWrapperImpl@1131714648: 11698 catch IO exception [java.io.IOException: Prepare failed.: status=0x1]
02-15 14:45:14.710 23491-23491/? E/MediaPlayer: Should have subtitle controller already set
02-15 14:45:15.530 23491-23491/? E/MediaPlayer: Should have subtitle controller already set
02-15 14:46:06.350 23491-23503/? E/BufferQueue: [unnamed-23491-58] dequeueBuffer: BufferQueue has been abandoned!
02-15 14:46:06.360 23491-23502/? E/MediaPlayer: error (1, -19)
02-15 14:46:06.360 23491-23530/? E/MediaPlayerWrapperImpl@1124914064: 11698 catch IO exception [java.io.IOException: Prepare failed.: status=0x1]
02-15 14:46:06.400 23491-2798/? E/AndroidRuntime: FATAL EXCEPTION: VideoPlayerView@1124209904
Process: com.volokh.danylo.videolist, PID: 23491
java.lang.IllegalStateException
at android.media.MediaPlayer._setVideoSurface(Native Method)
at android.media.MediaPlayer.setSurface(MediaPlayer.java:761)
at com.volokh.danylo.video_player_manager.ui.MediaPlayerWrapper.setSurfaceTexture(MediaPlayerWrapper.java:496)
at com.volokh.danylo.video_player_manager.ui.VideoPlayerView$5.run(VideoPlayerView.java:549)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.os.HandlerThread.run(HandlerThread.java:61)
02-15 14:46:06.640 23491-23491/? E/MediaPlayer: Should have subtitle controller already set
02-15 14:46:07.210 23491-2851/? E/BufferQueue: [unnamed-23491-67] query: BufferQueue has been abandoned!
02-15 14:46:07.640 23491-23491/? E/MediaPlayer: Should have subtitle controller already set

Please be as much specific as you can with bug reports:
Device, steps to reproduce.

Thanks for reply
I'm using samsung note 3
I'm add more item (40) in VideoRecyclerViewFragment and make fast scroll down and up this bug will happen .

Thanks

I'm unsure if you are still facing this issue, but for anyone using recyclerviews, set this as your addOnScrollListener

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
                if(!mList.isEmpty() && mLayoutManager.findFirstVisibleItemPosition() < recyclerView.getAdapter().getItemCount() && (mLayoutManager.findLastVisibleItemPosition() + 1) < recyclerView.getAdapter().getItemCount()){
                    // need to call this method from list view handler in order to have filled list
                    mRecyclerView.post(new Runnable() {
                        @Override
                        public void run() {
                            mVideoVisibilityCalculator.onScrollStateIdle(
                                    mItemsPositionGetter,
                                    mLayoutManager.findFirstVisibleItemPosition(),
                                    mLayoutManager.findLastVisibleItemPosition());
                        }
                    });

                    mScrollState = scrollState;
                    if(scrollState == RecyclerView.SCROLL_STATE_IDLE){
                        mVideoVisibilityCalculator.onScrollStateIdle(
                                mItemsPositionGetter,
                                mLayoutManager.findFirstVisibleItemPosition(),
                                mLayoutManager.findLastVisibleItemPosition());
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if(!mList.isEmpty() && mItemsPositionGetter.getFirstVisiblePosition() < recyclerView.getAdapter().getItemCount() && (mLayoutManager.findLastVisibleItemPosition() + 1) < recyclerView.getAdapter().getItemCount()){
                    // need to call this method from list view handler in order to have filled list
                    mRecyclerView.post(new Runnable() {
                        @Override
                        public void run() {
                            mVideoVisibilityCalculator.onScrollStateIdle(
                                    mItemsPositionGetter,
                                    mLayoutManager.findFirstVisibleItemPosition(),
                                    mLayoutManager.findLastVisibleItemPosition());
                        }
                    });

                    mVideoVisibilityCalculator.onScroll(
                            mItemsPositionGetter,
                            mLayoutManager.findFirstVisibleItemPosition(),
                            mLayoutManager.findLastVisibleItemPosition() - mLayoutManager.findFirstVisibleItemPosition() + 1,
                            mScrollState);
                }
            }
        });

it will fix issues regarding array index out of bounds exceptions and stops the illegal state from occuring

I have a new update for this issue, I was able to fix it with the code above. However there was still a crashes that occurred due to scrolling before the data was loaded and some videos would not pause on scroll. This code has fixed this for me. https://gist.github.com/ajchili/4ff1a5b077a72616cea280ba6db60118

Here is the code from the gist

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
        if(!mList.isEmpty()){
            // need to call this method from list view handler in order to have filled list
            mRecyclerView.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        mVideoVisibilityCalculator.onScrollStateIdle(
                                mItemsPositionGetter,
                                mLayoutManager.findFirstVisibleItemPosition(),
                                mLayoutManager.findLastVisibleItemPosition());
                    } catch (ArrayIndexOutOfBoundsException e) {

                    }
                }
            });

            mScrollState = scrollState;
            try {
                mVideoVisibilityCalculator.onScrollStateIdle(
                        mItemsPositionGetter,
                        mLayoutManager.findFirstVisibleItemPosition(),
                        mLayoutManager.findLastVisibleItemPosition());
            } catch (ArrayIndexOutOfBoundsException e) {

            }
        }
    }

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        if(!mList.isEmpty()){
            // need to call this method from list view handler in order to have filled list
            mRecyclerView.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        mVideoVisibilityCalculator.onScrollStateIdle(
                                mItemsPositionGetter,
                                mLayoutManager.findFirstVisibleItemPosition(),
                                mLayoutManager.findLastVisibleItemPosition());
                    } catch (ArrayIndexOutOfBoundsException e) {

                    }
                }
            });

            try {
                mVideoVisibilityCalculator.onScrollStateIdle(
                        mItemsPositionGetter,
                        mLayoutManager.findFirstVisibleItemPosition(),
                        mLayoutManager.findLastVisibleItemPosition());
            } catch (ArrayIndexOutOfBoundsException e) {

            }
        }
    }
});

@ajchili Thanks anyway!
I've already abandoned this lib, and move on to another.
VideoPlayerManager is a good Lib for learning and experiment.

@ajchili i changed the code like you suggested , but the problem still exist, outOfBoundException and illegalStateException while quick fling

@jeremyyu123 would you be able to send me a gist of your code or allow me to fork your repository

I found it may because of the xrecyclerview lib i use in my project , it contains a loadingmorefooter view and it causes the wrong index .Thanks for the reply

@jeremyyu123 hopefully that's the fix, always glad to help