Attempt fix seeking (Again)

This commit is contained in:
2015-10-30 17:37:53 +01:00
parent 41dd995175
commit 9a01b9e870
2 changed files with 11 additions and 8 deletions
+10 -7
View File
@@ -106,14 +106,14 @@ namespace MusicPlayer
private void PlayAudio() private void PlayAudio()
{ {
AState = AudioState.WAITING; AState = AudioState.WAITING;
while (ms.Length < 65536 * 10 && BState != BufferState.DONE) while (ms.Length < 65536 * 4 * 10 && BState != BufferState.DONE)
Thread.Sleep(1000); Thread.Sleep(75);
AState = AudioState.PLAYING; AState = AudioState.PLAYING;
long position = 0; long position = 0;
ms.Position = position;
Mp3FileReader mp3fr = new Mp3FileReader(ms); Mp3FileReader mp3fr = new Mp3FileReader(ms);
using (WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(mp3fr))) using (WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(mp3fr)))
{ {
@@ -141,15 +141,17 @@ namespace MusicPlayer
} }
if (AState == AudioState.SEEKING) if (AState == AudioState.SEEKING)
{ {
blockAlignedStream.Position = seek - (seek % blockAlignedStream.WaveFormat.BlockAlign); blockAlignedStream.Seek(seek - (seek % blockAlignedStream.WaveFormat.BlockAlign), SeekOrigin.Begin);
AState = AudioState.PLAYING; AState = AudioState.PLAYING;
waveOut.Play(); //waveOut.Play();
} }
if (AState == AudioState.STOPPED) if (AState == AudioState.STOPPED)
{ {
waveOut.Stop(); waveOut.Stop();
} }
Console.WriteLine(waveOut.PlaybackState + " | " + blockAlignedStream.Position + " | " + ms.Position);
playpos = blockAlignedStream.Position; playpos = blockAlignedStream.Position;
CurrentTime = (int)(playpos / waveOut.OutputWaveFormat.AverageBytesPerSecond); CurrentTime = (int)(playpos / waveOut.OutputWaveFormat.AverageBytesPerSecond);
@@ -183,7 +185,8 @@ namespace MusicPlayer
LengthBuffer = response.ContentLength; LengthBuffer = response.ContentLength;
using (var stream = response.GetResponseStream()) using (var stream = response.GetResponseStream())
{ {
byte[] buffer = new byte[65536]; // 64KB chunks //byte[] buffer = new byte[65536]; // 64KB chunks
byte[] buffer = new byte[65536*4]; // 256KB chunks
int read; int read;
BState = BufferState.BUFFERING; BState = BufferState.BUFFERING;
AState = AudioState.WAITING; AState = AudioState.WAITING;
@@ -196,7 +199,7 @@ namespace MusicPlayer
ms.Position = pos; ms.Position = pos;
this.bufpos += buffer.Length; this.bufpos = ms.Length;
} }
} }
+1 -1
View File
@@ -280,7 +280,7 @@
// //
// UpdateTimer // UpdateTimer
// //
this.UpdateTimer.Interval = 600; this.UpdateTimer.Interval = 150;
this.UpdateTimer.Tick += new System.EventHandler(this.UpdateTimer_Tick); this.UpdateTimer.Tick += new System.EventHandler(this.UpdateTimer_Tick);
// //
// notifyIcon1 // notifyIcon1