VideoView is unable to play video from Resource - android

I have checked other questions, and applied the solution available in them, but still it is not working.
I have placed a video in my raw folder. I am getting the video by using following method
String path = "android.resource://" + getPackageName() + "/"+ R.raw.splash_video;
videoView= (VideoView) findViewById(R.id.splash_videoView);
Uri uri= Uri.parse(path);
videoView.setVideoURI(uri);
videoView.start();
The video is in mp4 format, When i run my program, it displays me Can't play the video message.
When i debug the code, i found out that, it changes the path value to this:
path= android.resource:///2131099757
If i change the path to Some URL, it successfully plays the video.
String path= "www.abc.com/someVideo.mp4"
Kindly guide me how to play mp4 video from raw

Try with this URL.
String uriPath = "android.resource://"+getPackageName()+"/raw/myvideo";
Where myvideo is your video file name.

Related

Android Studio not recognising raw file on windows 10

I have added a raw file to my Res file but in java its not recognising the raw file or the mp4 file. Please see screen shot with highlights below
If you want to reproduce the video, see the code below.
VideoView videoView = (VideoView) findViewById(R.id.videoView_video);
Uri path = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.starwars);
videoView.setVideoURI(path);
videoView.start();
Remove the extension (.mp4)

can't play video file using Uri in android

Hi i want to play a video file but after showing video it is showing error that can't play video file i am using Video view and path of video is
Uri uri=Uri.parse(Environment.getRootDirectory().getPath()+"/Phone storage/video.mp4");
Can some help me how to play video file that is store on my phone
You should use Uri.fromFile instead of Uri.parse
Create "raw" folder in "res", copy your video file to raw folder, in your code you should to do that :
String UrlPath = "android.resource://" + getPackageName() + "/"
+ R.raw.your_video_name;
Uri video_uri = Uri.parse(UrlPath);
video.setVideoURI(video_uri);
video.setMediaController(new MediaController(this));
video.requestFocus();
video.start();
Try out this way:
Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"Phone storage"+File.separator+"video.mp4");

video view error (can't play this video) what is wrong with my code?

I'm trying to access the video file under assets folder. But When I run this, it shows error message(can't play this video file). I doubt something wrong with path.
videoView = (VideoView)findViewById(R.id.VideoView);
videoView.setVideoPath("file:///android_asset/testdoc.mp4");
videoView.start();
Use raw folder rather than asset:
String videoPath = android.resource://+ getPackageName() +/raw/testdoc";
Uri uri = Uri.parse(videoPath);
video.setVideoURI(uri);

Add and Access a video file in android project

I just wanted to run a predefined video file when a button is clicked. I have added this video file into res/raw folder in myVideApp project. Now I need to pass this path to videoView.setVideoPath() in order to play the video.
How can I access the stored video file's actual path in android. Note: I don't want to open the file. just want the actual location of the file to pass to video view.
I tried "path = this.getResources().getString(R.raw.bbc);" but its not working since it gives the path relative to the current project. but videoview needs absolute path.
Thank you,
Regards,
Robo.
Following Snippet will help you.
getWindow().setFormat(PixelFormat.TRANSLUCENT);
videoView = new VideoView(this);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/" + R.raw.bbc); //Don't put extension
videoView.requestFocus();
setContentView(videoView);
videoView.start();
Following are steps to access video file and to play video
Get Video Control
create media controller
Get Video path from local resorce
Set media controller to video
set path of video in video control
Set Focus
Start Video
.
VideoView videoView = (VideoView)findViewById(R.id.videoViewGuide);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri = Uri.parse("android.resource:// " + getPackageName() + "/" + R.raw.Guide_Video_01);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();

I want to play a video from my assets or raw folder

I want to play a video from my assets or raw folder in my app in Android
using VideoView I am getting the error as video cannot be played
please anyone give me a solution.
Here is the code I used
VideoView vd = (VideoView)findViewById(R.id.Video);
Uri uri = Uri.parse("android.resource:" + R.raw.video);
MediaController mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
vd.start();
A few things to note:
You must copy the video into your project's res/raw folder.
It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename: my_video_file.mp4
When you work with this resource in code, you will reference through the generated R statics - it will have the file extension removed: R.raw.my_video_file
The Activity class has a helper method getPackageName() which can be used by your code when constructing the correct URI to your video.
VideoView vv = (VideoView)this.findViewById(R.id.videoView)
String uri = "android.resource://" + getPackageName() + "/" + R.raw.my_video_file;
vv.setVideoURI(Uri.parse(uri));
vv.start();
There is more information on this here.
You must include the package name in the uri:
Uri uri = Uri.parse("android.resource://[package]/raw/video")
or
Uri uri = Uri.parse("android.resource://[package]/"+R.raw.video);
Also, check out these examples.
There are so many ways to go wrong with VideoView ! Mainly because the logcat gives you no help, always giving error UNKNOWN.
I found this link was by far the best way to get started...
A complete description so you can't go wrong. Thanks go to the author...
http://androidexample.com/Play_Video_File_-_Android_Example/index.php?view=article_discription&aid=124&aaid=144
When we include a video resource in /resource/raw/ or assets/, by default, it looks for the .mp4 format, it won't accept .wmv files. If you read video file from external locations(like: /mnt/sdcard/demo.wmv) then it'll accept them.
Try:
AssetFileDescriptor afd = getAssets().openFd(fileName);
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
Make sure to write the file video name without extension.

Categories

Resources