Example #1
0
        public PlaybackService(IFileService fileService, ITrackRepository trackRepository, ITrackStatisticRepository trackStatisticRepository, IEqualizerService equalizerService, IQueuedTrackRepository queuedTrackRepository)
        {
            this.fileService              = fileService;
            this.trackRepository          = trackRepository;
            this.trackStatisticRepository = trackStatisticRepository;
            this.queuedTrackRepository    = queuedTrackRepository;
            this.equalizerService         = equalizerService;

            this.context = SynchronizationContext.Current;

            this.queueManager = new QueueManager();

            // Event handlers
            this.fileService.TracksImported += async(tracks) => await this.EnqueueAsync(tracks);

            // Set up timers
            this.progressTimer.Interval = TimeSpan.FromSeconds(this.progressTimeoutSeconds).TotalMilliseconds;
            this.progressTimer.Elapsed += new ElapsedEventHandler(this.ProgressTimeoutHandler);

            this.saveQueuedTracksTimer.Interval = TimeSpan.FromSeconds(this.saveQueuedTracksTimeoutSeconds).TotalMilliseconds;
            this.saveQueuedTracksTimer.Elapsed += new ElapsedEventHandler(this.SaveQueuedTracksTimeoutHandler);

            this.savePlaybackCountersTimer.Interval = TimeSpan.FromSeconds(this.savePlaybackCountersTimeoutSeconds).TotalMilliseconds;
            this.savePlaybackCountersTimer.Elapsed += new ElapsedEventHandler(this.SavePlaybackCountersHandler);

            this.Initialize();
        }
        public PlaybackService(IFileService fileService, II18nService i18nService, ITrackRepository trackRepository,
                               IEqualizerService equalizerService, IQueuedTrackRepository queuedTrackRepository, IContainerProvider container, IPlaylistService playlistService)
        {
            this.fileService           = fileService;
            this.i18nService           = i18nService;
            this.trackRepository       = trackRepository;
            this.queuedTrackRepository = queuedTrackRepository;
            this.equalizerService      = equalizerService;
            this.playlistService       = playlistService;
            this.container             = container;

            this.context = SynchronizationContext.Current;

            this.queueManager = new QueueManager(this.trackRepository);

            // Event handlers
            this.fileService.ImportingTracks += (_, __) => this.canGetSavedQueuedTracks = false;
            this.fileService.TracksImported  += (tracks, track) => this.EnqueueFromFilesAsync(tracks, track);
            this.i18nService.LanguageChanged += (_, __) => this.UpdateQueueLanguageAsync();

            // Set up timers
            this.progressTimer.Interval = TimeSpan.FromSeconds(this.progressTimeoutSeconds).TotalMilliseconds;
            this.progressTimer.Elapsed += new ElapsedEventHandler(this.ProgressTimeoutHandler);

            this.saveQueuedTracksTimer.Interval = TimeSpan.FromSeconds(this.saveQueuedTracksTimeoutSeconds).TotalMilliseconds;
            this.saveQueuedTracksTimer.Elapsed += new ElapsedEventHandler(this.SaveQueuedTracksTimeoutHandler);

            this.savePlaybackCountersTimer.Interval = TimeSpan.FromSeconds(this.savePlaybackCountersTimeoutSeconds).TotalMilliseconds;
            this.savePlaybackCountersTimer.Elapsed += new ElapsedEventHandler(this.SavePlaybackCountersHandler);

            this.Initialize();
        }
