Better handling of radiostation

This commit is contained in:
2015-11-01 19:51:43 +01:00
parent 90f35de242
commit 98f6ab9bc0
+16 -4
View File
@@ -17,7 +17,13 @@ namespace MusicPlayer
public AudioState AState { get; set; } public AudioState AState { get; set; }
public BufferState BState { get; set; } public BufferState BState { get; set; }
public int Buffered { get { return Math.Min((int)((bufpos / (double)LengthBuffer) * 1000), 1000); } } public int Buffered { get
{
if(CurrentSong is RadioStation)
return Math.Min((int)((bufpos - ms.Position) / 1000), 1000);
else
return Math.Min((int)((bufpos / (double)LengthBuffer) * 1000), 1000);
} }
private long LengthBuffer { get; set; } private long LengthBuffer { get; set; }
private long bufpos = 0; private long bufpos = 0;
@@ -33,7 +39,7 @@ namespace MusicPlayer
private long seek = 0; private long seek = 0;
private Stream ms; private MemoryStream ms;
private Thread network; private Thread network;
private Thread audio; private Thread audio;
@@ -167,12 +173,19 @@ namespace MusicPlayer
waveOut.Stop(); waveOut.Stop();
} }
if (BState == BufferState.DONE && firstrun ) if (BState == BufferState.DONE && firstrun )
{
if( ! (CurrentSong is RadioStation))
{ {
position = mp3fr.Position; position = mp3fr.Position;
mp3fr.Close(); mp3fr.Close();
StreamFromMP3(ms,position, false); StreamFromMP3(ms, position, false);
break; break;
} }
else
{
AState = AudioState.STOPPED;
}
}
playpos = blockAlignedStream.Position; playpos = blockAlignedStream.Position;
CurrentTime = (int)(playpos / waveOut.OutputWaveFormat.AverageBytesPerSecond); CurrentTime = (int)(playpos / waveOut.OutputWaveFormat.AverageBytesPerSecond);
@@ -242,7 +255,6 @@ namespace MusicPlayer
ms.Write(buffer, 0, read); ms.Write(buffer, 0, read);
ms.Position = pos; ms.Position = pos;
this.bufpos = ms.Length; this.bufpos = ms.Length;
} }
} }