在Listview中使用videoview播放视频

时间:2014-09-09 10:21:12

标签: android android-listview android-video-player android-videoview

朋友我想在列表中提供的视频视图中播放我的视频。 我对目前的代码不满意,因为除了第一个视频之外它没有播放。我的要求是当我点击视频视图上的按钮时,任何列表项都必须有效地播放。

以下是我在listview中设置的适配器,用于显示从网址下载的所有视频,点击按钮,在视频中播放,隐藏播放按钮。

public class RantAdapter extends AbsAdapter {

public RantAdapter(Activity activity, ArrayList<RantModel> rantList) {
    super(activity, rantList);
}

GestureDetector mGestureDetector;
TextView likeCount = null;
TextView RantTitle = null;
VideoView videoView = null;
ImageView author = null;
ImageView videoImageUrl = null;
TextView author_name = null;
TextView commentCount = null;
OnGestureListener mGesturelistener;
Button playVideo;
Uri uri;

@Override
public View getView(int position, View view, ViewGroup parent) {

    super.getView(position, view, parent);

    LayoutInflater inflater = (LayoutInflater) mActivity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater
            .inflate(R.layout.rant_row_layout, parent, false);


    RantModel rantModel = mListContent.get(position);

    RantTitle.setText(rantModel.title);
    author.setImageBitmap(loadImageFromURL(rantModel.author_image_url));
    author_name.setText(rantModel.author_name);
    likeCount.setText(rantModel.view_count);
    commentCount.setText(rantModel.comment_count);
    videoImageUrl.setImageBitmap(loadImageFromURL(rantModel.content_image_url));

    final String videoUrl = rantModel.content_url;

    uri = Uri.parse(videoUrl);

    playVideo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            playVideo.setVisibility(View.GONE);
            videoImageUrl.setVisibility(View.INVISIBLE);
            MediaController mediacontrol = new MediaController(mActivity);
            mediacontrol.setAnchorView(videoView);
            videoView.stopPlayback();               
            videoView.setMediaController(mediacontrol);
            videoView.setVideoURI(uri); // videoView.seekTo(100);
            videoView.requestFocus();
            videoView.setZOrderOnTop(true);
            videoView.start();

        }
    });
    return rowView;
}}

1 个答案:

答案 0 :(得分:0)

请删除以下代码

if (rowView != null) {
}