【发布时间】:2015-02-18 18:01:50
【问题描述】:
我正在播放 PCM RAW 格式的音乐,前 5 秒播放正确,但之后播放速度提高了一倍
这是我所做的: 我有一个带有事件处理程序的播放器类,当程序从某个位置接收到一个字节时,它会添加到一个队列中,并从这个队列中添加一个线程到缓冲区。
我得到的音乐来自 spotify,使用 libspotifydotnet,CSCore.Codecs.RAW.RawDataReader 播放正确,但我不能在播放时继续向流中添加更多数据,或者我可以吗???!!
这是我到目前为止所做的事情
//Main.cs
WasapiOut soundOut = new WasapiOut();
soundOut.Initialize(Player.source);
soundOut.Play();
...
//Player.cs
public static WriteableBufferingSource source;
private static Queue<byte[]> _q = new Queue<byte[]>();
source = new WriteableBufferingSource(new CSCore.WaveFormat(Session.format.sample_rate, 16, Session.format.channels, CSCore.AudioEncoding.Pcm));
source.FillWithZeros = false;
byte[] buffer = null;
while (!_interrupt && !_complete)
{
if (_q.Count > 0)
{
buffer = _q.Dequeue();
source.Write(buffer, 0, buffer.Length);
System.Console.WriteLine("Buffer written {0} bytes", buffer.Length);
Thread.Sleep(10);
}
}
//New data downloaded event
private static void Session_OnAudioDataArrived(byte[] buffer)
{
if (!_interrupt && !_complete)
{
_q.Enqueue(buffer);
}
}
【问题讨论】:
标签: c# libspotify cscore