嘿,我被困在这个小小的Spotify应用程序上,我正在整理它来帮助练习新歌。它只是抓住开始时间和结束时间,然后一旦激活,继续循环它 - 适合学习轨道中的困难部分。
问题:我可以从控制台日志中看到,RealtimeAnalyzer正在放置我的消息的5到11个控制台日志以及我正在调用的.seek函数 - 所以当当前位置大于结束点时,它正在寻求回到In Point,但却是口吃。
如何突破这个电话,以防止这种口吃?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="$views/css/image.css">
<link rel="stylesheet" href="$views/css/list.css">
<link rel="stylesheet" href="$views/css/buttons.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/github.css">
</head>
<body>
<div id="wrapper">
<div id="index" class="section">
<h1>Loop Sections of Songs for Training</h1>
<table id="mytable" width="50%" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<th>
In Point
</th>
<th>
Out Point
</th>
<th colspan="3">
Actions
</th>
</tr>
<tr id="row0" class="row">
<td>
<button class="inPoint" id="inPoint0">0:00</button>
</td>
<td>
<button class="outPoint" id="outPoint0">0:00</button>
</td>
<td>
<button class="startLoop" id="startLoop0">Loop</button>
</td>
<td>
<button class="stopLoop" id="stopLoop0">Stop Loop</button>
</td>
<td>
<button class="clearLoop" id="clearLoop0">Clear Loop</button>
</td>
</tr>
</tbody>
</table>
<button id="add">+</button>
</div>
</div>
<script src="/js/jquery.min.js"></script>
<script type="text/javascript" data-container="js">
require(['$api/audio', '$api/models'], function(audio, models) {
var analyzer = audio.RealtimeAnalyzer.forPlayer(models.player);
var outPointValue = 0;
var inPointValue = 0;
var inPoint = $('.inPoint');
var outPoint = $('.outPoint');
var clearLoop = $('.clearLoop');
var startLoop = $('.startLoop');
var stopLoop = $('.stopLoop');
var trackPosition = null;
var loop = false;
//Watch Track Player Position
analyzer.addEventListener('audio', monitorAudio);
//Get The Current Player Position
function monitorAudio() {
models.player.load('position').done(function(p) {
console.log(p.position);
if(loop && p.position >= outPointValue && outPointValue !== 0) {
console.log('Begin to Loop Section Again');
p.seek(inPointValue);
}
if(inPoint.data('inClicked')) {
console.log('Set inPoint');
inPointValue = p.position;
inPoint.html(msToTime(inPointValue));
inPoint.data('inClicked', false);
}
if(outPoint.data('outClicked')) {
console.log('Set outPoint');
outPointValue = p.position;
outPoint.html(msToTime(outPointValue));
outPoint.data('outClicked', false);
}
});
}
stopLoop.prop('disabled', true);
startLoop.on('click', function() {
loop = true;
$(this).prop('disabled', true);
//var trid = $(this).closest('tr').attr('id');
$('.stopLoop').prop('disabled', false);
});
stopLoop.on('click', function() {
loop = false;
//console.log(this.id);
$(this.id).prop('disabled', false);
$(this.id).closest('.stopLoop').prev().prop('disabled', true);
});
clearLoop.on('click', function() {
loop = false;
inPointValue = 0;
inPoint.html('0:00');
outPointValue = 0;
outPoint.html('0:00');
});
inPoint.click(function(){
$(this).data('inClicked', true);
});
outPoint.click(function(){
$(this).data('outClicked', true);
});
function msToTime(s) {
var ms = s % 1000;
s = (s - ms) / 1000;
var secs = s % 60;
s = (s - secs) / 60;
var mins = s % 60;
var hrs = (s - mins) / 60;
return mins + ':' + secs;
}
$(document).ready(function() {
var counter = 1;
$("#add").click(function() {
$('#mytable .row:last').clone(true).insertAfter('#mytable .row:last');
$('#mytable .row:last').attr('id', 'row' + counter);
$('#mytable .row:last button').each(function() {
$(this).attr('id', $(this).attr('class') + counter);
});
counter++;
return false;
});
});
});
</script>
</body>
</html>
答案 0 :(得分:0)
我说你应该能够添加一个var requested_seek=false
,当你调用seek时将其设置为true,然后在else if p.position < outPointValue
或类似的东西中再次设置为false。哦,if(loop && !requested_seek && p.position >= outPointValue && outPointValue !== 0)
。如果您需要我完整的样本,请告诉我,但我认为这应该足够了,因为到目前为止您的工作。
喜欢app的想法,顺便说一句。