【问题标题】:How to play video of video-view that is currently focus in recycler view如何播放当前在回收站视图中关注的视频视图的视频
【发布时间】:2016-02-14 15:15:31
【问题描述】:

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

【问题讨论】:

    标签: android scrollview android-recyclerview android-videoview autoplay


    【解决方案1】:
    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;
                    }
                }
    
            }
    
        });
    }
    

    【讨论】:

    • 这是什么?如果您想更新源代码,请先编辑您自己的问题。
    • @NguyễnHoàiNam 我编辑了尽可能笼统的答案,我正在使用的应用程序内容丰富,无法在此处发布为问题。
    • 我的意思是你应该编辑你原来的问题。但不管怎样,你目前的实现有什么问题?
    • 很高兴听到这个消息。您应该将此作为已接受的答案进行检查(即使它是您的),这样其他人(比如我)就不会误解。不过,它会帮助其他人。
    • 为什么会这样?仅代码的答案通常没有帮助。
    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 2012-08-09
    • 2012-11-28
    • 2014-02-12
    • 2022-06-23
    相关资源
    最近更新 更多