7

I'm developing an app that uses WebView (in a fragment) to load a YouTube page. But the page only plays audio, no video. Strange thing is that after clicking the HOME button then click the icon on the desktop to return to the app, the video plays fine. Other than that, no video only audio. The app works fine on normal Android devices, this BUG only happens on Kindle Fire tablet devices.

hardware accelerate is ON.

Here is the WebView settings:

        WebSettings webSettings = this.webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        this.webView.setOverScrollMode(WebView.OVER_SCROLL_IF_CONTENT_SCROLLS);
        this.webView.setWebViewClient(this.webViewClient);
        this.webView.setWebChromeClient(this.webView.getWebChromeClient());
        webView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null);
  • And what is your activity structure overall? This is merely a snippet, but are there any callbacks that restart anything in you code when you return. Try logging activity lifecycle for a start. – Bondax Apr 16 '15 at 09:18
  • Try `this.webView.setWebChromeClient(new WebChromeClient() {});` instead of your line. http://stackoverflow.com/questions/12708890/youtube-video-not-playing-in-webview-android – Moti Azu Apr 16 '15 at 09:18
  • HTML5 Video in WebView can sometimes be buggy or not work correctly. There is a [library here](https://github.com/cprcrack/VideoEnabledWebView), which you should check out. – Jonas Czech Apr 16 '15 at 09:18
  • @JonasCz I have used that library, it didn't solve my problem. –  Apr 16 '15 at 09:25
  • @MotiAzu My `WebChromeClient` is a little too complicated. Couldn't just use the default `new WebChromeClient()`. –  Apr 16 '15 at 09:27
  • @trantor Your code looks like it's setting `null` as a `WebChromeClient`. Unless you have set the client before hand and did it again for some reason. (?) – Moti Azu Apr 16 '15 at 09:33
  • @MotiAzu my `WebViewChromeClient` is a class over 200 lines of code. All my `WebView` related codes are more than 2000 lines. It's not possible to post all these code here. I don't think the code is somewhere wrong, because `after clicking the HOME button then click the icon on the desktop to return to the app, the video plays fine.`, I just don't understand Why should return to HOME page, then the `webview` works all fine. –  Apr 16 '15 at 09:39
  • @trantor You should update your question with these details, it says nothing about 2000 lines related to `WebView` that can cause problems. This line either sets `WebChromeClient` to itself, or keeps it null. What is this line supposed to do? `this.webView.setWebChromeClient(this.webView.getWebChromeClient());` – Moti Azu Apr 16 '15 at 12:09

2 Answers2

1

I dont know if you need an answer now or not. But I was having the same issue and when I removed the webView.setLayerType it worked.
Here is my webview setup-

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.setBackgroundColor(Color.TRANSPARENT);
Siddharth jain
  • 447
  • 1
  • 5
  • 13
-1

I have the same issue untill I remove the "autoplay" attribution of the video tag in my html file.