[英]Can't play video in videoview android studio?
I know that there is too many solutions were given, but I can't get the exact solution.我知道给出了太多的解决方案,但我无法得到确切的解决方案。 My problem is that I have picked one video from internal storage device and after picking video then I have converted to String and set the video to videoView but then also it shows that "Can't play this video" in videoView.我的问题是我从内部存储设备中选择了一个视频,在选择视频后,我已转换为字符串并将视频设置为 videoView,但它也显示在 videoView 中“无法播放此视频”。
can anyone please help me to find out the solution:(谁能帮我找出解决方案:(
here is my code这是我的代码
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/videos.mp4");
Log.d("video",""+file);
if (file.exists()) {
Uri uri = Uri.fromFile(file);
String video = String.valueOf(uri);
Log.d("video",""+uri);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse(video));
videoView.requestFocus();
videoView.start();
}else {
Toast.makeText(this, "No video found", Toast.LENGTH_SHORT).show();
}
With scoped storage (required from API 30) you can't access files directly unless you request the MANAGE_EXTERNAL_STORAGE
(on Google Play you need to request it to Google).使用范围存储(API 30 要求)您无法直接访问文件,除非您请求MANAGE_EXTERNAL_STORAGE
(在 Google Play 上您需要向 Google 请求)。
The new way is to use the file uri.新方法是使用文件 uri. You can try those ways:你可以试试这些方法:
private final ActivityResultLauncher<String[]> openDoc =
registerForActivityResult(new ActivityResultContracts.OpenDocument(),
new ActivityResultCallback<Uri>() {
@Override
public void onActivityResult(Uri uri) {
// use uri
}
});
Call it with:调用它:
// Use the mimetype you want (optional). Like "text/plain"
openDoc.launch(new String[]{"text/plain"});
You'll also need the READ_EXTERNAL_STORAGE
permission if the file was not created by your app.如果文件不是由您的应用创建的,您还需要READ_EXTERNAL_STORAGE
权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.