public byte[] PlayFileWave() { int prevBuffer = bufferInUse; long pos = audioStream.Position; if (currentBufferWriter != null) { currentBufferWriter.Wait(); } int remain = Convert.ToInt32(audioStream.Length - audioStream.Position); Console.WriteLine(remain + "<" + bufferSize); if (remain < bufferSize) { state = PlaybackState.Stopped; if (remain != 0) { int newBufferSize = bufferSize + remain; byte[] tempB = new byte[newBufferSize]; Array.Copy(audioBuffers[bufferInUse], tempB, bufferSize); audioStream.Read(tempB, bufferSize, newBufferSize); bufferSize = newBufferSize; return(tempB); } else { return(audioBuffers[bufferInUse]); } } if (state == PlaybackState.Paused || state == PlaybackState.Stopped) { state = PlaybackState.Playing; audioStream.Read(audioBuffers[bufferInUse], 0, bufferSize); switchBuffer(); currentBufferWriter = audioStream.ReadAsync(audioBuffers[bufferInUse], 0, bufferSize); } else { switchBuffer(); currentBufferWriter = audioStream.ReadAsync(audioBuffers[bufferInUse], 0, bufferSize); } return(audioBuffers[prevBuffer]); //switchBuffer(); //int remain = Convert.ToInt32(audioStream.Length - audioStream.Position); //audioStream.Read(audioBuffers[bufferInUse], 0, remain); //return audioBuffers[bufferInUse]; }