Mak*_*ple 3 video android android-gridview
我在数组中有一个url字符串.如何在gridview中显示视频的网址,然后单击下一个屏幕中的网格播放.怎么实现这个?任何人指导我..
我尝试了图像它的工作正常..如何实现视频,数组是string..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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
非常感谢提前....
你在这个阶段错了.
How to display the url of video in gridview ?
Run Code Online (Sandbox Code Playgroud)
不要尝试将URL打印到网格视图项中.YouTube会在不同的框架中提供特定视频的缩略图.因此,您可以直接使用该网址并进行播放.
以下是YouTube缩略图的图片网址(按框架排序)
YouTube网址: http ://img.youtube.com/vi/
Video_ID: AxeOPU6n1_M
帧数:0.jpg
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
从Web服务获取,以便您可以使用它.
如果您不知道如何设置来自服务器的图像,请查看以下链接.
这两个示例都很好,现在您必须根据需要更新代码.
How to play on click the grid plays in next screen.
Run Code Online (Sandbox Code Playgroud)
这应该是通过意图调用的新活动,这将在YouTube播放器中播放.
@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();
}
Run Code Online (Sandbox Code Playgroud)