【问题标题】:Automatically Playing video in listview/scrollview similar to facebook在类似于 facebook 的列表视图/滚动视图中自动播放视频
【发布时间】:2016-02-26 17:19:32
【问题描述】:

如果视图包含视频,我需要视频在列表视图/滚动视图中自动播放。这与 facebook 非常相似。如果用户向下滚动并且可见区域包含视频,则系统将播放视频,如果仍然滚动,则它会自动停止该视频。它应该像一次播放一个视频一样工作。

有人可以帮我解决这个问题吗?

我经历过的来源:

  1. Play video in Android listview
  2. How to automatically play video in listview on android app
  3. How to automatically play video in listview on android app

谢谢..!!

【问题讨论】:

  • 对于 ScrollView 你可以设置一个监听器stackoverflow.com/questions/3948934/…
  • 有一些方法可以在 ListView 中找到可见项目的位置,您可以检查那些可见项目以开始/停止播放。对于 ScrollView,您需要在该 ScrollView 中找到项目的绑定。
  • 您找到解决方案了吗?
  • 还没有乔治·托马斯:|
  • 你找到解决办法了吗?

标签: android listview video scrollbar playing


【解决方案1】:

请注意要点

  1. 首先你需要在RecyclerView中添加一个滚动监听器
  2. 然后通过监听器更新你的RecyclerView适配器

    protected void onListViewUpdate(final int position, final Object object) {
        final RecyclerView view = mView;
        LinearLayoutManager layoutManager = ((LinearLayoutManager)view.getLayoutManager());
        final View convertView = layoutManager.findViewByPosition(position);
        int firstVisiblePosition = layoutManager.findFirstCompletelyVisibleItemPosition();
        int lastVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition();            
    
        if (firstVisiblePosition <= position && position <= lastVisiblePosition) {
            // this is the convertView that you previously returned in getView
            // just fix it (for example:)
    
            Thread thread = new Thread(){
                @Override
                public void run() {
                    super.run();
    
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            adapter.updateRow(adapter.getItem(position), convertView, object);
                        }
                    });
                }
            };
            thread.start();
        } else {
            // just update your data set, UI will be updated automatically in next
            // getView() call
            adapter.updateData(position, object);
        }
    }
    
  3. 从适配器通过updateRow() 方法更新当前可见视图。

工作完成:)

【讨论】:

    猜你喜欢
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 2016-07-01
    相关资源
    最近更新 更多