How to add a song progress bar in SoundManager2?

断了今生、忘了曾经 提交于 2019-12-06 14:08:59

The logic seems to be fine - what you need to is to call the modify width snippet while the track is playing, using the whileplaying method (I think):

soundManager.setup({
    url: '/swf',
    preferFlash: false,
    waitForWindowLoad: true,

    onready: function() {

        var myTrack1 = soundManager.createSound({
        id: 'trackOne', url: 'msamples/beep-1.mp3', volume: 80, autoPlay: false,});

        $("li.a5 a").click(function(event){soundManager.play('trackOne');});
    },

    whileplaying: function() {
      $(".progBar").css('width', ((this.position/this.duration) * 100) + '%');
    },

    ontimeout: function() {
      // Uh-oh. SWF missing, Flash blocked or other issue
    }
});

got it to work by adding the whileplaying: under soundManager.createSound. I also added an onfinish: to reset the progress bar back to 0 width at the end.

  soundManager.createSound({
    id: 'mySound1',
    url: 'msamples/beep-1.mp3',
    whileplaying: function() {
    $(".progBar").css('width', ((this.position/this.duration) * 100) + '%');
        },
    onfinish: function() {
        $(".progBar").css('width', '0');
        }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!