您的位置:首页 > 理论基础 > 计算机网络

Android 利用发送Intent播放本地视频和网络视频 (转载)

2016-06-22 16:22 204 查看
http://blog.sina.com.cn/s/blog_a000da9d01011y85.html

Android中除了利用VideoView、Mediaplayer播放视频文件外,还可以用发送Intent来调用视频播放模块。

 

方法如下:

 

1.播放本地视频

 

        Intent intent = new Intent(Intent.ACTION_VIEW);

        String type = "video/mp4";

        Uri uri = Uri.parse("file:///sdcard/test.mp4");

        intent.setDataAndType(uri, type);

        startActivity(intent);   

 

2.播放网络视频

 

        Intent intent = new Intent(Intent.ACTION_VIEW);

        String type = "video/* ";

   Uri uri = Uri.parse("http://forum.ea3w.com/coll_ea3w/attach/2008_10/12237832415.3gp");

        intent.setDataAndType(uri, type);

        startActivity(intent);   

 

     注意红色部分,如果不设置type的话,这样写:

       Intent intent = new Intent(Intent.ACTION_VIEW);

  Uri uri = Uri.parse("http://forum.ea3w.com/coll_ea3w/attach/2008_10/12237832415.3gp");

       intent.setData (uri);

       startActivity(intent);  

这样会默认用浏览器打开这个URL!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  视频 android