/// <summary> /// Initialize a local audio player with given type /// </summary> /// <param name="fileName">the file name to play</param> /// <param name="waveOutType">the wave out type to use</param> public LocalAudioPlayer(string fileName, WaveOutType waveOutType) { this.fileName = fileName; PlaybackStopType = PlaybackStopTypes.PlaybackStoppedReachingEndOfFile; Debug.Assert(this.wavePlayer == null); this.wavePlayer = CreateWavePlayer(waveOutType); wavePlayer.PlaybackStopped += wavePlayer_PlaybackStopped; try { if (fileName.ToLowerInvariant().EndsWith(".ogg")) { vorbisReader = new VorbisWaveReader(fileName); wavePlayer.Init(vorbisReader); } else if (fileName.ToLowerInvariant().EndsWith(".flac")) { flacReader = new FlacReader(fileName); wavePlayer.Init(flacReader); } else { this.file = new AudioFileReader(fileName); this.wavePlayer.Init(file); } //this.wavePlayer.PlaybackStopped += wavePlayer_PlaybackStopped; } catch (Exception) { //throw; } //Play(); }
private IWavePlayer CreateWavePlayer(WaveOutType woType) { switch (woType) { case WaveOutType.WaveOutEventType: return(new WaveOutEvent()); case WaveOutType.WaveOutWithCallback: return(new WaveOut(WaveCallbackInfo.FunctionCallback())); case WaveOutType.WaveOutSimpleType: default: return(new WaveOut()); } }