question

VuyiswaMaseko-8882 avatar image
0 Votes"
VuyiswaMaseko-8882 asked VuyiswaMaseko-8882 answered

Playing the live feed using WebView in Xamarin

Good Day All

I have a live stream site created with asp.net that works well. i want to show this in a Xamarin application using WebView. The following is the defination of the WebView

 >      <StackLayout>
 >             <WebView x:Name="webLive" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></WebView>
 >         </StackLayout>


and i am assigning the value like this


   ChannelToken = "AA7ED24C-9DFF-4C60-8B06-96EAFB749BB1";

     webLive.Source = "https://www.trovadating.com/Webview/Live_webview.aspx?channel_token=" + ChannelToken;

The URL works but my App does not want to play the video or live feed as depicted in the image below


245811-videonotplaying.png


dotnet-xamarin
videonotplaying.png (37.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT edited

Hello,

If you want to show webrtc, you need to add following permission in your AndroidManifest.xml.

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Then you need to create a custom renderer for your WebView to enable the JavaScript and request permission.

[assembly: ExportRenderer(typeof(WebView), typeof(MyWebview))]
namespace webviewPlayVideo.Droid
{
    internal class MyWebview : WebViewRenderer
    {
        public MyWebview(Context context) : base(context)
        {
        }
        protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
        {
            base.OnElementChanged(e);
            if (Control!=null) {
                Control.Settings.JavaScriptEnabled = true;
                Control.SetWebChromeClient(new MyWebChromeClient());
            }
            
        }
    }
   internal class MyWebChromeClient : Android.Webkit.WebChromeClient
    {
        public override void OnPermissionRequest(Android.Webkit.PermissionRequest request)
        {
            base.OnPermissionRequest(request);
            request.Grant(request.GetResources());
        }
    }
}

Please note: Test link is not working.



Best Regards,

Leon Lu



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VuyiswaMaseko-8882 avatar image
0 Votes"
VuyiswaMaseko-8882 answered

Thank you it worked 100%

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.