Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Video is playable from gallery but when I play it using Intent.ACTION_VIEW type video, cannot play

Here is my original question

I've implemented the answer there but still the problem persist.

Here is the gist: 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 the gallery, 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

The file exist from the answer that I got. But still the problem persist, and I have no idea what went wrong.

Any insight is appreciated. Thanks

Edit:To those who didn't see the answer in the first question. I've already implemented this:

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);

The file exist since I've checked it. I'm wondering if there is a problem with the file naming convention.

Also I'm debugging from my device, Samsung Galaxy Ace, Android 2.3.6, compiling with 4.2 sdk.

Edit 2: I've tried renaming the video into simpler one and now the video works, my guess is that the the file has a filename length limitation or an naming convention.

like image 760
Marl Avatar asked Jan 29 '26 20:01

Marl


2 Answers

This code is from a working app that I made, try it out.

Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(
                    Uri.parse("file://"+ file.getAbsolutePath()),
                    "video/*");
like image 104
Rotary Heart Avatar answered Feb 01 '26 09:02

Rotary Heart


You need to use the file scheme:

So you should use intent.setDataAndType("file://" + uri, "video/*");

like image 41
Seshu Vinay Avatar answered Feb 01 '26 09:02

Seshu Vinay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!