我有一个代码来从URL流式传输mp3。我想在UI中显示MP3播放器的当前时间。我试过用WaveOut.GetPosition
,但它不适用于我。 我该怎么做?如何使用NAudio流式传输mp3时获得当前时间?
我的代码:
do
{
//..codes to get url stream,to create BufferedWaveProvider
int decompressed = decompressor.DecompressFrame(frame, buffer, 0);
provider.AddSamples(buffer, 0, decompressed);
if (provider.BufferedDuration.Seconds > 2 && waveOut == null)
{
waveOut = new WaveOut();
waveOut.Init(provider);
waveOut.Play();
}
if (waveOut != null)
{
currentTime = (int)(waveOut.GetPosition() * 1d/AvgBytesPerSec);
}
}
while (bytesRead > 0 || waveOut.PlaybackState == PlaybackState.Playing);
什么类型是'提供者'? –
'provider'是BufferedWaveProvider,'waveOut'是WaveOut。如果你需要,我可以把整个代码。 –
它不起作用?它是否在播放音频? – ioctlLR