Reload mp3 stream when done buffering
This commit is contained in:
@@ -103,20 +103,15 @@ namespace MusicPlayer
|
|||||||
AState = AudioState.PAUSED;
|
AState = AudioState.PAUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlayAudio()
|
private void StreamFromMP3(Stream s, long pos, bool firstrun)
|
||||||
{
|
{
|
||||||
AState = AudioState.WAITING;
|
|
||||||
while (ms.Length < 65536 * 10 && BState != BufferState.DONE)
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
AState = AudioState.PLAYING;
|
|
||||||
|
|
||||||
long position = 0;
|
long position = 0;
|
||||||
|
|
||||||
ms.Position = position;
|
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)))
|
||||||
{
|
{
|
||||||
|
blockAlignedStream.Position = pos;
|
||||||
using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
|
using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
|
||||||
{
|
{
|
||||||
waveOut.Init(blockAlignedStream);
|
waveOut.Init(blockAlignedStream);
|
||||||
@@ -149,6 +144,13 @@ namespace MusicPlayer
|
|||||||
{
|
{
|
||||||
waveOut.Stop();
|
waveOut.Stop();
|
||||||
}
|
}
|
||||||
|
if (BState == BufferState.DONE && firstrun )
|
||||||
|
{
|
||||||
|
position = mp3fr.Position;
|
||||||
|
mp3fr.Close();
|
||||||
|
StreamFromMP3(ms,position, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
playpos = blockAlignedStream.Position;
|
playpos = blockAlignedStream.Position;
|
||||||
CurrentTime = (int)(playpos / waveOut.OutputWaveFormat.AverageBytesPerSecond);
|
CurrentTime = (int)(playpos / waveOut.OutputWaveFormat.AverageBytesPerSecond);
|
||||||
@@ -162,6 +164,17 @@ namespace MusicPlayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PlayAudio()
|
||||||
|
{
|
||||||
|
AState = AudioState.WAITING;
|
||||||
|
while (ms.Length < 65536 * 10 && BState != BufferState.DONE)
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
AState = AudioState.PLAYING;
|
||||||
|
|
||||||
|
StreamFromMP3(ms,0, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadAudio(object o)
|
private void LoadAudio(object o)
|
||||||
{
|
{
|
||||||
Song s = (Song) o;
|
Song s = (Song) o;
|
||||||
|
|||||||
Reference in New Issue
Block a user