Cannot play video in WebView in Android 7.1.2 RRS feed

  • Question

  • User282595 posted

    I´m trying to play video in a WebView HTML video-element. Works fine in for example Android 9.0. But not in 7.1.2. It works in Chrome 78.0 on the same unit but not in an app.

    I have no settings at all. Just WebView in a Page. Works in 9.0 but not in 7.1.2 (and under?).

    Try theese with a WebView. https://play.bellaco.se/video https://play.bellaco.se/slider

    I have spend a couple of days to find anyone who has a solution but havent found any. I cannot update Android. The hardware don´t allow me.

    Strange that it works in Chrome. What can Chrome do that WebView cannot?

    Any ideas - please...

    Tuesday, December 10, 2019 4:31 PM

All replies

  • User382871 posted

    Android 8.0 provides several APIs to help you manage the WebView objects that display web content in your app. Tutorial.

    But not in 7.1.2. It works in Chrome 78.0 on the same unit but not in an app. For Android project, if the WebView doesn't support playing video in app. You can set the chrome handler for WebView and set android:hardwareAccelerated to true. In Xamarin.Forms, you need to create a WebView custom renderer to achieve this. Check the code:

    CsutomWebView class ``` public class CsutomWebView : WebView {

    } CustomWebViewRenderer class [assembly: ExportRenderer(typeof(CsutomWebView), typeof(CustomWebViewRenderer))] namespace App19F_2.Droid { public class CustomWebViewRenderer : WebViewRenderer { public CustomWebViewRenderer(Context context) : base(context) {

        protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
            if (Control != null)
                if ((int)Build.VERSION.SdkInt >= 19)
                    Control.SetLayerType(Android.Views.LayerType.Hardware, null);
                    Control.SetLayerType(Android.Views.LayerType.Software, null);
                Control.SetWebChromeClient(new Android.Webkit.WebChromeClient());

    } ```

    Wednesday, December 11, 2019 9:07 AM
  • User382871 posted

    Do you have some update? If the reply solved your issue, please mark the helpful reply as answer. If you are facing some issues while implementing, try to post the particular error with the corresponding codes here.

    Monday, December 23, 2019 2:22 PM