视频视图正在替换它们在网格视图中的位置,有时 1 个视频视图在网格视图中重复
Video Views are replacing their position in a grid view and sometimes 1 video view is repeating in a grid view
基本上我有一个视频列表,我想在网格视图中显示所有视频并让它们重复播放,例如,如果 1 个视频播放到结尾,那么它应该开始播放 again.I 已处理完毕全部在我的适配器代码中给出..现在问题来了我面临的问题是滚动网格视图网格视图的项目(网格视图的单个项目由视频视图和删除按钮组成)有时交换彼此或有时单个视频视图在网格视图中重复..它还有另一种异常行为,即网格的最后一项有时会粘在屏幕底部..我只是不明白这里发生了什么..
public class MyGalleryAdapterMain extends BaseAdapter {
private Activity mActivity;
private LayoutInflater mLayoutInflater;
private ArrayList<File> mDatalist;
public MyGalleryAdapterMain(Activity mActivity, ArrayList<File> mDatalist) {
this.mActivity = mActivity;
this.mDatalist = mDatalist;
mLayoutInflater=(LayoutInflater)mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mDatalist.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v=convertView;
final File mData=mDatalist.get(position);
final Holder mHolder;
if(convertView==null){
v=mLayoutInflater.inflate(R.layout.grid_item,null);
mHolder =new Holder();
mHolder.mDeleteButton=(Button)v.findViewById(R.id.deleteButton);
mHolder.mVideoView=(VideoView)v.findViewById(R.id.videoImageView);
mHolder.mVideoNameTextView=(TextView)v.findViewById(R.id.videoNameTextView);
v.setTag(mHolder);
}else
mHolder=(Holder)v.getTag();
/* Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(mData.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
mHolder.mImageView.setImageBitmap(thumbnail);*/
if(mHolder.mVideoView.getCurrentPosition()==0) {
mHolder.mVideoView.setVideoPath(mData.getAbsolutePath());
final Holder mTempHolder=mHolder;
mHolder.mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mTempHolder.mVideoView.start();
}
});
mHolder.mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mTempHolder.mVideoView.start();
}
});
}
mHolder.mDeleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mData.delete();
mDatalist.remove(mData);
notifyDataSetChanged();
}
});
return v;
}
public class Holder{
private VideoView mVideoView;
private TextView mVideoNameTextView;
private Button mDeleteButton;
}
}
我认为这是因为您正在使用的回收视频观看次数在重复使用时没有被告知要重置自己,因此它们只会播放之前播放的相同视频。您应该停止或释放(我现在不在看 android 文档),然后在重新使用时重新加载视频视图。我没有看到你在你发布的代码中这样做。
基本上我有一个视频列表,我想在网格视图中显示所有视频并让它们重复播放,例如,如果 1 个视频播放到结尾,那么它应该开始播放 again.I 已处理完毕全部在我的适配器代码中给出..现在问题来了我面临的问题是滚动网格视图网格视图的项目(网格视图的单个项目由视频视图和删除按钮组成)有时交换彼此或有时单个视频视图在网格视图中重复..它还有另一种异常行为,即网格的最后一项有时会粘在屏幕底部..我只是不明白这里发生了什么..
public class MyGalleryAdapterMain extends BaseAdapter {
private Activity mActivity;
private LayoutInflater mLayoutInflater;
private ArrayList<File> mDatalist;
public MyGalleryAdapterMain(Activity mActivity, ArrayList<File> mDatalist) {
this.mActivity = mActivity;
this.mDatalist = mDatalist;
mLayoutInflater=(LayoutInflater)mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mDatalist.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v=convertView;
final File mData=mDatalist.get(position);
final Holder mHolder;
if(convertView==null){
v=mLayoutInflater.inflate(R.layout.grid_item,null);
mHolder =new Holder();
mHolder.mDeleteButton=(Button)v.findViewById(R.id.deleteButton);
mHolder.mVideoView=(VideoView)v.findViewById(R.id.videoImageView);
mHolder.mVideoNameTextView=(TextView)v.findViewById(R.id.videoNameTextView);
v.setTag(mHolder);
}else
mHolder=(Holder)v.getTag();
/* Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(mData.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
mHolder.mImageView.setImageBitmap(thumbnail);*/
if(mHolder.mVideoView.getCurrentPosition()==0) {
mHolder.mVideoView.setVideoPath(mData.getAbsolutePath());
final Holder mTempHolder=mHolder;
mHolder.mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mTempHolder.mVideoView.start();
}
});
mHolder.mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mTempHolder.mVideoView.start();
}
});
}
mHolder.mDeleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mData.delete();
mDatalist.remove(mData);
notifyDataSetChanged();
}
});
return v;
}
public class Holder{
private VideoView mVideoView;
private TextView mVideoNameTextView;
private Button mDeleteButton;
}
}
我认为这是因为您正在使用的回收视频观看次数在重复使用时没有被告知要重置自己,因此它们只会播放之前播放的相同视频。您应该停止或释放(我现在不在看 android 文档),然后在重新使用时重新加载视频视图。我没有看到你在你发布的代码中这样做。