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);
Related
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.
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
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.
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/*");
You need to use the file scheme:
So you should use intent.setDataAndType("file://" + uri, "video/*");
I've tried different solution. But I guess the problem occurred because of naming convention. I have tried renaming the file into a simpler format and it works. Also the problem with my original file name is that I have a "--" in the file name.
I want to play youtube video in my application. I am getting video URL from SAX Parsing. My question is how to play video from URL in VideoView, not in Webview or Browser.
I tried this code :
Intent lVideoIntent = new Intent(null, Uri.parse("VIDEO URL"));
startActivity(lVideoIntent);
It is displaying one popup screen with 'Internet' and 'YouTube' options. I want to play the video directly in youtube.
Please let me know your thoughts. Any code or any example is highly appreciated.
you can try below code for direct play in Youtube application.
Intent videoClient = new Intent(Intent.ACTION_VIEW);
videoClient.setData(Uri.parse("https://www.youtube.com/watch?v=EwSdmxyayx0&feature=youtube_gdata"));//you can try here your own video url
videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.PlayerActivity");
try{
startActivity(videoClient);
}catch(ActivityNotFoundException excp){
try{
videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
startActivity(videoClient);
}catch(ActivityNotFoundException exc){
exc.printStackTrace();
}
}
String videoUrl = "http://www.youtube.com/watch?v=cxLG2wtE7TM"
//split video url and get value of v ie cxLG2wtE7TM
String videoId = "cxLG2wtE7TM";
String action = Intent.ACTION_VIEW;
Uri uri = Uri.parse("vnd.youtube:" + videoId);
Intent videoIntent = new Intent(action, uri);
startActivity(videoIntent);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("video url"));
VideoActivity.this.startActivity(i);
It is displaying one popup screen with 'Internet' and 'YouTube'
because the ACTION_VIEW intent is written both in default browser and Youtube application. that's why whenever it catches the URL the Browser opens and whenever the Youtube URL is opened Both the browser and Youtube app.
I want to play the video directly in youtube
Take the embed link of Youtube video and set intent it will play the video.
ex:-http://www.youtube.com/embed/srMFb6zpx2Y
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).