列表视图中的 YouTube 播放器片段

YouTube Player Fragment in listview

我正在尝试使用来自 json 的 youtube 视频创建列表视图,但我无法将 youtube 播放器片段实施到我的 VideoAdapter 中。

我已经检查了 youtube api 中的示例代码,但我还没有那么先进。如何将 youtube 播放器片段实现到我的 VideoAdapter 文件中。

VideoAdapter.java

public class VideoAdapter extends ArrayAdapter<VideosActivity.Videos>{

    ArrayList<VideosActivity.Videos> videoList;
    LayoutInflater vi;
    int Resource;
    ViewHolder holder;

    public VideoAdapter(Context context, int resource, ArrayList<VideosActivity.Videos> objects) {
        super(context, resource, objects);
        vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        Resource = resource;
        videoList = objects;
    }

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

        View v = convertView;

        if (v == null) {
            holder = new ViewHolder();
            v = vi.inflate(Resource, null);


            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }

        holder.thumb.setImageResource(R.drawable.noimage);
        new DownloadImageTask(holder.thumb).execute(videoList.get(position).getThumb());
        return v;
    }

    static class ViewHolder {
        public ImageView thumb;

    }

    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;

        public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }
        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return mIcon;
        }
        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }
}

经过大量研究,我实现了我所需要的。任何需要播放列表中的列表视频的人,代码在上面。