Esempio n. 1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            base.OnNavigatedTo(e);
            Camera camera = e.Parameter as Camera;

            this.CameraViewModel = new CameraViewModel(camera);

            this.GoBackCommand               = new ButtonCommand(new Action(GoBack));
            this.AddToFavouritesCommand      = new ButtonCommand(new Action(this.AddToFavourites));
            this.RemoveFromFavouritesCommand = new ButtonCommand(new Action(this.RemoveFromFavourites));

            if (this.CameraViewModel.CanExecuteAddToFavouritesCommand())
            {
                this.AddToFavouritesButton.Command = this.AddToFavouritesCommand;
            }
            else
            {
                this.AddToFavouritesButton.Command = this.RemoveFromFavouritesCommand;
                this.HeartIcon.Glyph = "\xEB52";
            }

            try
            {
                this.ffmpeg = await FFmpegInterop.FFmpegInteropMSS.CreateFromUriAsync(camera.RtspAddress);

                MediaStreamSource streamSource = ffmpeg.GetMediaStreamSource();

                this.MediaElement.SetMediaStreamSource(streamSource);
                this.MediaElement.Play();

                CameraViewModel.AddToRecent();
            }
            catch (System.Runtime.InteropServices.COMException exception)
            {
                ShowContentDialog(exception.Message);
                GoBack();
            }
        }