Javascript 满足条件后RealtimeAnalyzer退出
嘿,我被这个小Spotify应用程序卡住了,我正在组装它来帮助练习新歌。它只需要抓取一个开始时间和结束时间,然后一旦激活,就可以继续在上面循环——这有利于学习曲目中的困难部分 问题:我可以从控制台日志中看到RealtimeAnalyzer正在放置我消息的5到11个控制台日志以及我正在调用的.seek函数-因此,当当前位置大于端点时,它使用seek返回到输入点,但会出现口吃 我怎样才能中断通话,防止口吃Javascript 满足条件后RealtimeAnalyzer退出,javascript,jquery,spotify,spotify-app,Javascript,Jquery,Spotify,Spotify App,嘿,我被这个小Spotify应用程序卡住了,我正在组装它来帮助练习新歌。它只需要抓取一个开始时间和结束时间,然后一旦激活,就可以继续在上面循环——这有利于学习曲目中的困难部分 问题:我可以从控制台日志中看到RealtimeAnalyzer正在放置我消息的5到11个控制台日志以及我正在调用的.seek函数-因此,当当前位置大于端点时,它使用seek返回到输入点,但会出现口吃 我怎样才能中断通话,防止口吃 <!DOCTYPE html> <html> <head
<!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:00
0:00
环
停止循环
清晰循环
+
要求(['$api/audio','$api/models'],函数(音频,模型){
var analyzer=audio.RealtimeAnalyzer.forPlayer(models.player);
var outPointValue=0;
var-inPointValue=0;
var inPoint=$('.inPoint');
var outPoint=$('.outPoint');
var clearLoop=$('.clearLoop');
var startoop=$('.startoop');
var stopLoop=$('.stopLoop');
var trackPosition=null;
var循环=假;
//观察运动员的位置
analyzer.addEventListener(“音频”,监视器音频);
//获取当前玩家位置
函数monitorAudio(){
models.player.load('position').done(函数(p){
控制台日志(p位置);
如果(循环和p.position>=输出点值和输出点值!==0){
log('再次开始循环节');
p、 查找(输入点值);
}
if(输入点数据('inClicked')){
log('Set inPoint');
inPointValue=p.位置;
html(msToTime(inPointValue));
输入点数据(“包含”,错误);
}
if(outPoint.data('outClicked')){
log('Set outPoint');
输出点值=p位置;
html(msToTime(outPointValue));
outPoint.data('outClicked',false);
}
});
}
stopLoop.prop('disabled',true);
startOOP.on('click',function()){
循环=真;
$(this.prop('disabled',true);
//var trid=$(this.nexist('tr').attr('id');
$('.stopLoop').prop('disabled',false);
});
stopLoop.on('click',function()){
循环=假;
//console.log(this.id);
$(this.id).prop('disabled',false);
$(this.id).closest('.stopLoop').prev().prop('disabled',true);
});
clearLoop.on('click',function(){
循环=假;
inPointValue=0;
html('0:00');
输出点值=0;
html('0:00');
});
inPoint.click(函数(){
$(此).data('inClicked',true);
});
输出点。单击(函数(){
$(this).data('outClicked',true);
});
函数msToTime(s){
var ms=s%1000;
s=(s-ms)/1000;
var secs=s%60;
s=(s-秒)/60;
var mins=s%60;
var-hrs=(s-分钟)/60;
返回分钟+':'+秒;
}
$(文档).ready(函数(){
var计数器=1;
$(“#添加”)。单击(函数(){
$('#mytable.row:last').clone(true).insertAfter('#mytable.row:last');
$('#mytable.row:last').attr('id','row'+计数器);
$('#mytable.row:last button')。每个(函数(){
$(this.attr('id',$(this.attr('class'))+计数器);
});
计数器++;
返回false;
});
});
});
我想说,您应该能够添加一个var requested\u seek=false
,在调用seek时将其设置为true,然后在中再次将其设置为false,否则如果p.position
或类似的内容。哦,如果(循环&&!请求&&p.position>=outPointValue&&outPointValue!==0)
。让我知道,如果你需要我工作出一个完整的样本,但我认为这应该足够了,考虑到你的工作到目前为止
顺便说一句,我喜欢这个应用程序的想法。谢谢托马斯。我会尝试一下,看看效果如何。我最初有一个setInterval,但后来在api中发现了它。几乎都是制作出来的,这样我就可以学习TesseracT鼓的部分节拍。。。