Reputation: 37
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..
Upvotes: 2
Views: 2392
Reputation: 28665
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.)
Upvotes: 1
Reputation: 7306
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
Upvotes: 1
Reputation: 10274
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.
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();
Upvotes: 1