public override async Task <ISoundPlayerBuilder <IStorageFileEx> > BuildAsync() { if (Input == null) { return(this); } DisposeInternally(); IRandomAccessStreamEx streamOpenFile = await Input.OpenReadAsync(); using (Stream nativeStream = streamOpenFile.AsStreamForRead()) { using (var soundStream = new SoundStream(nativeStream)) { Description = Input.Name; WaveFormat = soundStream.Format; _dataStream = soundStream.ToDataStream(); SourceVoice = VoicePool.GetVoice(WaveFormat); SourceVoice.PlayWith(_dataStream); } } return(this); }
private void DisposeInternally() { Stop(); if (SourceVoice != null) { SourceVoice.Clear(); VoicePool.PutVoice(SourceVoice, WaveFormat); SourceVoice = null; } if (_dataStream != null) { _dataStream.Dispose(); _dataStream = null; } }
private void DisposeInternally() { Stop(); if (SourceVoice != null) { SourceVoice.Clear(); VoicePool.PutVoice(SourceVoice, WaveFormat); } if (_overLapDataStream != null) { _overLapDataStream.Dispose(); } if (_overlapSourceVoice != null) { _overlapSourceVoice.Clear(); VoicePool.PutVoice(_overlapSourceVoice, WaveFormat); } }
public override Task <ISoundPlayerBuilder <IStorageFileEx> > BuildAsync() { DisposeInternally(); _dataStream = new DataStream(_currentSampleBuffer.Length, true, true); _overLapDataStream = new DataStream(_currentSampleBuffer.Length, true, true); _dataStream.Read(_currentSampleBuffer, 0, _currentSampleBuffer.Length); _dataStream.Seek(0, 0); _overLapDataStream.Read(_currentSampleBuffer, 0, _currentSampleBuffer.Length); _overLapDataStream.Seek(0, 0); SourceVoice = VoicePool.GetVoice(WaveFormat); _overlapSourceVoice = VoicePool.GetVoice(WaveFormat); SourceVoice.PlayWith(_dataStream); _overlapSourceVoice.PlayWith(_overLapDataStream); return(Task.FromResult <ISoundPlayerBuilder <IStorageFileEx> >(this)); }