Ejemplo n.º 1
0
        public PlayerMorePopupViewBindingModel(
            IMediaElementContainer mediaElementContainer,
            IPlayQueueService playQueueService,
            IEventAggregator eventAggregator,
            IApplicationStateService stateService,
            IApplicationResources applicationResources,
            IDispatcher dispatcher)
        {
            this.mediaElementContainer = mediaElementContainer;
            this.playQueueService      = playQueueService;
            this.eventAggregator       = eventAggregator;
            this.stateService          = stateService;
            this.applicationResources  = applicationResources;
            this.dispatcher            = dispatcher;

            this.RegisterForDispose(this.eventAggregator.GetEvent <QueueChangeEvent>().Subscribe(
                                        async(e) => await this.dispatcher.RunAsync(() =>
            {
                this.RaisePropertyChanged(() => this.IsShuffleEnabled);
                this.RaisePropertyChanged(() => this.IsRepeatAllEnabled);
            })));

            this.RegisterForDispose(this.eventAggregator.GetEvent <ApplicationStateChangeEvent>().Subscribe(
                                        async(e) => await this.dispatcher.RunAsync(() => this.RaisePropertyChanged(() => this.IsOnlineMode))));
        }
Ejemplo n.º 2
0
 public PlayerViewPresenter(
     IMediaElementContainer mediaElementContainer,
     IGoogleMusicSessionService sessionService,
     IPlayQueueService queueService,
     INavigationService navigationService,
     PlayerBindingModel playerBindingModel)
     : base(mediaElementContainer, sessionService, queueService, navigationService, playerBindingModel)
 {
     this.ShowMoreCommand = new DelegateCommand(() => this.MainFrame.ShowPopup <IPlayerMorePopupView>(PopupRegion.AppToolBarRight));
 }
Ejemplo n.º 3
0
        public SnappedPlayerBindingModel(
            SongsBindingModel songsBindingModel,
            IMediaElementContainer mediaElementContainer,
            IPlayQueueService playQueueService,
            IEventAggregator eventAggregator,
            IDispatcher dispatcher)
        {
            this.mediaElementContainer = mediaElementContainer;
            this.playQueueService      = playQueueService;
            this.eventAggregator       = eventAggregator;
            this.dispatcher            = dispatcher;
            this.SongsBindingModel     = songsBindingModel;

            this.eventAggregator.GetEvent <QueueChangeEvent>().Subscribe(
                async(e) => await this.dispatcher.RunAsync(() =>
            {
                this.RaisePropertyChanged(() => this.IsShuffleEnabled);
                this.RaisePropertyChanged(() => this.IsRepeatAllEnabled);
            }));
        }
Ejemplo n.º 4
0
        public PlayQueueService(
            ILogManager logManager,
            IMediaElementContainer mediaElement,
            ISettingsService settingsService,
            ISongsCachingService songsCachingService,
            ICurrentSongPublisherService publisherService,
            IGoogleMusicSessionService sessionService,
            IPlaylistsService playlistsService,
            IRadioWebService radioWebService,
            IEventAggregator eventAggregator)
        {
            this.logger              = logManager.CreateLogger("PlayQueueService");
            this.mediaElement        = mediaElement;
            this.settingsService     = settingsService;
            this.songsCachingService = songsCachingService;
            this.publisherService    = publisherService;
            this.playlistsService    = playlistsService;
            this.radioWebService     = radioWebService;
            this.eventAggregator     = eventAggregator;
            this.currentQueueIndex   = -1;

            this.IsRepeatAll = this.settingsService.GetValue("IsRepeatAllEnabled", defaultValue: false);
            this.IsShuffled  = this.settingsService.GetValue("IsShuffleEnabled", defaultValue: false);

            this.State = QueueState.Unknown;

            this.mediaElement.MediaEnded += async(sender, args) =>
            {
                if (this.CanSwitchToNext())
                {
                    await this.NextSongAsync();
                }
                else
                {
                    this.State = QueueState.Stopped;
                }
            };

            sessionService.SessionCleared += async(sender, args) => { await ClearQueueAsync(); };
            eventAggregator.GetEvent <ReloadSongsEvent>().Subscribe(async(e) => { await ClearQueueAsync(); });
        }
        public SnappedPlayerViewPresenter(
            IMediaElementContainer mediaElementContainer,
            IGoogleMusicSessionService sessionService,
            IPlayQueueService queueService,
            INavigationService navigationService,
            SnappedPlayerBindingModel snappedPlayerBindingModel)
            : base(mediaElementContainer, sessionService, queueService, navigationService, snappedPlayerBindingModel)
        {
            this.queueService = queueService;
            this.isRadio      = this.queueService.IsRadio;

            this.RepeatAllCommand =
                new DelegateCommand(
                    () => { },
                    () => this.queueService.State != QueueState.Busy && !this.isRadio);

            this.ShuffleCommand =
                new DelegateCommand(
                    () => { },
                    () => this.queueService.State != QueueState.Busy && !this.isRadio);

            this.AddToQueueCommand = new DelegateCommand(
                () =>
            {
                if (ApplicationView.TryUnsnap())
                {
                    navigationService.NavigateTo <IStartPageView>();
                }
            });

            this.queueService.StateChanged += async(sender, args) => await this.Dispatcher.RunAsync(async() =>
            {
                this.UpdateCommands();

                await this.View.ScrollIntoCurrentSongAsync();
            });
        }
