2

I'd like to play a video using WebView capabilities. Currently I'm able to play the following html in all browsers I've tested (Chrome, Chrome for Android, Navegator for Android). Unfortunately, I can not get it playing inside my own application using a WebView: the player's controls are shown, but clicking at play button make the seek bar goes to the end and a progress circle takes place and never ends. Here are the relevant code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);

    WebView webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl("file:///android_asset/www/index.html");
}

index.html:

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>video1</title>
</head>
<body>
<video id="video" controls height="240" width="360">
<source src="index.files/html5video/video1.m4v">
</video>
<script type="text/javascript">
    var vid=document.getElementById('video');
vid.addEventListene('click', function () {
    vid.play();
}, false);
</script>
</body>

You can rely that all files are placed in the right place.

Plinio.Santos
  • 1,709
  • 24
  • 31
  • Check these links could help you http://www.tandroid.org/html5webview http://stackoverflow.com/questions/3815090/webview-and-html5-video/3882736#3882736 http://stackoverflow.com/questions/12403380/android-webview-doesnt-playing-mp4-video-in-same-page – S.A.Norton Stanley Sep 26 '13 at 15:23
  • I had seen them already, but they were not helpful so far. – Plinio.Santos Sep 26 '13 at 19:51

2 Answers2

2

I know this is an old post, but I was having the same issue on my Galaxy S3. I solved it with this :

webView.SetWebChromeClient (new WebChromeClient ());

It worked just fine on Nexus 7 without this line, but on Galaxy S3 for some reason it just spun the loading circle forever.

NOTE: I also have these set:

webView.Settings.PluginsEnabled = true;
webView.Settings.JavaScriptEnabled = true;
webView.Settings.SetPluginState (WebSettings.PluginState.On);
webView.SetWebViewClient (new WebViewClient ());
Kibler88
  • 39
  • 4
0

I had the same problem, none of solutions found at others helped me. I have tried many different ways to solve this, but I didn't managed. So, my solution was to display a thumb instead of video, this thumb was an image linking to video source and when this thumb pressed, the video starts in Android native video player. You could try this if didn't resolved it yet.

Later, I found this: https://code.google.com/p/googletv-android-samples/source/browse/#git%2FWebAppNativePlayback It works by playing video in webview as you want, but the problem is you can not control video controls from D-pad keyboard.

Hope you got a solution!

MariusR
  • 53
  • 1
  • 4
  • If I could understood the googletv-android-sample right, it is not playing the video using HTML5 – Plinio.Santos Nov 08 '13 at 14:19
  • I did not. Actually I abandoned the webview approach. – Plinio.Santos Nov 11 '13 at 17:42