public virtual void SetupVideo(Guid id) { global::Android.App.Application.SynchronizationContext.Post(_ => { AgoraVideoViewHolder <FrameLayout> container = _containers.FirstOrDefault(a => a.GUID == id); if (container == null) { return; } SurfaceView layout = RtcEngine.CreateRendererView(container.NativeView.Context); layout.SetZOrderMediaOverlay(true); container.NativeView.AddView(layout); VideoCanvas canvas = new VideoCanvas(layout, (int)container.VideoView.Mode, (int)container.StreamUID); container.VideoView.IsOffline = false; if (container.StreamUID == 0 || container.StreamUID == _myId) { _agoraEngine?.SetupLocalVideo(canvas); _agoraEngine?.StartPreview(); } else { _agoraEngine?.SetupRemoteVideo(canvas); } container.NativeView.Visibility = ViewStates.Visible; }, null); }
public void OnUserOffline(int uid, int reason) { RunOnUiThread(async() => { FrameLayout container = (FrameLayout)FindViewById(Resource.Id.remote_video_view_container); IMethods.AudioRecorderAndPlayer.PlayAudioFromAsset("Error.mp3"); container.RemoveAllViews(); UserInfoview_container.Visibility = ViewStates.Visible; NoteTextView.Text = this.GetText(Resource.String.Lbl_Lost_his_connection); await Task.Delay(3000); try { AgoraEngine.StopPreview(); } catch (Exception e) { Console.WriteLine(e); } try { AgoraEngine.SetupLocalVideo(null); AgoraEngine.LeaveChannel(); AgoraEngine.Dispose(); } catch (Exception e) { Console.WriteLine(e); } AgoraEngine = null; Finish(); }); }
protected override void OnDestroy() { try { //Close Api Starts here >> PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => ApiRequest.Send_Agora_Call_Action_Async("close", CallId) }); if (AgoraEngine != null) { AgoraEngine.StopPreview(); AgoraEngine.SetupLocalVideo(null); AgoraEngine.LeaveChannel(); AgoraEngine.Dispose(); AgoraEngine = null; } base.OnDestroy(); } catch (Exception e) { Methods.DisplayReportResultTrack(e); base.OnDestroy(); } }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; int ret = 0; base.OnCreate(savedInstanceState); SetContentView(layoutResID: Resource.Layout.RemoteStream1); _layout = FindViewById(Resource.Id.remote_stream1); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); // Step #5 AgoraHandler = new AgoraRtcHandler(this); AgoraEngine = RtcEngine.Create(BaseContext, "c6122ec557d54eb09783b44f90cbfc7b", AgoraHandler); AgoraEngine.EnableWebSdkInteroperability(true); AgoraEngine.EnableVideo(); AgoraEngine.SetVideoProfile(Constants.VideoProfile360p, false); ret = AgoraEngine.JoinChannel( "006c6122ec557d54eb09783b44f90cbfc7bIACLw1riRkApB6HfNVEIKm7Ejz1U3Vd08e6z4rqsJNAsc1iNuxORY278FgACAAAAAAAAAAIAAQAAAAAAAwAAAAAA", "test2", string.Empty, 198); SystemDebug.WriteLine("### JOIN CHANNEL RETURN: " + ret); }
/// <summary> /// Setups the video. /// </summary> /// <param name="uid">Uid.</param> public virtual void SetupVideo(uint uid) { global::Android.App.Application.SynchronizationContext.Post(_ => { AgoraVideoViewHolder <FrameLayout>[] containers = _containers.Where(a => a.StreamUID == uid).ToArray(); if (containers.Length == 0) { return; } containers.ToList().ForEach(container => { SurfaceView layout = RtcEngine.CreateRendererView(container.NativeView.Context); layout.SetZOrderMediaOverlay(true); container.NativeView.AddView(layout); VideoCanvas canvas = new VideoCanvas(layout, (int)container.VideoView.Mode, (int)uid); container.VideoView.IsOffline = false; if (_agoraEngine != null) { if (uid == 0 || uid == _myId) { _agoraEngine.SetupLocalVideo(canvas); _agoraEngine.StartPreview(); } else { _agoraEngine.SetupRemoteVideo(canvas); } } container.NativeView.Visibility = ViewStates.Visible; }); }, null); }
public void OnEncCallClicked(View view) { AgoraEngine.StopPreview(); AgoraEngine.SetupLocalVideo(null); AgoraEngine.LeaveChannel(); AgoraEngine.Dispose(); AgoraEngine = null; Finish(); }
private void SetupLocalVideo() { FrameLayout container = (FrameLayout)FindViewById(Resource.Id.local_video_view_container); SurfaceView surfaceView = RtcEngine.CreateRendererView(BaseContext); surfaceView.SetZOrderMediaOverlay(true); container.AddView(surfaceView); _rtcEngine.SetupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RenderModeAdaptive, 0)); }
public void EndCall(View view) { _rtcEngine.StopPreview(); _rtcEngine.SetupLocalVideo(null); _rtcEngine.LeaveChannel(); _rtcEngine.Dispose(); _rtcEngine = null; Finish(); }
private void InitializeAgoraEngine() { try { AgoraHandler = new AgoraRtcHandler(this); AgoraEngine = RtcEngine.Create(BaseContext, AgoraSettings.AgoraAPI, AgoraHandler); } catch (Exception e) { Console.WriteLine(e); } }
private void InitializeAgoraEngine() { try { AgoraHandler = new AgoraRtcHandler(this); AgoraEngine = RtcEngine.Create(BaseContext, AgoraSettings.AgoraApi, AgoraHandler); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Join); _layout = FindViewById(Resource.Id.joinLayout); CheckPermissions(); FindViewById <EditText>(Resource.Id.channelName).Text = AgoraSettings.Current.RoomName; FindViewById <EditText>(Resource.Id.encryptionKey).Text = AgoraSettings.Current.EncryptionPhrase; AgoraHandler = new AgoraQualityHandler(this); AgoraEngine = RtcEngine.Create(BaseContext, AgoraTestConstants.AgoraAPI, AgoraHandler); AgoraEngine.EnableWebSdkInteroperability(true); AgoraEngine.EnableLastmileTest(); FindViewById <TextView>(Resource.Id.agora_version_text).Text = string.Format(VersionFormat, RtcEngine.SdkVersion); }
protected override void OnDestroy() { if (AgoraHandler != null) { AgoraHandler.Dispose(); AgoraHandler = null; } if (AgoraEngine != null) { AgoraEngine.Dispose(); AgoraEngine = null; } base.OnDestroy(); }
private void SetupRemoteVideo(int uid) { FrameLayout container = (FrameLayout)FindViewById(Resource.Id.remote_video_view_container); if (container.ChildCount >= 1) { return; } SurfaceView surfaceView = RtcEngine.CreateRendererView(BaseContext); container.AddView(surfaceView); _rtcEngine.SetupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RenderModeAdaptive, uid)); surfaceView.Tag = uid; }
/// <summary> /// Ends the session. /// </summary> public virtual void EndSession() { _containers.Clear(); _knownStreams.Clear(); _myId = 0; _agoraEngine.SetupRemoteVideo(null); _agoraEngine.StopPreview(); _agoraEngine.SetupLocalVideo(null); _agoraEngine.StopAudioRecording(); _agoraEngine.LeaveChannel(); _agoraEngine.Dispose(); _agoraEngine = null; RtcEngine.Destroy(); }
private void SetupLocalVideo() { FrameLayout container = (FrameLayout)FindViewById(Resource.Id.local_video_view_container); _localVideoView = RtcEngine.CreateRendererView(BaseContext); _localVideoView.SetZOrderMediaOverlay(true); container.AddView(_localVideoView); AgoraEngine.SetupLocalVideo(new VideoCanvas(_localVideoView, VideoCanvas.RenderModeAdaptive, 0)); if (!string.IsNullOrEmpty(AgoraSettings.Current.EncryptionPhrase)) { AgoraEngine.SetEncryptionMode(AgoraSettings.Current.EncryptionType.GetModeString()); AgoraEngine.SetEncryptionSecret(AgoraSettings.Current.EncryptionPhrase); } AgoraEngine.StartPreview(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); CheckPermissions(); _rtcEventHandler = new RtcEventHandler(this); _rtcEngine = RtcEngine.Create(BaseContext, "f02659d5a175465f96e45614761ddb07", _rtcEventHandler); _rtcEngine.SetVideoProfile(Constants.ChannelProfileCommunication, false); _rtcEngine.EnableVideo(); SetVideoEncoder(); SetupLocalVideo(); JoinChannel(); }
private void InitRtcEngine() { try { MRtcEngine = DT.Xamarin.Agora.RtcEngine.Create(ApplicationContext, AppSettings.AppIdAgoraLive, MHandler); // Sets the channel profile of the Agora RtcEngine. // The Agora RtcEngine differentiates channel profiles and applies different optimization algorithms accordingly. For example, it prioritizes smoothness and low latency for a video call, and prioritizes video quality for a video broadcast. MRtcEngine.SetChannelProfile(DT.Xamarin.Agora.Constants.ChannelProfileLiveBroadcasting); MRtcEngine.EnableVideo(); MRtcEngine.SetLogFile(FileUtil.InitializeLogFile(this)); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void SetupRemoteVideo(int uid) { _remoteId = (uint)uid; FrameLayout container = (FrameLayout)FindViewById(Resource.Id.remote_video_view_container); if (container.ChildCount >= 1) { return; } SurfaceView surfaceView = RtcEngine.CreateRendererView(BaseContext); container.AddView(surfaceView); AgoraEngine.SetupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RenderModeAdaptive, uid)); surfaceView.Tag = uid; // for mark purpose RefreshDebug(); }
protected override void OnDestroy() { AgoraEngine.DisableLastmileTest(); if (AgoraHandler != null) { AgoraHandler.Dispose(); AgoraHandler = null; } if (AgoraEngine != null) { AgoraEngine.Dispose(); AgoraEngine = null; } RtcEngine.Destroy(); RtmService.Instance.Logout(); base.OnDestroy(); }
private void InitializeAgoraEngine() { try { var handler = new RtcEngineEventHandler(); handler.DidJoinChannel += () => RunOnUiThread(() => Toast.MakeText(this, "Joined to channel", ToastLength.Short).Show()); handler.OnRemoteUserJoined += (uid) => RunOnUiThread(() => Toast.MakeText(this, $"User {uid} has joined", ToastLength.Short).Show()); handler.OnRemoteUserLeft += (uid) => RunOnUiThread(() => Toast.MakeText(this, $"User {uid} has left", ToastLength.Short).Show()); handler.OnRemoteUserVoiceMuted += (uid, muted) => RunOnUiThread(() => Toast.MakeText(this, $"User {uid} is {(muted ? "muted" : "unmuted" )}", ToastLength.Short).Show()); _rtcEngine = RtcEngine.Create(this, AgoraTestConstants.AgoraAPI, handler); _rtcEngine.SetChannelProfile(Constants.ChannelProfileCommunication); } catch (Exception) { Toast.MakeText(this, "Colud not create RtcEngine", ToastLength.Short).Show(); } }
/// <summary> /// Starts the session. /// </summary> /// <param name="sessionId">Session identifier.</param> /// <param name="agoraAPI">Agora API key.</param> public void StartSession(string sessionId, string agoraAPI, string token, VideoAgoraProfile profile = VideoAgoraProfile.Portrait360P, bool swapWidthAndHeight = false, bool webSdkInteroperability = false) { _knownStreams.Add(_myId); _agoraHandler = new AgoraRtcEngineEventHandler(this); _agoraEngine = RtcEngine.Create(global::Android.App.Application.Context, agoraAPI, _agoraHandler); _agoraEngine.EnableWebSdkInteroperability(webSdkInteroperability); _agoraEngine.SetChannelProfile(Constants.ChannelProfileCommunication); //_agoraEngine.SetVideoProfile(Constants.VideoProfile360p, false); <2.3.0 _agoraEngine.SetVideoEncoderConfiguration(GetVideoConfig(profile)); _agoraEngine.EnableLocalVideo(true); _agoraEngine.EnableVideo(); _agoraEngine.SwitchCamera(); _agoraEngine.SetEnableSpeakerphone(true); // if you do not specify the uid, we will generate the uid for you _agoraEngine.JoinChannel(token, sessionId, string.Empty, 0); }
public async void OnCallTime_Running_Out() { try { var ckd = GlobalContext?.LastCallsTab?.MAdapter?.MCallUser?.FirstOrDefault(a => a.Id == CallId); // id >> Call_Id if (ckd == null) { Classes.CallUser cv = new Classes.CallUser { Id = CallId, UserId = UserId, Avatar = Avatar, Name = Name, FromId = FromId, Active = Active, Time = "Missed call", Status = Status, RoomName = RoomName, Type = CallType, TypeIcon = "Cancel", TypeColor = "#FF0000" }; GlobalContext?.LastCallsTab?.MAdapter?.Insert(cv); SqLiteDatabase dbDatabase = new SqLiteDatabase(); dbDatabase.Insert_CallUser(cv); dbDatabase.Dispose(); } Methods.AudioRecorderAndPlayer.StopAudioFromAsset(); Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Error.mp3"); DurationTextView.Text = GetText(Resource.String.Lbl_No_respond_from_the_user); await Task.Delay(3000); AgoraEngine.LeaveChannel(); AgoraEngine.Dispose(); AgoraEngine = null; Finish(); } catch (Exception e) { Finish(); Console.WriteLine(e); } }
public async void OnCallTime_Running_Out() { try { var ckd = Last_Calls_Fragment.mAdapter?.mCallUser?.FirstOrDefault(a => a.id == CALL_ID); // id >> Call_Id if (ckd == null) { Classes.Call_User cv = new Classes.Call_User { id = CALL_ID, user_id = UserID, avatar = avatar, name = name, from_id = from_id, active = active, time = "Missed call", status = status, room_name = ROOM_NAME, type = CALL_TYPE, typeIcon = "Cancel", typeColor = "#FF0000" }; Last_Calls_Fragment.mAdapter?.Insert(cv); SqLiteDatabase dbDatabase = new SqLiteDatabase(); dbDatabase.Insert_CallUser(cv); dbDatabase.Dispose(); } IMethods.AudioRecorderAndPlayer.StopAudioFromAsset(); IMethods.AudioRecorderAndPlayer.PlayAudioFromAsset("Error.mp3"); DurationTextView.Text = this.GetText(Resource.String.Lbl_No_respond_from_the_user); await Task.Delay(3000); AgoraEngine.LeaveChannel(); AgoraEngine.Dispose(); AgoraEngine = null; Finish(); } catch (Exception e) { Finish(); Console.WriteLine(e); } }
/// <summary> /// Starts the session. /// </summary> /// <param name="sessionId">Session identifier.</param> /// <param name="agoraAPI">Agora API key.</param> public void StartSession(string sessionId, string agoraAPI, VideoAgoraProfile profile = VideoAgoraProfile.Portrait360P, bool swapWidthAndHeight = false, bool webSdkInteroperability = false) { _knownStreams.Add(_myId); _agoraHandler = new AgoraRtcEngineEventHandler(this); _agoraEngine = RtcEngine.Create(global::Android.App.Application.Context, agoraAPI, _agoraHandler); _agoraEngine.EnableWebSdkInteroperability(webSdkInteroperability); _agoraEngine.SetChannelProfile(Constants.ChannelProfileCommunication); _agoraEngine.EnableVideo(); _agoraEngine.EnableAudio(); _agoraEngine.SetAudioProfile(1, 2); _agoraEngine.EnableDualStreamMode(true); _agoraEngine.SetDefaultAudioRoutetoSpeakerphone(true); _agoraEngine.SetVideoEncoderConfiguration(BaseVideoEncoding); _agoraEngine.SetHighQualityAudioParameters(true, true, true); _agoraEngine.EnableLastmileTest(); // if you do not specify the uid, we will generate the uid for you _agoraEngine.JoinChannel(null, sessionId, string.Empty, 0); }
public void InitAgoraEngineAndJoinChannel(string roomName) { try { AgoraHandler = new AgoraRtcAudioCallHandler(this); AgoraEngine = RtcEngine.Create(BaseContext, AgoraSettings.AgoraApi, AgoraHandler); AgoraEngine.DisableVideo(); AgoraEngine.EnableAudio(); AgoraEngine.SetEncryptionMode("aes-128-xts"); AgoraEngine.SetEncryptionSecret(""); AgoraEngine.JoinChannel(null, roomName, string.Empty, 0); AgoraEngine.SetEnableSpeakerphone(false); } catch (Exception e) { Console.WriteLine(e); } }
public async void OnCall_Declined_From_User() { try { Methods.AudioRecorderAndPlayer.StopAudioFromAsset(); Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Error.mp3"); DurationTextView.Text = GetText(Resource.String.Lbl_The_user_declinde_your_call); await Task.Delay(3000); AgoraEngine.LeaveChannel(); AgoraEngine.Dispose(); AgoraEngine = null; Finish(); } catch (Exception e) { Console.WriteLine(e); } }
private void SetupRemoteVideo(int uid) { try { FrameLayout container = (FrameLayout)FindViewById(Resource.Id.remote_video_view_container); if (container.ChildCount >= 1) { return; } SurfaceView surfaceView = RtcEngine.CreateRendererView(BaseContext); container.AddView(surfaceView); AgoraEngine.SetupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RenderModeAdaptive, uid)); surfaceView.Tag = uid; // for mark purpose } catch (Exception e) { Console.WriteLine(e); } }
private void InitializeAgoraAndroidControl(FrameLayout container, int uid) { Console.WriteLine($"Renderer - we should show stream with uid = {uid}"); if (uid == 0) { //stop video } else { if (container.ChildCount == 0) { var surfaceView = RtcEngine.CreateRendererView(DemoHelper.Context); container.AddView(surfaceView); var videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RenderModeHidden, uid); var rtcEngine = DemoHelper.CurrentAgoraEngine.RtcEngine; var result = rtcEngine.SetupRemoteVideo(videoCanvas); Console.WriteLine($"Set remote video result {result}"); } } }
public override void OnBackPressed() { try { IMethods.AudioRecorderAndPlayer.StopAudioFromAsset(); AgoraEngine.StopPreview(); AgoraEngine.SetupLocalVideo(null); AgoraEngine.LeaveChannel(); AgoraEngine.Dispose(); AgoraEngine = null; Finish(); base.OnBackPressed(); } catch (Exception e) { Console.WriteLine(e); base.OnBackPressed(); } }
public async void OnCall_Declined_From_User() { try { IMethods.AudioRecorderAndPlayer.StopAudioFromAsset(); IMethods.AudioRecorderAndPlayer.PlayAudioFromAsset("Error.mp3"); NoteTextView.Text = this.GetText(Resource.String.Lbl_The_user_declinde_your_call); await Task.Delay(3000); if (AgoraEngine != null) { try { AgoraEngine.StopPreview(); } catch (Exception exception) { Console.WriteLine(exception); } try { AgoraEngine.SetupLocalVideo(null); AgoraEngine.LeaveChannel(); } catch (Exception exception) { Console.WriteLine(exception); } AgoraEngine.Dispose(); AgoraEngine = null; } Finish(); } catch (Exception exception) { Finish(); Console.WriteLine(exception); } }