예제 #1
0
        public void OpenURI(string uri)
        {
            SelectedServiceResult = null;

            Streaming.ServiceResult result = ServiceResultResolver.DialogProcessURIBlocking(uri, ShellViewModel.Instance.playerWindow);
            LoggerManager.Info($"OpenURI: Parsed '{uri}' to {result}");

            if (result == null)
            {
                urlLoadLock = false;
                return;
            }

            Execute.OnUIThread(() =>
            {
                ResetPlayback();

                LoadMedia(result);
            });
        }
예제 #2
0
        public ShellViewModel()
        {
            InitHeadsets();

            ShellViewModel.Instance = this;
            ShellViewModel.OnInstantiated?.Invoke(this);

            var currentParser = Parser.CreateTrigger;

            Parser.CreateTrigger = (target, triggerText) => ShortcutParser.CanParse(triggerText)
                                                                                                                                ? ShortcutParser.CreateTrigger(triggerText)
                                                                                                                                : currentParser(target, triggerText);

            NotifyOfPropertyChange(() => PlayerTitle);

            CurrentPosition = "00:00:00";
            VideoLength     = "00:00:00";

            NotificationCenter = new NotificationCenterViewModel();

            _mediaDecoder      = new MediaDecoder();
            _mediaDecoder.Loop = Loop;


            _mediaDecoder.OnReady += (duration) =>
            {
                _ready = true;
                SendEvent("movieLoaded", Path.GetFileName(SelectedFileName));
                if (autoplay)
                {
                    autoplay    = false;
                    urlLoadLock = false;
                    Play();
                }
            };

            _mediaDecoder.OnEnded += () =>
            {
                SendEvent("movieEnded", Path.GetFileName(SelectedFileName));
                Task.Factory.StartNew(() => Execute.OnUIThread(() =>
                {
                    Stop();
                    ShowStartupUI();
                }));
            };

            _mediaDecoder.OnStop += () =>
            {
                Task.Factory.StartNew(() => waitForPlaybackStop.Set());
                SendEvent("movieStopped", Path.GetFileName(SelectedFileName));
            };

            _mediaDecoder.OnTimeUpdate += (time) =>
            {
                if (!_mediaDecoder.IsPlaying)
                {
                    return;
                }

                Execute.OnUIThreadAsync(() =>
                {
                    if (!lockSlider)
                    {
                        VRUIUpdatePlaybackTime(time);
                        CurrentPosition = (new TimeSpan(0, 0, (int)Math.Floor(time))).ToString();
                        _timeValue      = time;
                        NotifyOfPropertyChange(() => TimeValue);
                    }
                    UpdateTimeLabel();
                });
            };

            _mediaDecoder.OnError += (error) =>
            {
                urlLoadLock = false;
                Execute.OnUIThreadAsync(() =>
                {
                    NotificationCenter.PushNotification(MediaDecoderHelper.GetNotification(error));
                    SelectedServiceResult = null;
                    ShowStartupUI();
                });
                SendEvent("playbackError", error);
            };

            _mediaDecoder.OnBufferingStarted += () =>
            {
                Execute.OnUIThreadAsync(() =>
                {
                    shellView.BufferingStatus.Visibility = Visibility.Visible;
                });
            };

            _mediaDecoder.OnBufferingEnded += () =>
            {
                Execute.OnUIThreadAsync(() =>
                {
                    shellView.BufferingStatus.Visibility = Visibility.Collapsed;
                });
            };

            _mediaDecoder.OnProgress += (progress) =>
            {
                Execute.OnUIThreadAsync(() =>
                {
                    shellView.BufferingStatus.Text = $"Buffering... {progress}";
                });
            };


            UpdateTimeLabel();

            VolumeRocker                 = new VolumeControlViewModel();
            VolumeRocker.Volume          = 0.5;
            VolumeRocker.OnVolumeChange += (volume) =>
            {
                _mediaDecoder.SetVolume(volume);
                ShellViewModel.SendEvent("volumeChanged", volume);
            };


            Logic.Instance.OnUpdateAvailable += () => Execute.OnUIThreadAsync(() =>
            {
                NotificationCenter.PushNotification(
                    new NotificationViewModel(
                        "A new version of Bivrost® 360Player is available.",
                        () =>
                {
                    Updater.OnUpdateFail +=
                        () => Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Something went wrong :(")));
                    Updater.OnUpdateSuccess +=
                        () => Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Update completed successfully.", () =>
                    {
                        System.Windows.Forms.Application.Restart();
                        System.Windows.Application.Current.Shutdown();
                    }, "restart", 60f)));
                    Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Installing update...")));
                    Task.Factory.StartNew(() => Updater.InstallUpdate());
                },
                        "install now"
                        )
                    );
            });

            Logic.Instance.ValidateSettings();
        }