I am capturing video using MediaPicker
from xamarin.labs
and then upload that video on my web server. Then after, I retrieve that video to show in WebView with HTML5 video tag.
This works fine for iOS. however the same code doesn't work on Android.
I create custom renderer in android to create Webchromeclient
but it does not play video on android.
the sample html5 with video is (I also try with type
parameter in <video>
tag:
<Doctype! HTML>
<html>
<body><video src="www.myserver.com/video1.mp4" controls height="150" width="150"/>
</body>
</html/>
and this is my web view part 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 anyone tell me what is wrong ?
Thanks in advance.
Try to replace the sample HTML as below with some fixes. Not sure if this is the root cause.
<!DOCTYPE html>
<html>
<body>
<video src="http://www.myserver.com/video1.mp4" controls height="150" width="150">
</body>
</html>
I made the adjustments for two things:
Also, you may refer to this blog post (Making HTML5 Video work on Android phones) for further HTML tips and tricks on making video work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With