private void InitComponent()
        {
            try
            {
                MainUserViewProfile = FindViewById <RelativeLayout>(Resource.Id.userInfoview_container);
                UserPrimaryVideo    = FindViewById <VideoView>(Resource.Id.userthumbnailVideo);         // userthumbnailVideo
                ThumbnailVideo      = FindViewById <VideoView>(Resource.Id.local_video_view_container); //local_video_view_container
                SwitchCamButton     = FindViewById <Button>(Resource.Id.switch_cam_button);
                MuteVideoButton     = FindViewById <CircleButton>(Resource.Id.mute_video_button);
                EndCallButton       = FindViewById <CircleButton>(Resource.Id.end_call_button);
                MuteAudioButton     = FindViewById <CircleButton>(Resource.Id.mute_audio_button);
                UserImageView       = FindViewById <ImageView>(Resource.Id.userImageView);
                UserNameTextView    = FindViewById <TextView>(Resource.Id.userNameTextView);
                NoteTextView        = FindViewById <TextView>(Resource.Id.noteTextView);

                PictureInToPictureButton = FindViewById <ImageView>(Resource.Id.pictureintopictureButton);
                if (!PackageManager.HasSystemFeature(PackageManager.FeaturePictureInPicture))
                {
                    PictureInToPictureButton.Visibility = ViewStates.Gone;
                }

                MuteVideoButton.Selected = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
 void UpdateTrackRenderer(TwilioVideo.VideoTrack videoTrack, TwilioVideo.VideoView renderer)
 {
     if (videoTrack != null && !IsDestroyed && !IsFinishing)
     {
         videoTrack.AddRenderer(renderer);
     }
     renderer.Visibility = videoTrack == null ? ViewStates.Invisible : ViewStates.Visible;
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.VideoCall);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            _btnEndCall         = FindViewById <AppCompatImageView>(Resource.VideoCall.btnEndCall);
            _cbMute             = FindViewById <AppCompatCheckBox>(Resource.VideoCall.cbMute);
            _btnFlip            = FindViewById <AppCompatCheckBox>(Resource.VideoCall.btnFlip);
            _lblUserName        = FindViewById <TextView>(Resource.VideoCall.lblUserName);
            _lblStatus          = FindViewById <TextView>(Resource.VideoCall.lblDuration);
            _primaryVideo       = FindViewById <TwilioVideo.VideoView>(Resource.VideoCall.primaryVideo);
            _spinner            = FindViewById <View>(Resource.VideoCall.pgLoading);
            _thumbnailVideo     = FindViewById <TwilioVideo.VideoView>(Resource.VideoCall.thumbnailVideo);
            _root               = FindViewById <ViewGroup>(Resource.VideoCall.root);
            _thumbnailContainer = FindViewById <ViewGroup>(Resource.VideoCall.thumbnailContainer);

            _primaryVideo.Visibility   = ViewStates.Invisible;
            _thumbnailVideo.Visibility = ViewStates.Invisible;

            _btnFlip.Click    += OnFlipButtonClick;
            _btnEndCall.Click += OnCancelButtonClick;

            bool twoOrMoreCameras = Cameras.Count() > 1;

            _btnFlip.Enabled    = twoOrMoreCameras;
            _btnFlip.Visibility = twoOrMoreCameras ? ViewStates.Visible : ViewStates.Gone;

            VolumeControlStream = Stream.VoiceCall;

            bool granted = ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) == Permission.Granted &&
                           ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.RecordAudio) == Permission.Granted;

            CheckVideoCallPermissions(granted);

            TwilioVideo = TwilioVideoHelper.GetOrCreate(ApplicationContext);
            UpdateState();
            ConnectToRoom();
        }
