如果视图包含视频,我需要在listview / scrollview中自动播放视频。这与facebook非常相似。如果用户向下滚动并且可见区域包含系统将播放视频的视频,并且如果仍然滚动则自动停止该视频。它应该像一个视频应该一次播放一样工作。
有人可以帮我吗?
我经历过的消息来源:
答案 0 :(得分:1)
请按照要点
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()
方法的当前可见视图。
工作完成:)