【问题标题】:How to display the videos url in thumbnails?如何在缩略图中显示视频网址?
【发布时间】:2013-04-24 11:07:01
【问题描述】:

我在缩略图中显示视频时遇到问题..

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

我想在缩略图网格视图中显示视频数组。如何实施?可以显示吗?

谁能帮帮我?提前非常感谢。

我试过这个......

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;
    }

【问题讨论】:

  • 一开始你在右边的网格中显示图像,点击网格项目你到底想做什么?在点击网格项目时,视频应该在单独的屏幕上播放还是必须在网格单元本身中播放?
  • 视频应该在你管视频的单独屏幕上播放..在此之前我应该​​在网格视图列表中显示...指导我..
  • 没有人可以帮助我..请告诉我我做错了什么我想改变什么

标签: android gridview video-thumbnails


【解决方案1】:

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

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
  }
});

【讨论】:

  • 我将 videourl 作为 JSONObject 作为 String..我如何将字符串存储在 ArrayList
  • 简单..通过 jsonObj.getString("name_of_Field_URL") 解析 json 对象时,只需通过 add(jsonObj.getString("name_of_Field_URL")) 将其存储在您的数组中;
猜你喜欢
  • 2018-06-14
  • 2012-12-06
  • 2012-06-08
  • 1970-01-01
  • 2011-03-25
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 2014-11-20
相关资源
最近更新 更多