How to display the videos url in thumbnails?

本小妞迷上赌 提交于 2019-12-12 17:14:37

问题


I'm facing problem in showing videos in thumbnails..

From the database video link is retrieved and stored in string array.

I want to display the array of videos in thumbnails grid view. How to implement this? Its possible to display?

Can anyone help me? Thanks a lot in advance.

I tried this....

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

回答1:


Its very simple, instead of string array use object arraylist which has thumbnail/bitmap for the grid item and video url like given below.

class video
{
  Bitmap thumnail;
  String videoURL;
}

From database make an arraylist of this video class then use that arraylist in 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;
}

Then in the onitemclick, using the same arraylist you can get the videourl and you can play the video in separate screen.

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


来源:https://stackoverflow.com/questions/16190374/how-to-display-the-videos-url-in-thumbnails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!