1

ve build a webRTC application that allows streaming audio and video via web using javascript, now i need to run this web application on my phone

i need to run this webrtc app on mobile webview, its working fine, but camera and audio not working any help will be thankful.

fawadayub
  • 17
  • 5

1 Answers1

0

in iOS

You just need to add the permission in Info.plistlike the following

Key:Privacy - Microphone Usage Description  
Value: Do you allow this App to use your microphone ?

Key:Privacy - Photo Library Usage Description  
Value: Do you allow this App to access your media library?

Key:Privacy - Camera Usage Description  
Value: Do you allow this App to use your camera ?

enter image description here

in Android

Add the permission in Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.app18" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
    <application android:label="App18.Android"></application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
</manifest>

And use the custom renderer in Android project

[assembly: ExportRenderer(typeof(WebView), typeof(MyWebViewRenderer))]
namespace xxx.Droid
{
    public class MyWebViewRenderer : WebViewRenderer
    {
        Activity mContext;
        public MyWebViewRenderer(Context context) : base(context)
        {
            this.mContext = context as Activity;
        }
            protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);
            Control.Settings.JavaScriptEnabled = true;
            Control.ClearCache(true);
            Control.SetWebChromeClient(new MyWebClient(mContext));
        }
        public class MyWebClient : WebChromeClient
        {
            Activity mContext;
            public MyWebClient(Activity context) {
                this.mContext = context;
            }
            [TargetApi(Value = 21)]
            public override void OnPermissionRequest(PermissionRequest request)
            {
                mContext.RunOnUiThread(() => {
                        request.Grant(request.GetResources());

                        });

            }
        }

    }

}
Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22