Ejemplo n.º 1
0
        protected override void Configure()
        {
            _container.Singleton <IDialogsPresenter, WindowDialogsPresenter>();
            _container.Singleton <IWindowManager, WindowManager>();

            _container.PerRequest <ViewModels.MainViewModel>();

            var currentParser = Parser.CreateTrigger;

            //http://www.siimviikman.com/2012/06/28/caliburn-adding-keyboard-shortcuts/
            //http://kent-boogaart.com/blog/multikeygesture
            Parser.CreateTrigger = (target, triggerText) => ShortcutParser.CanParse(triggerText)
                                                                ? ShortcutParser.CreateTrigger(triggerText)
                                                                : currentParser(target, triggerText);


            MessageBinder.SpecialValues.Add("$originalsourcecontext", context =>
            {
                var args = context.EventArgs as RoutedEventArgs;
                var fe   = args?.OriginalSource as FrameworkElement;

                return(fe?.DataContext);
            });

            base.Configure();
        }
Ejemplo n.º 2
0
 public Parser(string validOptionSetupString = null)
 {
     ValidOptions = new List <ValidOption>();
     if (string.IsNullOrWhiteSpace(validOptionSetupString))
     {
         return;
     }
     ValidOptions.AddRange(ShortcutParser.Parse(validOptionSetupString));
 }
Ejemplo n.º 3
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();
        }