在类似于Facebook的listview/scrollview中自动播放视频 [英] Automatically Playing video in listview/scrollview similar to facebook

查看:160
本文介绍了在类似于Facebook的listview/scrollview中自动播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need Video to play automatically in listview/scrollview, if view contains video. This is ver much similar with facebook. If user scrolls down and visible area contains video that system will play video and if still scroll then it automaticaly stops that video. It should work like one video should play at one time.

有人可以帮我吗?

我经历过的来源:

  1. 在Android listview中播放视频
  2. 如何在android的listview中自动播放视频应用
  3. 如何在android的listview中自动播放视频应用
  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

谢谢.. !!

推荐答案

请遵循以下要点

  1. 首先,您需要在RecyclerView
  2. 中添加滚动侦听器
  3. 然后通过侦听器更新您的RecyclerView适配器

  1. First you need to add a scroll listener into RecyclerView
  2. Then through the listener update your RecyclerView adapter

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

  • 从适配器通过updateRow()方法更新当前可见视图.

  • From the adapter update the current visible view from updateRow() method.

    完成工作:)

    这篇关于在类似于Facebook的listview/scrollview中自动播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