如何暂停音频onclick现在停止音频并从头开始

时间:2015-11-06 07:11:39

标签: javascript jquery dom audio html5-canvas

伙计们请帮助我完成我的项目,首先让我告诉你我的网站流量,有4个鹿每个都包含一个独特的声音,当我点击其中任何一个音频文件播放曲目和鹿开始动画时,当我再次点击它时,音频停止,动画也停止了。现在,如果我再次点击鹿,音频从头开始。我想要做的是从开始音频开始,我停止,换句话说我想暂停或静音音频所以当我再次点击它时,它从我停止的地方开始。以下是我的网站链接,如果您需要有关该项目的其他信息,请告诉我。 My Project Link

<script type="text/javascript">
function $extend(e, t) {
    function a() {}
    a.prototype = e;
    var i, n = new a;
    for (i in t) n[i] = t[i];
    return n
}


function $bind(e, t) {
    var a = function() {
        return a.method.apply(a.scope, arguments)
    };
    return a.scope = e, a.method = t, a
}
var Horse = function(e) {
    this._play = !1, this._index = e;
    var t = createjs.SoundJS.getCapability("mp3") ? ".mp3" : ".ogg";
    this._sound = "r/" + this._index + t, t = Horse._sizes[e], 
    e = new createjs.SpriteSheet({
        images: ["r/" + e + ".png"],
        frames: {
            width: t.w,
            height: t.h
        },
        animations: {
            sing: [0, Horse._totalFrames[e] - 1]
        }
    }), createjs.BitmapAnimation.call(this, e), console.log(e.getNumFrames("sing")), this.gotoAndStop(0), this.onClick = $bind(this, this.clickHandler)
};
Horse.__super__ = createjs.BitmapAnimation, Horse.prototype = $extend(createjs.BitmapAnimation.prototype, {
    clickHandler: function() {
        (this._play = !this._play) ? (this.gotoAndPlay("sing"), createjs.SoundJS.play(this._sound, createjs.SoundJS.INTERRUPT_NONE, -1, 0, 0)) : (this.gotoAndStop(0), createjs.SoundJS.stop(this._sound))
    }
});

var Main = function() {
    createjs.Ticker.setFPS(12);
    var e = document.getElementById("canv");
    this._stage = new createjs.Stage(e);
    var t = new createjs.Bitmap("r/bg.jpg");
    this._stage.addChild(t), 
    t = new Horse(0), 
    t.x = 2, t.y = 45, 
    this._stage.addChild(t), 
    t = new Horse(1), 
    t.x = 150, t.y = 45, 
    this._stage.addChild(t), 
    t = new Horse(2), 
    t.x = 270, t.y = 45, 
    this._stage.addChild(t), 
    t = new Horse(3), 
    t.x = 395, 
    t.y = 45, 
    this._stage.addChild(t), 
    t = e.width / 550, 
    e = e.height / 300, 
    t > e ? t = e : e = t,
    this._stage.scaleX = t, 
    this._stage.scaleY = e, 
    this._stage.update(), 
    createjs.Ticker.addListener($bind(this, this.tickerHandler))
};
Main.main = function() {
    var e = new createjs.PreloadJS;
    e.installPlugin(createjs.SoundJS), e.onComplete = Main.loaderCompleteHandler, e.loadFile("r/bg.jpg"), createjs.SoundJS.checkPlugin(!0);
    for (var t = createjs.SoundJS.getCapability("mp3") ? ".mp3" : ".ogg", a = 0; 4 > a;) {
        var i = a++;
        e.loadFile("r/" + i + t), e.loadFile("r/" + i + ".png")
    }
}, Main.loaderCompleteHandler = function() {
    new Main
}, Main.prototype = {
    tickerHandler: function() {
        this._stage.update()
    }
};
var $_;
Horse._totalFrames = [8, 8, 8, 8], Horse._sizes = [{
    w: 152,
    h: 257
}, {
    w: 152,
    h: 257
}, {
    w: 152,
    h: 257
}, {
    w: 152,
    h: 257
}], Main.main();</script>

0 个答案:

没有答案