问题
Do you think this might be a flawlles solution to Check if Audio() is playing? Like when handling a stratup theme ...
Place this above in the head
songStarted = false;
song = new Audio();
song.src = 'audio/startuptheme.mp3';
song.addEventListener('playing', (event) => {songStarted = true;});
song.play();
And use the following script anywhere (where first user interaction should happen), as many times as you need
if (!songStarted){
if (typeof song == 'undefined'){
song = new Audio();
song.src = 'audio/startuptheme.mp3';
}
song.addEventListener('playing', (event) => {songStarted = true;});
song.play();
}
I dont think any one can come with a better solution, unless it's an equally flawless solution without the use of globals vars.
来源:https://stackoverflow.com/questions/61407319/dont-you-think-this-might-be-a-flawlles-solution-to-check-if-audio-is-playing