I take a video using MediaPicker from xamarin.labs and then upload this video to my web server. Then after that I retrieve this video for display in WebView using the HTML5 tag.
This works great for iOS. however, the same code does not work on Android.
I am creating my own renderer in android to create a Webchromeclient , but it does not play video on android.
html5 sample with video (I am also trying to use the type parameter in the <video> :
<Doctype! HTML> <html> <body><video src="www.myserver.com/video1.mp4" controls height="150" width="150"/> </body> </html/>
and this is my part of the web view in my PCL project:
public class MyWebView: WebView { }
this is my page:
public class VideoPage: ContentPage { public VidoePage() { var webView = new MyWebView(); webView.Source = new HtmlSource {Html = abovementionedHtml}; var layout = new StackLayout() { Childern = {webWiew} }; this.Content= layout; }
Android renderer:
[assembly: ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))] namespace VideoSample.Droid { using Xamarin.Forms.Platform.Android; public class MyWebViewRenderer : WebRenderer { protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); if (this.Control == null) { var webView = new global::Android.Webkit.WebView(this.Context); webView.SetWebChromeClient(new WebChromeClient()); webView.Settings.JavaScriptEnabled = true; webView.Settings.SetPluginState(WebSettings.PluginState.On); this.SetNativeControl(webView); } } } }
So can someone tell me what is wrong?
Thanks in advance.
source share