微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