其他分享
首页 > 其他分享> > android – 自动在listview / scrollview中播放视频,类似于facebook

android – 自动在listview / scrollview中播放视频,类似于facebook

作者:互联网

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

有人可以帮我吗?

我经历过的消息来源:

> Play video in Android listview
> How to automatically play video in listview on android app
> How to automatically play video in listview on android app

谢谢..!!

解决方法:

请按照要点

>首先,您需要在RecyclerView中添加滚动侦听器
>然后通过监听器更新您的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);
    }
}

>从适配器更新updateRow()方法的当前可见视图.

任务完成 :)

标签:android,scrollbar,listview,video,playing
来源: https://codeday.me/bug/20190706/1397861.html