From 8d7365b683d522250b6a701219e193f5d8761309 Mon Sep 17 00:00:00 2001 From: oc Date: Sun, 3 Feb 2019 18:55:39 +0800 Subject: [PATCH] stopSound --- libs/control.js | 18 +++++++++++++++++- libs/core.js | 5 +++++ libs/events.js | 15 +-------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/libs/control.js b/libs/control.js index f336d1c1..30e34c33 100644 --- a/libs/control.js +++ b/libs/control.js @@ -2667,7 +2667,6 @@ control.prototype.playSound = function (sound) { var source = core.musicStatus.audioContext.createBufferSource(); source.buffer = core.material.sounds[sound]; source.connect(core.musicStatus.gainNode); - source.loop = true; var id = parseInt(Math.random()*10000000); source.onended = function () { delete core.musicStatus.playingSounds[id]; @@ -2697,6 +2696,23 @@ control.prototype.playSound = function (sound) { } } +control.prototype.stopSound = function () { + for (var i in core.musicStatus.playingSounds) { + var source = core.musicStatus.playingSounds[i]; + try { + source.stop(); + } + catch (e) { + try { + source.noteOff(0); + } + catch (e) { + main.log(e); + } + } + } +} + control.prototype.checkBgm = function() { core.playBgm(core.musicStatus.playingBgm || main.startBgm); } diff --git a/libs/core.js b/libs/core.js index a9506ef9..47eb16c9 100644 --- a/libs/core.js +++ b/libs/core.js @@ -1502,6 +1502,11 @@ core.prototype.playSound = function (sound) { core.control.playSound(sound); } +////// 停止所有音效 ////// +core.prototype.stopSound = function () { + core.control.stopSound(); +} + ////// 动画显示某对象 ////// core.prototype.show = function (obj, speed, callback) { core.utils.show(obj, speed, callback); diff --git a/libs/events.js b/libs/events.js index 509d6428..3cd877cc 100644 --- a/libs/events.js +++ b/libs/events.js @@ -960,20 +960,7 @@ events.prototype.doAction = function() { this.doAction(); break; case "stopSound": - for (var i in core.musicStatus.playingSounds) { - var source = core.musicStatus.playingSounds[i]; - try { - source.stop(); - } - catch (e) { - try { - source.noteOff(0); - } - catch (e) { - main.log(e); - } - } - } + core.stopSound(); break; case "setVolume": data.value = core.clamp(parseInt(data.value)/100, 0, 1);