I'm using VideoView and MediaController attached to it
i know how to load a video from the raw folder and how to load a url
but i'm unable to load a local file that sits in the Assets folder
i saw some way to do it with a MediaPlayer and SurfaceView, but i'm seeking a way to do so without changing the all activity and layout
Thanks
try using the function getAssets().open("videofile")
Try
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw....);
videoView.setVideoURI(uri);
Related
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)
I'm beginner in android and want to play gif animation in android video view so my gif file in this image show:
and write this code for play that:
VideoView videoView = (VideoView)findViewById(R.id.video_view);
videoView.setVideoPath("raw/newline.gif");
videoView.start();
but when run that app,i get error,can not play this video,why?
Try this code:
Uri uri= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.newline);
videoView.setVideoURI(uri);
videoView.start();
Your mistake is that you can't just specify a path to resource file. In this case you have to use Uri.
But AFAIK VideoView can't play gif. So check out this and this solutions.
my activity_main.xml
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true" />
my main activity
ws = (WebSettings) wb.getSettings();
wb.setWebChromeClient(new WebChromeClient());
ws.setJavaScriptEnabled(true);
wb.loadUrl("File:///android_asset/www/html5.html");
myhtml
<source src="playlist.mp4" type="video/mp4">
i'm load video from asset. directory my video asset/www/playlist.mp4
but it's not working..
How to Play Video from asset in Webview Android.
we can't play video in webview from asset folder. even its very difficult to play video
from server url in webview. all we can do is to make a custom HTML5 webview and then we
can play.but this is very long process.
Suggestion and Solution
Its better to use videoview provided by android.and put your video in raw folder not in assets.use the below code to play video from Raw folder in your app:
getWindow().setFormat(PixelFormat.TRANSLUCENT);
VideoView _view= new VideoView(this);
_view.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.your_raw_file); //add file without any extension
_view.setVideoURI(video);
setContentView(_view);
_view.start();
Better You use VideoView
VideoView videoHolder = new VideoView(this);
setContentView(videoHolder);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.splash); // you file name
videoHolder.setVideoURI(video);
Reference Link to follow and this
I'm using a different approach. Instead of putting the video into the assets folder, I base64 encode it and put it directly into the html file / source code.
Since videos in the assets folders are fix, they won't change anyway, and neither does the html file probably. Therefore, why not put the video directly into the html page.
The effect is the same, and it works without problems.
Example: http://iandevlin.com/html5/data-uri/video.php
Base64 Encoder (online): http://www.opinionatedgeek.com/dotnet/tools/base64encode/
(It doesn't really answer the question about video playback from the assets folder, but the result is the same imho.)
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");
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();