public void KickTrack() { CurrentTrack.Unload(); CurrentTrack = null; SoundSource = null; OnPropertyChanged("TrackLength"); OnPropertyChanged("CurrentTrackLength"); OnPropertyChanged("Position"); OnPropertyChanged("CurrentTrackPosition"); CurrentStateChanged(); }
public async Task <bool> OpenTrack(PlayableBase track) { if (!IsEnabled) { OnSoundOutErrorOccurred(Application.Current.Resources["NoSoundOutDeviceFound"].ToString()); return(false); } _playAfterLoading = false; IsLoading = true; StopPlayback(); if (CurrentTrack != null) { CurrentTrack.IsOpened = false; CurrentTrack.Unload(); } if (SoundSource != null && !_crossfade.IsCrossfading) { SoundSource.Dispose(); } track.IsOpened = true; CurrentTrack = track; var t = Task.Run(() => track.Load()); Equalizer equalizer; var result = await SetSoundSource(track); switch (result.State) { case State.False: track.IsOpened = false; return(false); case State.Exception: track.IsOpened = false; IsLoading = false; CurrentTrack = null; if (ExceptionOccurred != null) { ExceptionOccurred(this, (Exception)result.CustomState); } StopPlayback(); return(false); } if (Settings.SampleRate == -1 && SoundSource.WaveFormat.SampleRate < 44100) { SoundSource = SoundSource.ChangeSampleRate(44100); } else if (Settings.SampleRate > -1) { SoundSource = SoundSource.ChangeSampleRate(Settings.SampleRate); } SoundSource = SoundSource .AppendSource(x => Equalizer.Create10BandEqualizer(x.ToSampleSource()), out equalizer) .AppendSource(x => new SingleBlockNotificationStream(x), out _singleBlockNotificationStream) .AppendSource(x => new SimpleNotificationSource(x) { Interval = 100 }, out _simpleNotificationSource) .ToWaveSource(Settings.WaveSourceBits); MusicEqualizer = equalizer; SetAllEqualizerSettings(); _simpleNotificationSource.BlockRead += notifysource_BlockRead; _singleBlockNotificationStream.SingleBlockRead += notificationSource_SingleBlockRead; _analyser = new SampleAnalyser(FFTSize); _analyser.Initialize(SoundSource.WaveFormat); try { _soundOut.Initialize(SoundSource); } catch (Exception ex) { track.IsOpened = false; IsLoading = false; OnSoundOutErrorOccurred(ex.Message); return(false); } OnPropertyChanged("TrackLength"); OnPropertyChanged("CurrentTrackLength"); CurrentStateChanged(); _soundOut.Volume = Volume; if (StartVisualization != null) { StartVisualization(this, EventArgs.Empty); } track.LastTimePlayed = DateTime.Now; if (_crossfade.IsCrossfading) { _fader.CrossfadeIn(_soundOut, Volume); } IsLoading = false; if (_playAfterLoading) { TogglePlayPause(); } await t; return(true); }