gpt4 book ai didi

android - 如何以缩略图显示视频网址?

转载 作者:行者123 更新时间:2023-11-29 00:30:14 24 4
gpt4 key购买 nike

我在以缩略图形式显示视频时遇到问题..

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

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

谁能帮帮我?非常感谢。

我试过了....

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

最佳答案

它非常简单,而不是字符串数组使用对象数组列表,它具有网格项目和视频 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 中,使用相同的数组列表,您可以获得 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
}
});

关于android - 如何以缩略图显示视频网址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16190374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com