首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Howler.js持续负载

Howler.js持续负载
EN

Stack Overflow用户
提问于 2014-10-04 17:49:33
回答 1查看 2.4K关注 0票数 0

我有以下脚本,使用howler.js和jquery 1.8.21.custom.min.js:

代码语言:javascript
复制
$(function(){
    var sounduser1 = new Howl({
        urls: ['studio/keysintheair.mp3', 'studio/keysintheair.ogg'],
        buffer:true,
        volume: 1.0,
        onend: function() {
            $('.buttons').fadeIn();
        },
    });
    var sounduser2 = new Howl({
        urls: ['studio/keysintheair-original.mp3'],
        buffer:true,
        volume: 0.1,
    });

    var thisArray = {
        user1: sounduser1,
        user2: sounduser2
    };

    $.each( thisArray, function(key,value) {
        $('.buildplayer .player').clone().attr('id',key).appendTo('#song');
        $('#song .player:last .waveform').css("width", value._duration + "px");
        $('#song .player:last .slider').slider({
            value: value.volume() * 100,
            range: "min",
            animate: true,
            orientation: "horizontal",
            //Slider Event
            slide: function(event, ui) { //When the slider is sliding
                var now_id = $(this).parent().parent('.player').attr('id');
                thisArray[now_id].volume(ui.value/100);
            },
        });
    });

    $('.mainplayer .trackslider').slider({
        value: 0,
        range: "min",
        animate: true,
        orientation: "horizontal",
        //Slider Event
        slide: function trackslider(event, ui) { //When the slider is sliding
            var audiogetlength = Object.keys( thisArray ).map(function ( key ) { return thisArray[key]._duration; });
            var longest = Math.max.apply( null, audiogetlength );
            var dividedlength = 100/ui.value;
            $.each( thisArray, function( key, value ) {
                value.pos(longest/dividedlength);
                if (ui.value > value._duration) {
                    value.stop();
                }
            });
        },
     });

    setInterval(function starttrackslider() {
        var dividedslider = sounduser1._duration/sounduser1.pos();
        $('.trackslider').slider('value', 100/dividedslider);
    },1000);

    //Single Audio Track Player
    $('.ex1-play').on('click', function(){
        var now_id = $(this).parent().parent('.player').attr('id');
        thisArray[now_id].stop().play();
    });
    $('.ex1-stop').on('click', function(){
        var now_id = $(this).parent().parent('.player').attr('id');
        thisArray[now_id].stop();
    });
    $('.ex1-loop').on('click', function(){
        var now_id = $(this).parent().parent('.player').attr('id');
        thisArray[now_id].loop(true);
    });

    //Main All Track Player
    $('.main-play').on('click', function(){
        $.each( thisArray, function( key, value ) {
        value.stop().play();
        $('.buttons').fadeOut();
        });
    });
    $('.main-pause').on('click', function(){
        $.each( thisArray, function( key, value ) {
        value.pause();
        });
    });
    $('.main-stop').on('click', function(){
        $.each( thisArray, function( key, value ) {
        value.stop();
        $('.buttons').fadeIn();
        });
    });
    $('.main-loop').on('click', function(){
        $.each( thisArray, function( key, value ) {
        value.loop(true);
        });
    });

});

$('.mainplayer .trackslider').slider({ });的最后一部分,您会发现if (ui.value > value._duration) {value.stop();}

value等于sounduser2

两首录音带同时开始。使用滑块会让我跳过音频。滑块将有最长的音轨长度--这是一种叫sounduser1的声音。使用滑块将返回一个数字,这将激活音频的位置。

如果滑块返回一个更大的数字,那么音轨的实际长度就应该停止较短的音轨。

出于某种原因,它不会停止比赛,即使情况是正确的。有人知道该怎么做吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-12 12:51:53

代码语言:javascript
复制
$('.mainplayer .trackslider').slider({
        value: 0,
        range: "min",
        animate: true,
        orientation: "horizontal",
        //Slider Event
        slide: function (event, ui) { //When the slider is sliding
            var audiogetlength = Object.keys( thisArray ).map(function ( key ) { return thisArray[key]._duration; });
            var longest = Math.max.apply( null, audiogetlength );
            var dividedlength = 100/ui.value;
            $.each( thisArray, function( key, value ) {
                var percentvalue = (value._duration/longest)*100;
                if (percentvalue > ui.value) {
                    if (value.pos()==0) {
                        value.play().pos(longest/dividedlength);
                    } else {
                        value.pos(longest/dividedlength);
                    } 
                } else {
                        value.stop();
                }

            });
        }
    });

成功了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26195494

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档