Intent.ACTION_VIEW video: external storage video “Sorry, this video cannot be played”, but in regular android player, it is playable

主宰稳场 提交于 2019-12-08 05:13:18

问题


So I'm playing a video from external storage(sdcard), I'm having a problem with playing the video and this is my code:

Uri uri = Uri.parse(url);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");

It prompts "Sorry, this video cannot be played", but in regular android player, it is playable. I printed the url and this is what I got:

VideoPlayer url: file:///mnt/sdcard/foldername/video-2012-12-26-21-26--44.mp4

Is it a problem with the uri? If no, can you point me to the right direction. Also if I try a foldername that have a dot(.) will I have a problem?

url = file:///mnt/sdcard/Android/data/com.example.project/video-2012-12-26-21-26--44.mp4

Thanks.

Edit: Since my real problem was not solve, and nobody want to answer anymore, I open up a new question: Android: Video is playable from gallery but when I play it using Intent.ACTION_VIEW type video, cannot play

Partial Answer to my problem:

The problem occurs because of naming convention. I think the player doesn't accept file names that have "--" in it. So I solved this problem by changing the file name format.

//Disclaimer: I don't have a full explanation and source but this info is just deduced from my workaround.


回答1:


make sure you are passing right sdcard path with Intent. best way is use Environment.getExternalStorageDirectory() for getting SDCARD path instead of passing static string :

intent = new Intent(Intent.ACTION_VIEW);

File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "/foldername/video-2012-12-26-21-26-44.mp4");

intent.setDataAndType(Uri.fromFile(file), "video/*");

startActivity(intent);


来源:https://stackoverflow.com/questions/14133140/intent-action-view-video-external-storage-video-sorry-this-video-cannot-be-pl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!