From cfb2925fb592c117c119edb8cd784b99e2142bc0 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 11 Mar 2022 00:50:34 +0800 Subject: still trying to fix autoplay. --- libs/music/player.d/main_static.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libs/music') diff --git a/libs/music/player.d/main_static.js b/libs/music/player.d/main_static.js index 28ecee5..7070e1d 100644 --- a/libs/music/player.d/main_static.js +++ b/libs/music/player.d/main_static.js @@ -472,16 +472,18 @@ NSAudio={ { window.AudioContext=window.AudioContext||window.webkitAudioContext||window.mozAudioContext||window.msAudioContext; if(!window.AudioContext)alert('This page requires Web Audio API to work...'); - this.audioctx=new AudioContext; - this.anlznode=this.audioctx.createAnalyser(); + if(this.audioctx===null)this.audioctx=new AudioContext; + if(this.anlznode===null)this.anlznode=this.audioctx.createAnalyser(); this.anlznode.fftSize=2*NSVisualization.nbins; NSUI.audio.volume=1; }, connect:function() { + if(this.srcnode===null) this.srcnode=this.audioctx.createMediaElementSource(NSUI.audio); this.srcnode.connect(this.anlznode); this.anlznode.connect(this.audioctx.destination); + if(this.audioctx.state!="running")throw "resume required"; }, }; @@ -768,7 +770,7 @@ function init() let initerr=0; try{ NSAudio.audioInit();NSAudio.connect(); - }catch(e){initerr=1;} + }catch(e){initerr=1;console.log(e);if(NSAudio.audioctx!==null)NSAudio.audioctx.resume();} if(window.location.hash.length) { let p=window.location.hash.substr(1).split('/'); -- cgit v1.2.3