private void DirectSoundOutput_PlaybackStopped(object sender, StoppedEventArgs sea) { StoppedPlayerEventArgs stoppedPlayerEventArgs = null; string nextSongTyp = ""; if (_stopCause == StopCause.EofReached) { _audioPlayerState = AudioPlayerState.Stopped; if (_nextSongType == NextSongType.NextSong) { nextSongTyp = "NEXT"; } else if (_nextSongType == NextSongType.PrevSong) { nextSongTyp = "PREV"; } else { nextSongTyp = "NONE"; } _nextSongType = NextSongType.NextSong; stoppedPlayerEventArgs = new StoppedPlayerEventArgs("EOF", nextSongTyp); } else if (_stopCause == StopCause.UserTriggered) { _audioPlayerState = AudioPlayerState.Stopped; stoppedPlayerEventArgs = new StoppedPlayerEventArgs("USR", "NONE"); } //else stoppedPlayerEventArgs = new StoppedPlayerEventArgs("UNK"); StoppedPlayerNotification(new object(), stoppedPlayerEventArgs); }
public AudioPlayer ( StartedPlayingEventHandler startedPlayingNotification, PausedPlayerEventHandler pausedPlayerNotification, StoppedPlayerEventHandler stoppedPlayerNotification ) { _stopCause = StopCause.EofReached; _audioPlayerState = AudioPlayerState.Stopped; _nextSongType = NextSongType.NextSong; StartedPlayingNotification += startedPlayingNotification; PausedPlayerNotification += pausedPlayerNotification; StoppedPlayerNotification += stoppedPlayerNotification; }
//starting playing the ...player public void PlaySong(AudioFile audioFile) { _timer = new Timer(100); _timer.Enabled = true; _timer.Start(); _currentFile = audioFile; if (_audioPlayerState == AudioPlayerState.Stopped) { _stopCause = StopCause.EofReached; _nextSongType = NextSongType.NextSong; _audioPlayerState = AudioPlayerState.Playing; switch (audioFile.Format.ToLower()) { case ".mp3": _waveStream = new Mp3FileReader(audioFile.Path); break; case ".wav": _waveStream = new WaveFileReader(audioFile.Path); break; case ".aiff": _waveStream = new AiffFileReader(audioFile.Path); break; default: _waveStream = new AudioFileReader(audioFile.Path); break; } _directSoundOut = new DirectSoundOut(150); _waveChannel32 = new WaveChannel32(_waveStream, 5, 0) { PadWithZeroes = false }; _directSoundOut.Init(_waveChannel32); _directSoundOut.Play(); _directSoundOut.PlaybackStopped += DirectSoundOutput_PlaybackStopped; } else if (_audioPlayerState == AudioPlayerState.Paused) { _audioPlayerState = AudioPlayerState.Playing; _directSoundOut.Play(); } StartedPlayingNotification(new object(), new StartedPlayerEventArgs()); }
//play PREV song public void PlayPreviousSong() { _nextSongType = NextSongType.PrevSong; _waveStream.CurrentTime = TimeSpan.FromSeconds(_waveStream.TotalTime.TotalSeconds - 0.1); }