Ejemplo n.º 6
0
        protected PlayerViewPresenterBase(
            IMediaElementContainer mediaElementContainer,
            IGoogleMusicSessionService sessionService,
            IPlayQueueService queueService,
            INavigationService navigationService,
            TPlayerBindingModel playerBindingModel)
        {
            this.mediaElement      = mediaElementContainer;
            this.sessionService    = sessionService;
            this.queueService      = queueService;
            this.navigationService = navigationService;

            this.BindingModel = playerBindingModel;

            this.SkipBackCommand  = new DelegateCommand(this.PreviousSong, () => !this.BindingModel.IsBusy && this.queueService.CanSwitchToPrevious());
            this.PlayCommand      = new DelegateCommand(async() => await this.PlayAsync(), () => !this.BindingModel.IsBusy && (this.BindingModel.State == QueueState.Stopped || this.BindingModel.State == QueueState.Paused));
            this.PauseCommand     = new DelegateCommand(async() => await this.PauseAsync(), () => !this.BindingModel.IsBusy && this.BindingModel.IsPlaying);
            this.SkipAheadCommand = new DelegateCommand(this.NextSong, () => !this.BindingModel.IsBusy && this.queueService.CanSwitchToNext());

            this.BindingModel.Subscribe(
                () => this.BindingModel.CurrentPosition,
                async(sender, args) =>
            {
                if (this.BindingModel.IsPlaying)
                {
                    double currentPosition = this.BindingModel.CurrentPosition;
                    if (Math.Abs(this.progressPosition - currentPosition) > 1)
                    {
                        await this.mediaElement.SetPositionAsync(TimeSpan.FromSeconds(currentPosition));
                    }
                }
            });

            this.mediaElement.PlayProgress += (sender, args) =>
            {
                if (this.BindingModel.IsPlaying)
                {
                    try
                    {
                        this.BindingModel.FreezeNotifications();
                        this.BindingModel.TotalSeconds    = args.Duration.TotalSeconds;
                        this.BindingModel.CurrentPosition = this.progressPosition = args.Position.TotalSeconds;
                    }
                    finally
                    {
                        this.BindingModel.UnfreezeNotifications();
                    }
                }
            };

            this.sessionService.SessionCleared += (sender, args) => this.Dispatcher.RunAsync(
                async() =>
            {
                // TODO: clear playlists
                await this.StopAsync();
            });

            this.queueService.DownloadProgress += this.CurrentSongStreamOnDownloadProgressChanged;
            this.queueService.QueueChanged     += (sender, args) => this.UpdateCommands();
            this.queueService.StateChanged     += async(sender, args) => await this.Dispatcher.RunAsync(
                () =>
            {
                if (args.State == QueueState.Busy || args.State == QueueState.Stopped)
                {
                    this.BindingModel.CurrentPosition = 0d;
                    this.BindingModel.TotalSeconds    = 1.0d;
                }

                this.BindingModel.CurrentSong = args.CurrentSong == null ? null : new SongBindingModel(args.CurrentSong);
                this.BindingModel.State       = args.State;
                this.UpdateCommands();
            });

            this.NavigateToQueueView = new DelegateCommand(() => this.navigationService.NavigateTo <ICurrentPlaylistPageView>(parameter: true));
        }