Beispiel #1
0
        public RadioViewModel(IRadioService radio, IAudioPlayer player)
        {
            Guard.AgainstNull(radio);
            Guard.AgainstNull(player);

            _radio  = radio;
            _player = player;

            // ===================== setting up all commands ============================

            PlaybackCommand  = new RelayCommand(SongPlaybackAction);
            ShowAlbumCommand = new RelayCommand(ViewAlbumContainingCurrentSong);

            PreviousSongCommand = new RelayCommand(async() =>
            {
                await _radio.MoveToPrevSongAsync();
                PlayCurrentSong();
                UpdateSongPanels();
            });

            NextSongCommand = new RelayCommand(async() =>
            {
                await _radio.MoveToNextSongAsync();
                PlayCurrentSong();
                UpdateSongPanels();
            });

            ChangeSongCommand = new RelayCommand(async() =>
            {
                await _radio.ChangeSongAsync(SelectedUpcomingSong.Id);
                UpdateSongPanels();
            });

            RemoveSongCommand = new RelayCommand(async() =>
            {
                await _radio.RemoveSongAsync(SelectedUpcomingSong.Id);
                UpdateSongPanels();
            });

            StopCommand = new RelayCommand(() =>
            {
                _player.Stop();
                PlaybackSymbol = SymbolPlay;
            });

            WindowClosingCommand = new RelayCommand(() =>
            {
                _isStopped = true;  // Stop radio when the window is closing
                _player.Close();    // to avoid a memory leak
            });

            // ===========================================================================

            if (_radio.UpcomingSongs.Any())
            {
                StartRadio();
            }
            else
            {
                _radio.MakeSonglistAsync().ContinueWith(task =>
                {
                    UpdateSongPanels();
                    StartRadio();
                });
            }
        }
Beispiel #2
0
        public RadioWindowViewModel(IRadioService radio, IAudioPlayer player, IDialogService dialogService)
        {
            Guard.AgainstNull(radio);
            Guard.AgainstNull(player);
            Guard.AgainstNull(dialogService);

            _radio         = radio;
            _player        = player;
            _dialogService = dialogService;

            // ===================== setting up all commands ============================

            PlaybackCommand  = new DelegateCommand(SongPlaybackAction);
            ShowAlbumCommand = new DelegateCommand(ViewAlbum);

            PreviousSongCommand = new DelegateCommand(async() =>
            {
                await _radio.MoveToPrevSongAsync();
                UpdateSongPanels();
                await PlayCurrentSong();
            });

            NextSongCommand = new DelegateCommand(async() =>
            {
                await _radio.MoveToNextSongAsync();
                UpdateSongPanels();
                await PlayCurrentSong();
            });

            ChangeSongCommand = new DelegateCommand(async() =>
            {
                await _radio.ChangeSongAsync(SelectedUpcomingSong.Id);
                UpdateSongPanels();
            });

            RemoveSongCommand = new DelegateCommand(async() =>
            {
                await _radio.RemoveSongAsync(SelectedUpcomingSong.Id);
                UpdateSongPanels();
            });

            StopCommand = new DelegateCommand(() =>
            {
                _player.Stop();
                PlaybackSymbol = MdlConstants.SymbolPlay;
            });

            // ===========================================================================

            if (_radio.UpcomingSongs.Any())
            {
                StartRadio();
            }
            else
            {
                _radio.MakeSonglistAsync().ContinueWith(task =>
                {
                    UpdateSongPanels();
                    StartRadio();
                });
            }
        }