Hi All I want to play video in android from raw folder in native player .I able to play video from sd card and server url. But if my mp4 is in raw folder its fire exception. Can somebody help me.
My code is here.
Uri uri = Uri.parse("android.resource://" + getPackageName() + R.raw.sun);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);intent.setDataAndType(uri, "video/*");
startActivity(intent);
its working if i play using Video View but i don't want play in Video View.
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.sun);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);intent.setDataAndType(uri, "video/*");
startActivity(intent);
what you missed is simply the "/"
Hope this helps :)
Related
I want to play videos i have stored in the external storage with the phone's standard video Player app. I've tried using FileProvider, but I can't manage to pass the video to the player.
private void passVideo(String videoname){
File videoPath = new File(Environment.getExternalStorageDirectory(), "video_folder");
File newFile = new File(videoPath, videoname);
Uri path = FileProvider.getUriForFile(this, "com.example.provider", newFile);
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType(getContentResolver().getType(path))
.setStream(path)
.getIntent();
shareIntent.setData(path);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Open Video..."));
}
With this code I manage to get the Chooser for gmail, whatsapp and other social media platforms, but that's not what I want and they all say they can't handle the file format anyway. It also gives the option to play the video with VLC, but it instantly crashes.
I have tried every possible file format and none of them works.
Sorry if I'm missing something obvious, I am still a beginner.
ShareCompat.IntentBuilder is for ACTION_SEND, which is not the typical Intent action for playing a video. ACTION_VIEW would be more typical. So, try:
private void passVideo(String videoname){
File videoPath = new File(Environment.getExternalStorageDirectory(), "video_folder");
File newFile = new File(videoPath, videoname);
Uri uri = FileProvider.getUriForFile(this, "com.example.provider", newFile);
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
viewIntent.setType(getContentResolver().getType(uri));
viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(viewIntent);
}
i am working on an app, in which i want to play a video intenting ACTION VIEW from URL receiving from WEB SERVER, i am getting unsupportable file format. my code is
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
videostring = ib.getVideostring();
Uri data = Uri.parse("file:///https://" + videostring.get(0));
intent.setDataAndType(data, "video/*");
context.startActivity(intent);
Change Uri data = Uri.parse("file:///https://" + videostring.get(0));
to
Uri data = Uri.parse("https://" + videostring.get(0));
I need to play a mp4 video in my app, bat I want to use intent. Is this possible?
private void startTrailer(){
Uri contentUri = Uri.parse("android.resource://" + pkgName + "/" +R.raw.v01_homem_ferro_3);
Intent intent = new Intent( Intent.ACTION_VIEW );
intent.setDataAndType( contentUri, "video/mp4" );
context.startActivity( intent );
}
Exception: No Activity found to handle Intent.
Somebody had this issue before. Check these links and see if they give you a good starting point to solve the problem:
Android intent for playing video?
How to play a video (.mp4) from assets or raw folder with the video intent?
Please try this, Here strMyVideo is my filepath,
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strMyVideo));
intent.setDataAndType(Uri.parse(strMyVideo), "video/mp4");
activity.startActivity(intent);
i WAnna play a video that is in my assets folder. that can be played in any player installed in android.
Help OuT
Take a video view and media player in layout and in your activity onCreate you can do this
private VideoView video;
private MediaController ctlr;
uri=Uri.parse("android.resource://packagename/" + R.raw.famous);
video=(VideoView)findViewById(R.id.video);
video.setVideoURI(uri);
ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
video.start();
Here the video named famous is in raw folder in res. or you can keep in assets and change the file name based on that.
Code is tested and it works fine.
check this out :
Intent viewMediaIntent = new Intent();
viewMediaIntent.setAction(android.content.Intent.ACTION_VIEW);
Uri audio = Uri.parse("android.resource://com.audio.test/raw/"+R.raw.audio1);
Log.d(TAG,"uri:"+audio.toString());
viewMediaIntent.setDataAndType(audio, "video/*");
viewMediaIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Log.d(TAG,"Starting");
Intent i = Intent.createChooser(viewMediaIntent, "Play Music");
mGap.startActivity(i);
Log.d(TAG,"Started");
Intent intent1 = new Intent(
android.provider.MediaStore.INTENT_ACTION_MUSIC_PLAYER)
.setData(selectedImageUri);
i want to play a media file using android default media player but its not working in devices showing
ActivityNotFoundException
.can any one help me to correct it.i am stuck here
String extension = MimeTypeMap
.getFileExtensionFromUrl(selectedImagePath);
String mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension);
Intent mediaIntent = new Intent(Intent.ACTION_VIEW);
mediaIntent.setDataAndType(Uri.parse(selectedImagePath),
mimeType);
startActivity(mediaIntent);
I used this code and i got my output.
Maybe this will help you. The following is the piece which I use and it works fine. Pass the url to your default media Player and from there it will take care of it.
Uri myUri = Uri.parse( //your url);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(myUri, "audio/*");
startActivity(intent);