如何播放回收站视图中当前关注的视频视图的视频

问题描述 投票:4回答:1

在我的应用中,有一个具有视频视图的回收视图,我想自动播放滚动时完全聚焦的特定视频视图。

android scrollview android-recyclerview android-videoview autoplay
1个回答
7
投票
RecyclerView rv_featureList;
private View currentFocusedLayout, oldFocusedLayout;

@Override
public void onCreate(Bundle instanceState) {
    rv_featuredList.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView,
                                         int newState) {
            super.onScrollStateChanged(recyclerView, newState);


            if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
                //get the recyclerview position which is completely visible and first
                int positionView = ((LinearLayoutManager) rv_featuredList.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
                Log.i("VISISBLE", positionView + "");
                if (positionView >= 0) {
                    if (oldFocusedLayout != null) {
                        //Stop the previous video playback after new scroll
                        VideoView vv_dashboard = (VideoView) oldFocusedLayout.findViewById(R.id.vv_dashboard);
                        vv_dashboard.stopPlayback();
                    }


                    currentFocusedLayout = ((LinearLayoutManager) rv_featuredList.getLayoutManager()).findViewByPosition(positionView);
                    VideoView vv_dashboard = (VideoView) currentFocusedLayout.findViewById(R.id.vv_dashboard);
                    //to play video of selected recylerview, videosData is an array-list which is send to recyclerview adapter to fill the view. Here we getting that specific video which is displayed through recyclerview.
                    playVideo(videosData.get(positionView));
                    oldFocusedLayout = currentFocusedLayout;
                }
            }

        }

    });
}
© www.soinside.com 2019 - 2024. All rights reserved.