我正在构建一个音频播放控制器,允许用户通过触摸和鼠标事件在音频文件中前后滑动。我应该如何使用响应式事件流来管理这些事件?
以下是我期望构建它的大致想法。
然后,使用Bacon.js创建事件流。
以下是我期望构建它的大致想法。
<div id="timeline">
<span id="scrubber"></span>
</div>
然后,使用Bacon.js创建事件流。
var mousedowns = $('#timeline').asEventStream('mousedown');
var touchstarts = $('#timeline').asEventStream('touchstart');
var starts = Bacon.mergeAll(mousedowns, touchstarts);
var mousemoves = $('#timeline').asEventStream('mousemove');
var touchmoves = $('#timeline').asEventStream('touchmove');
var moves = Bacon.mergeAll(mousemoves, touchmoves);
var mouseups = $('#timeline').asEventStream('mouseup');
var touchends = $('#timeline').asEventStream('touchend');
var ends = Bacon.mergeAll(mouseups, touchends);
starts.onValue(function () {
var repositionScrubber = moves.onValue(function (ev) {
$('#scrubber').moveTo(ev.offsetX);
});
ends.onValue(function () {
repositionScrubber.stop();
});
});
我确定这样做是完全错误的,但是我对使用可观察流处理事件还很陌生,并且我还不知道有什么好的指南可以参考。希望能得到帮助!
(我相信上面的内容有很多错误,但我对使用可观察流处理事件还很新,也不知道有没有好的指南可以参考。如果您能提供帮助,我将不胜感激!)
flatMap
)。 - OlliM