Exemplo n.º 1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Media> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources.
            }

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    _stream       = e.NewElement.Stream;
                    _hangup       = e.NewElement.Hangup;
                    _label        = e.NewElement.Label;
                    _videoMuted   = e.NewElement.VideoMuted;
                    _audioMuted   = e.NewElement.AudioMuted;
                    _cameraType   = e.NewElement.CameraType;
                    _showControls = e.NewElement.ShowControls;

                    if (_stream is not null)
                    {
                        _videoTrack = _stream.GetVideoTracks().FirstOrDefault();
                        _audioTrack = _stream.GetAudioTracks().FirstOrDefault();
                    }

                    // Instantiate the native control and assign it to the Control property with
                    // the SetNativeControl method.
                    var context = global::Xamarin.Essentials.Platform.CurrentActivity.ApplicationContext;
                    _mediaView = new MediaView(context);
                    if (_videoTrack is not null)
                    {
                        _mediaView.SetTrack(_videoTrack);
                    }
                    SetNativeControl(_mediaView);
                }
                // Configure the control and subscribe to event handlers.
            }
        }
Exemplo n.º 2
0
        protected override void OnElementChanged(ElementChangedEventArgs <Media> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources.
            }

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    _stream     = e.NewElement.Stream;
                    _label      = e.NewElement.Label;
                    _videoMuted = e.NewElement.VideoMuted;
                    _audioMuted = e.NewElement.AudioMuted;

                    if (_stream is not null)
                    {
                        _videoTrack = _stream.GetVideoTracks().FirstOrDefault();
                        _audioTrack = _stream.GetAudioTracks().FirstOrDefault();
                    }

                    // Instantiate the native control and assign it to the Control property with
                    // the SetNativeControl method.
                    _mediaView = new MediaView();
                    if (_videoTrack is not null)
                    {
                        _mediaView.SetTrack(_videoTrack);
                    }
                    SetNativeControl(_mediaView);
                }
                // Configure the control and subscribe to event handlers.
            }
        }