Merge pull request #810 from nonameShijian/PR-Branch

背景音乐在不可播放时不调用play()
This commit is contained in:
Spmario233 2024-01-18 23:31:24 +08:00 committed by GitHub
commit 842835c521
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -17,7 +17,7 @@ export async function cordovaReady() {
}
});
document.addEventListener("resume", () => {
if (ui.backgroundMusic) ui.backgroundMusic.play();
if (ui.backgroundMusic && !isNaN(ui.backgroundMusic.duration)) ui.backgroundMusic.play();
});
document.addEventListener("backbutton", function () {
if (ui.arena && ui.arena.classList.contains('menupaused')) {

View File

@ -9050,10 +9050,9 @@ class Create extends Uninstantable {
ui.backgroundMusic.autoplay = true;
ui.backgroundMusic.addEventListener('ended', game.playBackgroundMusic);
ui.window.appendChild(ui.backgroundMusic);
ui.window.addEventListener(lib.config.touchscreen ? 'touchend' : 'click', function playMusic() {
ui.window.removeEventListener(lib.config.touchscreen ? 'touchend' : 'click', playMusic, false);
if (!ui.backgroundMusic.played.length && lib.config.background_music != 'music_off') ui.backgroundMusic.play();
}, false);
ui.window.addEventListener(lib.config.touchscreen ? 'touchend' : 'click', () => {
if (!ui.backgroundMusic.played.length && lib.config.background_music != 'music_off' && !isNaN(ui.backgroundMusic.duration)) ui.backgroundMusic.play();
}, {once:true});
if (lib.config.cursor_style == 'pointer') {
ui.window.classList.add('nopointer');
}
@ -14142,6 +14141,10 @@ export class UI extends Uninstantable {
* @type { HTMLDivElement }
*/
static pause;
/**
* @type { HTMLAudioElement }
*/
static backgroundMusic;
static refresh(node) {
void window.getComputedStyle(node, null).getPropertyValue("opacity");
}