0

嘿,我被困在这个小型的 Spotify 应用程序上,我正在整合它来帮助练习新歌。它只是抓取开始时间和结束时间,然后一旦激活,就会继续循环 - 非常适合学习曲目中的困难部分。

问题:我可以从控制台日志中看到 RealtimeAnalyzer 将我的消息的 5 到 11 个控制台日志以及我正在调用的 .seek 函数放入 - 所以当当前位置大于终点时,它正在使用 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>
4

1 回答 1

0

我会说你应该能够添加 a var requested_seek=false,在你调用 seek 时将其设置为 true,然后在 anelse if p.position < outPointValue或类似的东西中再次将其设置为 false。哦,还有if(loop && !requested_seek && p.position >= outPointValue && outPointValue !== 0)。如果您需要我制作完整的样本,请告诉我,但鉴于您目前的工作,我认为这应该足够了。

喜欢这个应用程序的想法,顺便说一句。

于 2014-01-01T19:10:43.110 回答