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才能使用它.

如果您不知道如何设置来自服务器的图像,请查看以下链接.

Example – 1

LazyList

这两个示例都很好,现在您只需要按照要求更新代码即可.

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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...