android-如何使用视频网址字符串在网格视图中显示视频
作者:互联网
我在数组中有一个URL字符串.如何在gridview中显示视频的网址,然后单击,在下一个屏幕中播放网格.
如何实现呢?任何人都可以引导我..
我尝试图像工作正常..如何实现视频,数组是字符串..url ..
public class act extends Activity {
/** Called when the activity is first created. */
//Integer[] imageIDs={R.drawable.icon,R.drawable.icon,R.drawable.icon};
String uri1="https://i3.ytimg.com/vi/bQaWsVQSLdY/default.jpg";
String uri2="https://i4.ytimg.com/vi/cJQCniWQdno/mqdefault.jpg";
String uri3="https://i1.ytimg.com/vi/D8dA4pE5hEY/mqdefault.jpg";
String[] urls={uri1,uri2,uri3};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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();
}
});
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
private int itemBackground;
ImageAdapter(Context c)
{
context=c;
TypedArray a=obtainStyledAttributes(R.styleable.Gallery1);
itemBackground=a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground,0);
a.recycle();
}
public int getCount()
{
return urls.length;
}
public Object getItem(int pos)
{
return pos;
}
public long getItemId(int pos)
{
return pos;
}
public View getView(int pos,View cv,ViewGroup vg)
{
ImageView imageview=new ImageView(context);
imageview.setImageResource(urls.length);
imageview.setScaleType(ImageView.ScaleType.FIT_XY);
imageview.setLayoutParams(new GridView.LayoutParams(150,120));
imageview.setBackgroundResource(itemBackground);
return imageview;
}
}
}
非常感谢.
解决方法:
您在此阶段错了.
How to display the url of video in gridview ?
不要尝试将您的URL打印到网格视图项中. YouTube提供了不同帧中特定视频的缩略图.因此,请直接使用该URL并进行播放.
这是YouTube缩略图的图像URL(按帧排序)
YouTube URL:http://img.youtube.com/vi/
Video_ID:AxeOPU6n1_M
帧号:0.jpg
最终的YouTube缩略图网址
http://img.youtube.com/vi/AxeOPU6n1_M/0.jpg
http://img.youtube.com/vi/AxeOPU6n1_M/1.jpg
http://img.youtube.com/vi/AxeOPU6n1_M/2.jpg
因此,最后必须从网络服务获取youtube_img_url才能使用它.
如果您不知道如何设置来自服务器的图像,请查看以下链接.
这两个示例都很好,现在您只需要按照要求更新代码即可.
How to play on click the grid plays in next screen.
这里应该是通过意图调用的新活动,它将在YouTube Player中播放.
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.videoplaying);
String url= "Your url";
Uri uri=Uri.parse(url);
VideoView video=(VideoView)findViewById(R.id.videoplaying);
video.setVideoURI(uri);
video.start();
}
标签:android-gridview,video,android 来源: https://codeday.me/bug/20191031/1971984.html