android开发应用怎么实现调用本地视频播放器播放视频

原文地址:https://blog.csdn.net/dodod2012/article/details/80570181

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.csdn.net/dodod2012/article/details/80570163

发布了141 篇原创文章 · 获赞 51 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/dreams_deng/article/details/83902909