Example #1
0
        public PlaylistSidePaneContentViewModel(
            MediaPlayer mediaPlayer,
            HohoemaPlaylist playerModel,
            PlaylistSettings playlistSettings,
            PageManager pageManager
            )
        {
            MediaPlayer      = mediaPlayer;
            HohoemaPlaylist  = playerModel;
            PlaylistSettings = playlistSettings;
            PageManager      = pageManager;

            CurrentPlaylist     = playerModel.CurrentPlaylist;
            CurrentPlayingItem  = playerModel.Player.Current;
            CurrentPlaylistName = new ReactiveProperty <string>(CurrentWindowContextScheduler, HohoemaPlaylist.CurrentPlaylist?.Label)
                                  .AddTo(_CompositeDisposable);
            IsShuffleEnabled = PlaylistSettings.ToReactivePropertyAsSynchronized(x => x.IsShuffleEnable, CurrentWindowContextScheduler)
                               .AddTo(_CompositeDisposable);

            IsTrackRepeatModeEnable = PlaylistSettings.ObserveProperty(x => x.RepeatMode)
                                      .Select(x => x == MediaPlaybackAutoRepeatMode.Track)
                                      .ToReactiveProperty(CurrentWindowContextScheduler)
                                      .AddTo(_CompositeDisposable);
            IsListRepeatModeEnable = PlaylistSettings.ObserveProperty(x => x.RepeatMode)
                                     .Select(x => x == MediaPlaybackAutoRepeatMode.List)
                                     .ToReactiveProperty(CurrentWindowContextScheduler)
                                     .AddTo(_CompositeDisposable);

            IsTrackRepeatModeEnable.Subscribe(x =>
            {
                MediaPlayer.IsLoopingEnabled = x;
            })
            .AddTo(_CompositeDisposable);


            IsReverseEnabled = PlaylistSettings.ToReactivePropertyAsSynchronized(x => x.IsReverseModeEnable, CurrentWindowContextScheduler)
                               .AddTo(_CompositeDisposable);

            PlaylistCanGoBack = HohoemaPlaylist.Player.ObserveProperty(x => x.CanGoBack)
                                .ToReactiveProperty(CurrentWindowContextScheduler)
                                .AddTo(_CompositeDisposable);
            PlaylistCanGoNext = HohoemaPlaylist.Player.ObserveProperty(x => x.CanGoNext)
                                .ToReactiveProperty(CurrentWindowContextScheduler)
                                .AddTo(_CompositeDisposable);

            PlaylistItems = CurrentPlaylist.Select(x =>
            {
                var video = Database.NicoVideoDb.Get(x);
                return(new PlaylistItem()
                {
                    ContentId = x,
                    Title = video.Title,
                    Owner = CurrentPlaylist,
                    Type = PlaylistItemType.Video
                });
            }).ToObservable()
                            .ToReadOnlyReactiveCollection(scheduler: CurrentWindowContextScheduler)
                            .AddTo(_CompositeDisposable);
            RaisePropertyChanged(nameof(PlaylistItems));
        }
        public PlaylistSidePaneContentViewModel(MediaPlayer mediaPlayer, HohoemaPlaylist playerModel, PlaylistSettings playlistSettings, PageManager pageManager)
        {
            _MediaPlayer      = mediaPlayer;
            _Player           = playerModel;
            _PlaylistSettings = playlistSettings;
            _PageManager      = pageManager;

            CurrentPlaylist     = playerModel.CurrentPlaylist;
            CurrentPlayingItem  = playerModel.Player.Current;
            CurrentPlaylistName = new ReactiveProperty <string>(CurrentWindowContextScheduler, _Player.CurrentPlaylist?.Label)
                                  .AddTo(_CompositeDisposable);
            IsShuffleEnabled = _PlaylistSettings.ToReactivePropertyAsSynchronized(x => x.IsShuffleEnable, CurrentWindowContextScheduler)
                               .AddTo(_CompositeDisposable);

            IsTrackRepeatModeEnable = _PlaylistSettings.ObserveProperty(x => x.RepeatMode)
                                      .Select(x => x == MediaPlaybackAutoRepeatMode.Track)
                                      .ToReactiveProperty(CurrentWindowContextScheduler)
                                      .AddTo(_CompositeDisposable);
            IsListRepeatModeEnable = _PlaylistSettings.ObserveProperty(x => x.RepeatMode)
                                     .Select(x => x == MediaPlaybackAutoRepeatMode.List)
                                     .ToReactiveProperty(CurrentWindowContextScheduler)
                                     .AddTo(_CompositeDisposable);

            IsTrackRepeatModeEnable.Subscribe(x =>
            {
                _MediaPlayer.IsLoopingEnabled = x;
            })
            .AddTo(_CompositeDisposable);


            IsReverseEnabled = _PlaylistSettings.ToReactivePropertyAsSynchronized(x => x.IsReverseModeEnable, CurrentWindowContextScheduler)
                               .AddTo(_CompositeDisposable);

            PlaylistCanGoBack = _Player.Player.ObserveProperty(x => x.CanGoBack)
                                .ToReactiveProperty(CurrentWindowContextScheduler)
                                .AddTo(_CompositeDisposable);
            PlaylistCanGoNext = _Player.Player.ObserveProperty(x => x.CanGoNext)
                                .ToReactiveProperty(CurrentWindowContextScheduler)
                                .AddTo(_CompositeDisposable);

            PlaylistItems = CurrentPlaylist.PlaylistItems
                            .ToReadOnlyReactiveCollection(CurrentWindowContextScheduler)
                            .AddTo(_CompositeDisposable);
            RaisePropertyChanged(nameof(PlaylistItems));
        }