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");
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 video player when i share video and open that link its play on my default player not in my app. how to open that video on my app.
Here is my code(in fragment class):
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
"Hey check out my app at: "+share_video);
sendIntent.setType("text/plain");
startActivity(sendIntent);
Try this:- You may use the createChooser for your intent, which will displays all the app those are able to handle your intent.
For Example:-
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
"Hey check out my app at: "+share_video);
sendIntent.setType("text/plain");
Intent chooser = Intent.createChooser(sendIntent);
// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
Use video view:
for streaming a link u can do something like:
String LINK = "type_here_the_link";
VideoView mVideoView = (VideoView) findViewById(R.id.videoview);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
mVideoView.setMediaController(mc);
mVideoView.setVideoURI(video);
mVideoView.start();
>or for local video u can do something like:
VideoView videoView =(VideoView)findViewById(R.id.videoView1);
//Creating MediaController
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
//specify the location of media file
Uri uri=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/media/1.mp4");
//Setting MediaController and URI, then starting the videoView
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
> U can visit the link for more understanding:
> https://www.javatpoint.com/playing-video-in-android-example
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 :)
Bs"d
Hi everybody
I need to play a video
I have created an VideoView that takes uri parameter
and plays it
In Galaxy s2 and Galaxy s1 it works good but in Galaxy s3
it doesn't play
This is my source code
video=new VideoView(this);
MediaController mc = new MediaController(this);
video.setMediaController(mc);
Uri uri = Uri.parse(url);
video.setVideoURI(uri);
video.requestFocus();
setContentView(video);
video.start();
I am developing an application. I want to realize a function like that I want to call the system default player.
After downloading the custom Audio or video file. Could it play using the system audio and video player in the program?
I want to create intent, and give the file path. Then call the system’s player.
any idears?
Try This
videourl="/sdcard/zzzz.3gp";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videourl));
startActivity(intent);
String video = "http://www.nandudu.com/hls/course/video/2/test.m3u8";
Intent openVideo = new Intent(Intent.ACTION_VIEW);
openVideo.setDataAndType(Uri.parse(video), "video/*");
startActivity(openVideo);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videourl));
startActivity(intent);
The above code should works for you to play video files
For kotlin:
val path: String = contentUri.getPath()
val file = File(path)
val intent = Intent(
Intent.ACTION_VIEW,Uri.fromFile(file))
intent.setDataAndType(Uri.parse(path), "video/*")
startActivity(intent)