Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayQueueViewModel"/> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        /// <param name="playbackService">The playback service.</param>
        /// <param name="openSynoSettings"></param>
        public PlayQueueViewModel(IEventAggregator eventAggregator, IPlaybackService playbackService, INotificationService notificationService, IOpenSynoSettings openSynoSettings, ILogService logService, ITrackViewModelFactory trackViewModelFactory, IPageSwitchingService pageSwitchingService)
        {
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }

            if (playbackService == null)
            {
                throw new ArgumentNullException("playbackService");
            }

            if (notificationService == null)
            {
                throw new ArgumentNullException("notificationService");
            }

            if (openSynoSettings == null)
            {
                throw new ArgumentNullException("openSynoSettings");
            }

            if (trackViewModelFactory == null)
            {
                throw new ArgumentNullException("trackViewModelFactory");
            }

            if (pageSwitchingService == null)
            {
                throw new ArgumentNullException("pageSwitchingService");
            }

            _trackViewModelFactory = trackViewModelFactory;

            RemoveTracksFromQueueCommand = new DelegateCommand<IEnumerable<object>>(OnRemoveTracksFromQueue);

            Action consecutiveAlbumsIdPatcher = () =>
            {
                var previousAlbumGuid = Guid.Empty;
                string previousAlbumId = null;
                foreach (var trackViewModel in this.PlayQueueItems)
                {
                    if (previousAlbumId != trackViewModel.TrackInfo.ItemPid)
                    {
                        previousAlbumId = trackViewModel.TrackInfo.ItemPid;
                        previousAlbumGuid = Guid.NewGuid();
                    }
                    trackViewModel.ConsecutiveAlbumIdentifier = previousAlbumGuid;
                }
            };

            _playbackService = playbackService;
            this.PlayQueueItems = new ObservableCollection<TrackViewModel>(playbackService.GetTracksInQueue().Select(o => _trackViewModelFactory.Create(o.Guid, o.Track, this._pageSwitchingService)));
            this.PlayQueueItems.CollectionChanged += (s, ea) =>
                                                         {
                                                             consecutiveAlbumsIdPatcher();
                                                         };
            consecutiveAlbumsIdPatcher();
            _playbackService.PlayqueueChanged += this.OnPlayqueueChanged;

            // FIXME : using aggregated event is not a great idea here : we'd rather use a service : that would be cleaner and easier to debug !
            eventAggregator.GetEvent<CompositePresentationEvent<PlayListOperationAggregatedEvent>>().Subscribe(OnPlayListOperation, true);
            this._notificationService = notificationService;
            _openSynoSettings = openSynoSettings;
            _logService = logService;
            _pageSwitchingService = pageSwitchingService;
            _playbackService.TrackStarted += (o, e) =>
                                                 {
                                                     CurrentArtwork = new Uri(e.Track.AlbumArtUrl, UriKind.Absolute);
                                                     this.ActiveTrack = this._trackViewModelFactory.Create(e.Guid, e.Track, this._pageSwitchingService);
                                                 };

            _playbackService.BufferingProgressUpdated += (o, e) =>
                {
                    // throttle refresh through binding.
                    if (_lastBufferProgressUpdate.AddMilliseconds(500) < DateTime.Now || e.BytesLeft == 0)
                    {
                        _lastBufferProgressUpdate = DateTime.Now;
                        this.BufferedBytesCount = e.FileSize - e.BytesLeft;
                        this.CurrentFileSize = e.FileSize;
                        Debug.WriteLine("Download progress : " + (double)(e.FileSize - e.BytesLeft) / (double)e.FileSize * (double)100.0);
                    }
                };

            _playbackService.TrackCurrentPositionChanged += (o, e) =>
                {
                    CurrentPlaybackPercentComplete = e.PlaybackPercentComplete;;
                    CurrentTrackPosition = e.Position;
                };

            PlayCommand = new DelegateCommand<TrackViewModel>(o => OnPlay(o), track => track != null);
            PlayNextCommand = new DelegateCommand(OnPlayNext);
            PausePlaybackCommand = new DelegateCommand(OnPausePlayback);
            ResumePlaybackCommand = new DelegateCommand(OnResumePlayback);
            PlayPreviousCommand = new DelegateCommand(OnPlayPrevious);
            SavePlaylistCommand = new DelegateCommand<IEnumerable<TrackViewModel>>(OnSavePlaylist);
            SelectAllAlbumTracksCommand = new DelegateCommand<Guid>(OnSelectAllAlbumTracks);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayQueueViewModel"/> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        /// <param name="playbackService">The playback service.</param>
        /// <param name="openSynoSettings"></param>
        public PlayQueueViewModel(IEventAggregator eventAggregator, IPlaybackService playbackService, INotificationService notificationService, IOpenSynoSettings openSynoSettings, ILogService logService, ITrackViewModelFactory trackViewModelFactory, IPageSwitchingService pageSwitchingService)
        {
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }

            if (playbackService == null)
            {
                throw new ArgumentNullException("playbackService");
            }

            if (notificationService == null)
            {
                throw new ArgumentNullException("notificationService");
            }

            if (openSynoSettings == null)
            {
                throw new ArgumentNullException("openSynoSettings");
            }

            if (trackViewModelFactory == null)
            {
                throw new ArgumentNullException("trackViewModelFactory");
            }

            if (pageSwitchingService == null)
            {
                throw new ArgumentNullException("pageSwitchingService");
            }

            _trackViewModelFactory = trackViewModelFactory;

            RemoveTracksFromQueueCommand = new DelegateCommand <IEnumerable <object> >(OnRemoveTracksFromQueue);

            Action consecutiveAlbumsIdPatcher = () =>
            {
                var    previousAlbumGuid = Guid.Empty;
                string previousAlbumId   = null;
                foreach (var trackViewModel in this.PlayQueueItems)
                {
                    if (previousAlbumId != trackViewModel.TrackInfo.ItemPid)
                    {
                        previousAlbumId   = trackViewModel.TrackInfo.ItemPid;
                        previousAlbumGuid = Guid.NewGuid();
                    }
                    trackViewModel.ConsecutiveAlbumIdentifier = previousAlbumGuid;
                }
            };

            _playbackService    = playbackService;
            this.PlayQueueItems = new ObservableCollection <TrackViewModel>(playbackService.GetTracksInQueue().Select(o => _trackViewModelFactory.Create(o.Guid, o.Track, this._pageSwitchingService)));
            this.PlayQueueItems.CollectionChanged += (s, ea) =>
            {
                consecutiveAlbumsIdPatcher();
            };
            consecutiveAlbumsIdPatcher();
            _playbackService.PlayqueueChanged += this.OnPlayqueueChanged;

            // FIXME : using aggregated event is not a great idea here : we'd rather use a service : that would be cleaner and easier to debug !
            eventAggregator.GetEvent <CompositePresentationEvent <PlayListOperationAggregatedEvent> >().Subscribe(OnPlayListOperation, true);
            this._notificationService = notificationService;
            _openSynoSettings         = openSynoSettings;
            _logService                    = logService;
            _pageSwitchingService          = pageSwitchingService;
            _playbackService.TrackStarted += (o, e) =>
            {
                CurrentArtwork   = new Uri(e.Track.AlbumArtUrl, UriKind.Absolute);
                this.ActiveTrack = this._trackViewModelFactory.Create(e.Guid, e.Track, this._pageSwitchingService);
            };

            _playbackService.BufferingProgressUpdated += (o, e) =>
            {
                // throttle refresh through binding.
                if (_lastBufferProgressUpdate.AddMilliseconds(500) < DateTime.Now || e.BytesLeft == 0)
                {
                    _lastBufferProgressUpdate = DateTime.Now;
                    this.BufferedBytesCount   = e.FileSize - e.BytesLeft;
                    this.CurrentFileSize      = e.FileSize;
                    Debug.WriteLine("Download progress : " + (double)(e.FileSize - e.BytesLeft) / (double)e.FileSize * (double)100.0);
                }
            };

            _playbackService.TrackCurrentPositionChanged += (o, e) =>
            {
                CurrentPlaybackPercentComplete = e.PlaybackPercentComplete;;
                CurrentTrackPosition           = e.Position;
            };

            PlayCommand                 = new DelegateCommand <TrackViewModel>(o => OnPlay(o), track => track != null);
            PlayNextCommand             = new DelegateCommand(OnPlayNext);
            PausePlaybackCommand        = new DelegateCommand(OnPausePlayback);
            ResumePlaybackCommand       = new DelegateCommand(OnResumePlayback);
            PlayPreviousCommand         = new DelegateCommand(OnPlayPrevious);
            SavePlaylistCommand         = new DelegateCommand <IEnumerable <TrackViewModel> >(OnSavePlaylist);
            SelectAllAlbumTracksCommand = new DelegateCommand <Guid>(OnSelectAllAlbumTracks);
        }