问题描述
我在这里使用 NAudio 循环辅助类:
https://markheath.net/post/looped-playback-in-net-with-naudio
我试图让它循环 N 次而不是无限循环。我尝试修改 Read()
来自:
public override int Read(byte[] buffer,int offset,int count)
{
int totalBytesRead = 0;
while (totalBytesRead < count)
{
int bytesRead = sourceStream.Read(buffer,offset + totalBytesRead,count - totalBytesRead);
if (bytesRead == 0)
{
if (sourceStream.Position == 0 || !EnableLooping)
{
// something wrong with the source stream
break;
}
// loop
sourceStream.Position = 0;
}
totalBytesRead += bytesRead;
}
return totalBytesRead;
}
致:
public override int Read(byte[] buffer,int count)
{
int totalBytesRead = 0;
for (var i = 0; i < 3; i++)
{
int bytesRead = sourceStream.Read(buffer,count - totalBytesRead);
totalBytesRead += bytesRead;
}
return totalBytesRead;
}
但这似乎不会循环播放样本(仅播放一次)。
此代码无限循环:
public override int Read(byte[] buffer,int count)
{
int totalBytesRead = 0;
for (var i = 0; i < 3; i++)
{
var bytesRead = sourceStream.Read(buffer,count - totalBytesRead);
totalBytesRead += bytesRead;
sourceStream.Position = 0;
}
return totalBytesRead;
}
有谁知道我如何循环 n 次?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)