Playing the live feed using WebView in Xamarin

Vuyiswa Maseko 351 Reputation points
2022-09-28T22:03:20.677+00:00

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

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,300 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,311 Reputation points Microsoft Vendor
    2022-09-29T06:11:41.887+00:00

    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vuyiswa Maseko 351 Reputation points
    2022-09-29T23:00:28.997+00:00

    Thank you it worked 100%

    0 comments No comments