微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

        }

    });
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