0
我想創建一個列表視圖與來自json的YouTube視頻,我無法設法將YouTube播放器片段實現到我的VideoAdapter。列表視圖中的YouTube播放器片段
我已經檢查了來自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);
}
}
}