我有ListView,当我点击任何项目时,它包含多个视频,当向上或向下滚动视频时视频正在播放停止,我提到https://github.com/danylovolokh/VideoPlayerManager它工作正常但是当我点击任何屏幕上100%可见的项目如下:
当时播放以下项目视频,如下所示:
当我点击任何项目但我在日志中找到正确位置时,我检查了日志中的位置,那么我该怎么办?请大家帮忙解决一下。我很多天都遇到过这个问题
我的代码如下:
public class PlayVideo extends Activity {
private Activity mActivity;
private static final boolean SHOW_LOGS = Config.SHOW_LOGS;
private static final String TAG = PlayVideo.class.getSimpleName();
private ArrayList<BaseVideoItem> mList = new ArrayList<>();
private String videoId = "";
public static int isVideoPlay = 0;
public static ProgressDialog pDialog;
private final ListItemsVisibilityCalculator mListItemVisibilityCalculator =
new SingleListViewItemActiveCalculator(new DefaultSingleItemCalculatorCallback(), mList);
private ItemsPositionGetter mItemsPositionGetter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_video_list_view);
mActivity = PlayVideo.this;
pDialog = new ProgressDialog(mActivity);
pDialog.setMessage("Loading");
pDialog.setCanceledOnTouchOutside(false);
pDialog.setCancelable(true);
try {
mList.add(ItemFactory.createItemFromUrl(mActivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", R.drawable.video_sample_1_pic, mActivity, mVideoPlayerManager));
mList.add(ItemFactory.createItemFromUrl(mActivity, "http://www.androidbegin.com/tutorial/AndroidCommercial.3gp", R.drawable.video_sample_3_pic, mActivity, mVideoPlayerManager));
mList.add(ItemFactory.createItemFromUrl(mActivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", R.drawable.video_sample_4_pic, mActivity, mVideoPlayerManager));
mList.add(ItemFactory.createItemFromUrl(mActivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", R.drawable.video_sample_1_pic, mActivity, mVideoPlayerManager));
mList.add(ItemFactory.createItemFromUrl(mActivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", R.drawable.video_sample_2_pic, mActivity, mVideoPlayerManager));
mList.add(ItemFactory.createItemFromUrl(mActivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", R.drawable.video_sample_3_pic, mActivity, mVideoPlayerManager));
mList.add(ItemFactory.createItemFromUrl(mActivity, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", R.drawable.video_sample_4_pic, mActivity, mVideoPlayerManager));
} catch (IOException e) {
throw new RuntimeException(e);
}
mListView = (ListView) findViewById(R.id.list_view);
VideoListViewAdapter videoListViewAdapter = new VideoListViewAdapter(mVideoPlayerManager, mActivity, mList);
mListView.setAdapter(videoListViewAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("isVideo------------", String.valueOf(isVideoPlay));
if (isVideoPlay == 0) {
pDialog.show();
Log.d("Position....", String.valueOf(position));
mItemsPositionGetter = new ListViewItemPositionGetter(mListView);
Log.d("mListView.getFirstVisiblePosition()....", String.valueOf(mListView.getFirstVisiblePosition()));
Log.d("mListView.getLastVisiblePosition()....", String.valueOf(mListView.getFirstVisiblePosition()));
Log.d("mItemsPositionGetter....", String.valueOf(mItemsPositionGetter));
mListItemVisibilityCalculator.onScrollStateIdle(mItemsPositionGetter, mListView.getFirstVisiblePosition(),
mListView.getLastVisiblePosition());
}
}
});
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
mScrollState = scrollState;
if (scrollState == SCROLL_STATE_IDLE && !mList.isEmpty()) {
if(isVideoPlay == 1){
isVideoPlay = 0;
pDialog.dismiss();
}
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (!mList.isEmpty()) {
if(isVideoPlay == 1){
isVideoPlay = 0;
pDialog.dismiss();
}
}
}
});
}
private final VideoPlayerManager<MetaData> mVideoPlayerManager = new SingleVideoPlayerManager(new PlayerItemChangeListener() {
@Override
public void onPlayerItemChanged(MetaData metaData) {
if (SHOW_LOGS) Logger.v(TAG, "onPlayerItemChanged " + metaData);
}
});
private int mScrollState = AbsListView.OnScrollListener.SCROLL_STATE_IDLE;
private ListView mListView;
@Override
public void onStop() {
super.onStop();
// we have to stop any playback in onStop
mVideoPlayerManager.resetMediaPlayer();
}
}