2013-04-24 79 views
2

我在缩略图中显示视频时遇到问题..如何以缩略图显示视频网址?

从数据库中检索视频链接并将其存储在字符串数组中。

我想在缩略图网格视图中显示视频数组。如何实现这一点?它可能显示?

任何人都可以帮助我吗?提前致谢。

我想这....

vid = new ArrayList<String>(new ArrayList<String>(vid)); 

runOnUiThread(new Runnable() { 
    public void run() { 
     setContentView(R.layout.gallery); 
     GridView grd = (GridView)findViewById(R.id.gridView1); 
     grd.setAdapter(new ImageAdapter(this)); 
     grd.setOnItemClickListener(new OnItemClickListener() 
     { 
     public void onItemClick(AdapterView<?> parent,View v,int pos,long id) 
     { 
     Toast.makeText(getBaseContext(), 
         "pic"+(pos+1)+"select ",Toast.LENGTH_SHORT).show(); 
     } 
    }); 
} 
    }); 
     return; 
    private class ImageAdapter extends BaseAdapter { 
    private final Runnable context; 
    public ImageAdapter(Runnable runnable) { 
      context = runnable; 
    } 
    public int getCount() 
    { 
     return vid.size(); 
    } 
    public Object getItem(int position) 
    { 
     return position; 
    } 
    public long getItemId(int position) 
    { 
     return position; 
    } 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
     ImageView picturesView; 
     if (convertView == null) { 
      picturesView = new ImageView((Context) context); 
      //Creation of Thumbnail of video 
      Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(vid.get(position),0); 
      picturesView.setImageBitmap(bitmap); 
      picturesView.setScaleType(ImageView.ScaleType.FIT_XY); 
      //picturesView.setPadding(8, 8, 8, 8); 
      picturesView.setLayoutParams(new Gallery.LayoutParams(150, 120)); 
     }else { 
      picturesView = (ImageView)convertView; 
     } 
     return picturesView; 
    } 
+0

最初,您正在网格右侧显示图像,您想要在点击网格项目时执行什么操作?在点击网格项目时,应该在单独的屏幕上播放视频,还是必须在网格单元中播放视频? – Padma 2013-04-24 11:26:37

+0

视频应播放在单独的屏幕你管视频..在此之前,我应该显示在网格视图列表...指导我.. – 2013-04-24 11:48:11

+0

没有人在那里帮助我..请告诉我做错了什么我想改变 – 2013-04-24 12:33:46

回答

2

它非常简单,而不是具有缩略图/位图网格项目和视频网址类似如下字符串数组使用对象数组列表。

class video 
{ 
    Bitmap thumnail; 
    String videoURL; 
} 

从数据库中创建此视频类的数组列表,然后在getview中使用该数组列表。

videoList = new ArrayList<Video>(); 
// populate videolist 


public int getCount() 
{ 
    return videoList.size(); 
} 

public View getView(int position, View convertView, ViewGroup parent) 
{ 
    ImageView picturesView; 
    if (convertView == null) { 
     picturesView = new ImageView((Context) context); 
     //Creation of Thumbnail of video 
     //Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(vid.get(position),0); 
     Bitmap bitmap = videoList.get(position).thumnail; 
     picturesView.setImageBitmap(bitmap); 
     picturesView.setScaleType(ImageView.ScaleType.FIT_XY); 
     //picturesView.setPadding(8, 8, 8, 8); 
     picturesView.setLayoutParams(new Gallery.LayoutParams(150, 120)); 
    }else { 
     picturesView = (ImageView)convertView; 
    } 
    return picturesView; 
} 

然后在onitemclick,使用相同的arraylist你可以得到videourl,你可以在单独的屏幕上播放视频。

grd.setOnItemClickListener(new OnItemClickListener() 
    { 
    public void onItemClick(AdapterView<?> parent,View v,int pos,long id) 
    { 
    String videoLink = videoList.get(pos).videoURL; 
    // pass this video link to another activity where you want to play the video 
    } 
}); 
+0

即时通讯将视频作为JSONObject作为字符串..如何将字符串存储在ArrayList中

+0

简单..when通过jsonObj.getString(“name_of_Field_URL”)解析json对象时,只需通过add(jsonObj.getString(“ name_of_Field_URL“)); – Jonny2Plates 2014-12-15 19:02:46