Пример #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                // Create your application here
                SetContentView(Resource.Layout.TwilioVideoCallActivityLayout);
                Window.AddFlags(WindowManagerFlags.KeepScreenOn);

                Intent intentCloser = new Intent(this, typeof(NotificationManagerClass.NotificationBroadcasterCloser));
                intentCloser.PutExtra("action", "answer");
                intentCloser.PutExtra("type", Intent.GetStringExtra("type"));
                SendBroadcast(intentCloser);

                UserID = Intent.GetStringExtra("UserID");
                avatar = Intent.GetStringExtra("avatar");
                name   = Intent.GetStringExtra("name");

                var data_CALL_ID = Intent.GetStringExtra("CallID") ?? "Data not available";
                if (data_CALL_ID != "Data not available" && !String.IsNullOrEmpty(data_CALL_ID))
                {
                    CALL_ID = data_CALL_ID;

                    TWILIO_ACCESS_TOKEN       = Intent.GetStringExtra("access_token");
                    TWILIO_ACCESS_TOKEN_USER2 = Intent.GetStringExtra("access_token_2");
                    from_id   = Intent.GetStringExtra("from_id");
                    active    = Intent.GetStringExtra("active");
                    time      = Intent.GetStringExtra("time");
                    status    = Intent.GetStringExtra("status");
                    ROOM_NAME = Intent.GetStringExtra("room_name");
                    CALL_TYPE = Intent.GetStringExtra("type");
                }

                //Get values
                MainUserViewProfile    = FindViewById <RelativeLayout>(Resource.Id.userInfoview_container);
                _UserprimaryVideo      = FindViewById <VideoView>(Resource.Id.userthumbnailVideo);         // userthumbnailVideo
                _thumbnailVideo        = FindViewById <VideoView>(Resource.Id.local_video_view_container); //local_video_view_container
                Switch_cam_button      = FindViewById <Button>(Resource.Id.switch_cam_button);
                Mute_video_button      = FindViewById <CircleButton>(Resource.Id.mute_video_button);
                End_call_button        = FindViewById <CircleButton>(Resource.Id.end_call_button);
                Mute_audio_button      = FindViewById <CircleButton>(Resource.Id.mute_audio_button);
                UserInfoview_container = FindViewById <RelativeLayout>(Resource.Id.userInfoview_container);
                UserImageViewAsync     = FindViewById <ImageView>(Resource.Id.userImageViewAsync);
                UserNameTextView       = FindViewById <TextView>(Resource.Id.userNameTextView);
                NoteTextView           = FindViewById <TextView>(Resource.Id.noteTextView);

                //Event
                Switch_cam_button.Click += Switch_cam_button_Click;
                Mute_video_button.Click += Mute_video_button_Click;
                End_call_button.Click   += End_call_button_Click;
                Mute_audio_button.Click += Mute_audio_button_Click;

                VolumeControlStream = Stream.VoiceCall;

                bool granted =
                    ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) ==
                    Permission.Granted &&
                    ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.RecordAudio) ==
                    Permission.Granted;

                CheckVideoCallPermissions(granted);
                Mute_video_button.Selected = true;

                if (CALL_TYPE == "Twilio_video_call")
                {
                    if (!string.IsNullOrEmpty(TWILIO_ACCESS_TOKEN))
                    {
                        TwilioVideo = TwilioVideoHelper.GetOrCreate(ApplicationContext);
                        UpdateState();
                        NoteTextView.Text = this.GetText(Resource.String.Lbl_Waiting_for_answer);
                        var Check_for_ResponseDate = API_Request.Send_Twilio_Video_Call_Answer_Async("answer", CALL_ID);
                        ConnectToRoom();
                        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      = "Answered call",
                                status    = status,
                                room_name = ROOM_NAME,
                                type      = CALL_TYPE,
                                typeIcon  = "Accept",
                                typeColor = "#008000"
                            };

                            Last_Calls_Fragment.mAdapter?.Insert(cv);

                            SqLiteDatabase dbDatabase = new SqLiteDatabase();
                            dbDatabase.Insert_CallUser(cv);
                            dbDatabase.Dispose();
                        }
                    }
                }
                else if (CALL_TYPE == "Twilio_video_calling_start")
                {
                    if (!string.IsNullOrEmpty(UserID))
                    {
                        LoadProfileFromUserID(UserID);
                    }

                    NoteTextView.Text = this.GetText(Resource.String.Lbl_Calling_video);
                    TwilioVideo       = TwilioVideoHelper.GetOrCreate(ApplicationContext);

                    IMethods.AudioRecorderAndPlayer.PlayAudioFromAsset("mystic_call.mp3");

                    UpdateState();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }