原文地址:https://blog.youkuaiyun.com/u010248450/article/details/75048047?locationNum=6&fps=1
1.调用播放器播放本地视频
错误演示:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(Environment.getExternalStorageDirectory() + "/1.mp4"), "video/*");
startActivity(intent);部分手机播放不了正确演示:
Intent intent = new Intent(Intent.ACTION_VIEW);
String path = Environment.getExternalStorageDirectory().getPath()+ "/1.mp4";//该路径可以自定义
File file = new File(path);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "video/*");
startActivity(intent);2.调用播放器播放网络视频
String url = "http://www.baidu.com/1.mp4";//示例,实际填你的网络视频链接 String extension = MimeTypeMap.getFileExtensionFromUrl(url); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); Intent mediaIntent = new Intent(Intent.ACTION_VIEW); mediaIntent.setDataAndType(Uri.parse(url), mimeType); startActivity(mediaIntent);
Android 7.0 以上 android.os.FileUriExposedException 解决方法:
https://blog.youkuaiyun.com/dodod2012/article/details/80570163
本文介绍了如何使用Android Intent来播放本地及网络视频的方法,并针对不同情况提供了代码示例,包括解决Android 7.0及以上版本中出现的`android.os.FileUriExposedException`异常。
4392





