android – 如何播放当前焦点在回收站视图中的视频视频视频

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

解决方法

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;
                }
            }

        }

    });
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...