我使用水平列表视图https://github.com/sephiroth74/HorizontalVariableListView来显示使用适配器的视频缩略图。现在我想在每个缩略图上播放视频,为此我夸大了我的自定义视频播放器及其工作正常。但我的问题是,当我点击多个视频然后,所有点击视频充气视图并开始播放视频,我的任务是一次只播放一个视频,如果用户点击另一个视频和之前的视频正在播放那么它应该并播放当前视频。
我的adapetr课程是:
public class VideoSearchAdapter extends ArrayAdapter<SearchVideoBean> {
public VideoSearchAdapter(Context context, int resource,
ArrayList<SearchVideoBean> searchVideoUrls) {
super(context, resource);
this.videoList = searchVideoUrls;
this.mcontext = context;
vi = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
gesture = new GestureDetector(mcontext, new listnerOnVideo());
}
@Override
public int getCount() {
return videoList.size();
}
@Override
public View getView(final int position, View convertView,
final ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
convertView = vi.inflate(Resource, null);
holder.imageview = (ImageView) convertView.findViewById(R.id.userPic);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.imageview.setTag(position);
// set user image
holder.imageview.setScaleType(ScaleType.CENTER_CROP);
String url = videoList.get(position).getVideoUrl();
url = url.replaceAll(" ", "%20").trim();
ImageLoader.getInstance().displayImage(url, holder.imageview, MainActivity.defaultOptions);
holder.imageview.setOnTouchListener(new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View view, MotionEvent event) {
if (alreadyplaying) {
parent.removeView(parent.findViewById(R.id.bc_myvideo));
}
else{
Log.i("ddd", "video not playing");
imageParent = view.getParent();
return gesture.onTouchEvent(event);
}
return false;
}
});
catalog.findVideoByID(videoList.get(position).getVideoId(), new VideoListener() {
@Override
public void onVideo(Video video) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// progressBar.setVisibility(View.GONE);
}
}, 1500);
tempVideoView.add(video);
tempVideoView.start();
alreadyplaying = true;
}
@Override
public void onError(String error) {
}
});
return convertView;
}
class ViewHolder {
public ImageView imageview;
}
class listnerOnVideo extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
try {
LayoutInflater inflater1 = (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewGroup parent = (ViewGroup) (imageParent);
View v2 = inflater1.inflate(R.layout.brightcove_video_view, parent);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(holder.imageview.getWidth(), holder.imageview.getHeight());
tempVideoView = (BrightcoveVideoView) v2.findViewById(R.id.bc_myvideo);
progressBar = (ProgressBar) v2.findViewById(R.id.pBarinMain);
tempVideoView.setLayoutParams(layoutParams);
tempVideoView.requestLayout();
tempVideoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
parent.removeView(parent.findViewById(R.id.bc_myvideo));
}
});
}
catch (Exception ee) {
Log.e("ddd", ""+ee.getMessage());
}
return super.onSingleTapUp(e);
}
}
}