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.)
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 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.
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);
I want to play video files in my application which are part of my application.
for that i create 'raw' folder in 'res' and write following code in my activity.
MediaPlayer mp = MediaPlayer.create(VideoPlayer.this,R.raw.jeevrangala);
mp.start();
now i am testing it on emulator, but it does not displaying any thing.
is any one have solution to play video files in raw folder. please let me know.
Initial i was trying to play video files from raw folder. but cant run it. so i use another way to do this
VideoView video=(VideoView) findViewById(R.id.videoview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
//Uri uri = Uri.parse("android.resource://play.vedio/"+R.raw.dobeernotdrugs);
video.setKeepScreenOn(true);
video.setVideoPath("android.resource://one.two/raw/"+resource);
video.start();
video.requestFocus();
resource is file name which you want to play and one.two is package name your path may as like
"android.resource://package_name/raw/file_name"
You can use this code to run video on emulator.. for me it is working
VideoView videoHolder = (VideoView) findViewById(R.id.video_view);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.samplevideo);
videoHolder.setVideoURI(video);
videoHolder.start();
And please turn on your graphics acceleration for the emulator..
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.