Example #3
0
        public PlaybackService(ITrackRepository trackRepository, IQueuedTrackRepository queuedTrackRepository, IEqualizerService equalizerService)
        {
            this.trackRepository       = trackRepository;
            this.queuedTrackRepository = queuedTrackRepository;
            this.equalizerService      = equalizerService;

            this.context = SynchronizationContext.Current;

            // Initialize the PlayerFactory
            this.playerFactory = new PlayerFactory();

            // Set up timers
            this.progressTimer.Interval = TimeSpan.FromSeconds(this.progressTimeoutSeconds).TotalMilliseconds;
            this.progressTimer.Elapsed += new ElapsedEventHandler(this.ProgressTimeoutHandler);

            this.saveQueuedTracksTimer.Interval = TimeSpan.FromSeconds(this.saveQueuedTracksTimeoutSeconds).TotalMilliseconds;
            this.saveQueuedTracksTimer.Elapsed += new ElapsedEventHandler(this.SaveQueuedTracksTimeoutHandler);

            this.saveTrackStatisticsTimer.Interval = TimeSpan.FromSeconds(this.saveTrackStatisticsTimeoutSeconds).TotalMilliseconds;
            this.saveTrackStatisticsTimer.Elapsed += new ElapsedEventHandler(this.SaveTrackStatisticsHandler);

            // Equalizer
            this.SetIsEqualizerEnabled(XmlSettingsClient.Instance.Get <bool>("Equalizer", "IsEnabled"));

            // Queued tracks
            this.GetSavedQueuedTracksAsync();
        }
        public TracksViewModelBase(IContainerProvider container) : base(container)
        {
            // Dependency injection
            this.container             = container;
            this.trackRepository       = container.Resolve <ITrackRepository>();
            this.dialogService         = container.Resolve <IDialogService>();
            this.searchService         = container.Resolve <ISearchService>();
            this.playbackService       = container.Resolve <IPlaybackService>();
            this.collectionService     = container.Resolve <ICollectionService>();
            this.i18nService           = container.Resolve <II18nService>();
            this.eventAggregator       = container.Resolve <IEventAggregator>();
            this.providerService       = container.Resolve <IProviderService>();
            this.playlistService       = container.Resolve <IPlaylistService>();
            this.metadataService       = container.Resolve <IMetadataService>();
            this.queuedTrackRepository = container.Resolve <IQueuedTrackRepository>();

            // Events
            this.metadataService.MetadataChanged += MetadataChangedHandlerAsync;

            // Commands
            this.ToggleTrackOrderCommand             = new DelegateCommand(() => this.ToggleTrackOrder());
            this.AddTracksToPlaylistCommand          = new DelegateCommand <string>(async(playlistName) => await this.AddTracksToPlaylistAsync(playlistName, this.SelectedTracks));
            this.PlaySelectedCommand                 = new DelegateCommand(async() => await this.PlaySelectedAsync());
            this.PlayNextCommand                     = new DelegateCommand(async() => await this.PlayNextAsync());
            this.AddTracksToNowPlayingCommand        = new DelegateCommand(async() => await this.AddTracksToNowPlayingAsync());
            this.RemoveSelectedTracksFromDiskCommand = new DelegateCommand(async() => await this.RemoveTracksFromDiskAsync(this.SelectedTracks), () => !this.IsIndexing);

            // Settings changed
            SettingsClient.SettingChanged += (_, e) =>
            {
                if (SettingsClient.IsSettingChanged(e, "Behaviour", "ShowRemoveFromDisk"))
                {
                    RaisePropertyChanged(nameof(this.ShowRemoveFromDisk));
                }
            };

            // Events
            this.i18nService.LanguageChanged += (_, __) =>
            {
                RaisePropertyChanged(nameof(this.TotalDurationInformation));
                RaisePropertyChanged(nameof(this.TotalSizeInformation));
                this.RefreshLanguage();
            };

            this.playbackService.PlaybackCountersChanged += PlaybackService_PlaybackCountersChanged;
        }
Example #5
0
        public PlaybackService(IFileService fileService, ITrackRepository trackRepository, ITrackStatisticRepository trackStatisticRepository, IEqualizerService equalizerService, IQueuedTrackRepository queuedTrackRepository)
        {
            this.fileService              = fileService;
            this.trackRepository          = trackRepository;
            this.trackStatisticRepository = trackStatisticRepository;
            this.queuedTrackRepository    = queuedTrackRepository;
            this.equalizerService         = equalizerService;

            // Initialize MMDevice
            using (var mmdeviceEnumerator = new MMDeviceEnumerator())
            {
                using (
                    var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                {
                    outputDevice = mmdeviceCollection[0];
                }
            }

            this.context = SynchronizationContext.Current;

            this.queueManager = new QueueManager();

            // Event handlers
            this.fileService.TracksImported += async(tracks) => await this.EnqueueAsync(tracks);

            // Set up timers
            this.progressTimer.Interval = TimeSpan.FromSeconds(this.progressTimeoutSeconds).TotalMilliseconds;
            this.progressTimer.Elapsed += new ElapsedEventHandler(this.ProgressTimeoutHandler);

            this.saveQueuedTracksTimer.Interval = TimeSpan.FromSeconds(this.saveQueuedTracksTimeoutSeconds).TotalMilliseconds;
            this.saveQueuedTracksTimer.Elapsed += new ElapsedEventHandler(this.SaveQueuedTracksTimeoutHandler);

            this.savePlaybackCountersTimer.Interval = TimeSpan.FromSeconds(this.savePlaybackCountersTimeoutSeconds).TotalMilliseconds;
            this.savePlaybackCountersTimer.Elapsed += new ElapsedEventHandler(this.SavePlaybackCountersHandler);

            this.Initialize();
        }