简体   繁体   English

使用NAudio将音频播放同步到计时器

[英]Synchronize playback of audio to a timer using NAudio

I want to synchronize the playback of a song to a timer so that I can keep the beats of a song in sync with things rendered on the screen. 我想将歌曲的播放与计时器同步,以便可以使歌曲的节拍与屏幕上呈现的内容保持同步。 Any way of accomplishing this using NAudio? 有什么用NAudio做到这一点的方法吗?

Several out the output devices in NAudio support the IWavePosition interface, which gives a more accurate indication of where the soundcard is currently up to in the buffer it is playing. NAudio中的几个输出设备都支持IWavePosition接口,该接口可以更准确地指示声卡当前在播放缓冲区中的位置。 Usually this is reported in terms of number of bytes that have been played since playback started - so it does not necessarily correspond to the position within the file you are playing or within a song. 通常以开始播放后已播放的字节数来报告-因此它不一定与您正在播放的文件中或歌曲中的位置相对应。 So if you use this you will need to keep track of when you started playing. 因此,如果使用此功能,则需要跟踪开始播放的时间。

Usually you would keep the things rendered on screen synchronized to the audio playback position, rather than the other way round. 通常,您将使呈现在屏幕上的内容与音频播放位置保持同步,而不是相反。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM