public AudioPlayerManager(IAudioPlayer player, ISettingsService settingsService, IOutputDeviceProvider outputDeviceProvider) { _player = player; _settingsService = settingsService; _outputDeviceProvider = outputDeviceProvider; _currentAudioSource = AudioSourceBase.Null; _currentPlaylist = PlaylistModel.Null; }
public Result <bool> Play(PlaylistModel playlist, TrackModel track) { PlaybackState = PlaybackState.Loading; AudioSourceBase audioSource; bool isPlaying; try { audioSource = AudioSourceBase.GetAudioSource(track); isPlaying = _player.Play(audioSource.GetSoundSource()); } catch (Exception ex) { return(new ErrorResult <bool>(ex.Message)); } if (isPlaying) { PlaybackState = PlaybackState.Playing; if (_currentAudioSource != AudioSourceBase.Null) { _currentAudioSource.Model.IsPlaying = false; } _currentAudioSource = audioSource; _currentAudioSource.Model.IsPlaying = true; _currentPlaylist = playlist; _currentPlaylist.CurrentTrack = _currentAudioSource.Model; Messenger.Send(new CurrentTrackChangedMessage(track)); } return(new SuccessResult <bool>(isPlaying)); }