Android Mp4 video Not playing - android

I have video that is locally stored in assets folder. Here is my code. I am getting error cannot play video. It is .mp4 file. It plays perfectly on my macbook.
Uri video = Uri.parse("file:///android_asset/video");
Intent intent = new Intent(Intent.ACTION_VIEW, video)
intent.setDataAndType(video, "video/*");
startActivity(Intent.createChooser(intent, "Play Video"));
I have also placing it in raw folder, In this case I am not getting ActiviyNotFoundException
Uri video = Uri.parse("file:///android.resource://" + getActivity().getPackageName() + "/" + R.raw.video);

The assets directory is private to your application; other applications cannot access it.
You will either need to provide access to the file using a FileProvider, or copy the file to a directory that other applications can access.

If you want to play from sdcard then the try this.
Uri vidFile = Uri.parse("link");
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoPath(path);
videoView.setMediaController(new MediaController(this));
videoView.start();
path can also be retrieved by MediaStore.Video.Media.DATA or you can type the path as /sdcard/videos
Also have a look at this tutorial

Related

Android (Intent.ACTION_VIEW) not recognizing on Mi device for mimeType video/mp4

I have taken a video from camera which gets saved in camera/DCIM location on sdCard
Now my app takes the local path of the video and try playing the video using default video player with below code
private void playVideo(String path) {
Uri videoUri = Uri.parse(path);
Intent videoIntent = new Intent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(videoUri, "video/*");
if (videoIntent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(videoIntent, null));
}
}
Now issue is the video doesn't play with a toast "Media view not found" on Mi devices + a few other.
But the same video plays through through selecting video from FileManager applications.
So I guess the issue is not with VideoPlayer. INSTEAD I think it's the issue with what mimeType is getting shared to the player. But thats just my assumption.
Anyone faced a similar issue, I need help as this issue is eating up my time.
Thanks
/storage/emulated/0/DCIM/Camera/VID_20160113_130138.mp4 is not a valid string representation of a Uri. A Uri needs a scheme.
Presumably, once upon a time, you had a File object for this. Use that, and Uri.fromFile(), instead of Uri.parse(). Or, use Uri.fromFile(new File(path)). This will give you the proper scheme setup.

How to play video using software like on MX player?

I have troubled in playing a video that is not supported by hardware I want to create a simple video player that can play any video even it is not supported by hardware. I like the way how mx player did it. Can any one help me how to play a video like in MX player. I have this basic syntax but it only plays hardware supported videos. Here's my code
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri = uri = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.videointro);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
You need to write intent and for that please pass the video url. Then android will identify apps which will able to play video then you need to pick/select one.

Android Play video in Mediaplayer?

Video in res->raw folder.I want to play video directly in mediaplayer.I trying to search in google but cant get final solution...
Didn't tested yet, but I think this should work,
Tell me if you found and issue.
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/raw/"+videoName);
Intent tostart = new Intent(Intent.ACTION_VIEW);
tostart.setDataAndType(uri, "video/*");
startActivity(tostart);

android: using default video player

I have an application that plays video files.
I have been using code for using Videoview and starting the Videoview manually to play video files. However, I just wanted to know if I can use the default media player or video player of android rather than creating or using the VideoView to play the file..
Please make comments if the question is not clear.
Thanks alot
Sure - just use an Intent with the file Uri.
File file = new File("fileUri");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);

Android intent to open video with raw resource?

Does anyone know of an intent I can use to open a raw mp4 resource in the phone's video player? I tried this code:
Uri video = Uri.parse( "android.resource://" + getPackageName() + "/" + R.raw.video );
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(video, "video/*");
startActivity(intent);
This threw an ActivityNotFoundException, however this has worked for me when the URI was the sdcard and the video was located there. Does anyone know how I can use the above code with a resource file in my app?
Other apps can't access your resources. You'll need to create a ContentProvider, or store the data in a place accessible to anyone (either SD card, or in a public folder in your local storage).

Categories

Resources