scratchfoundation / scratch-gui

Graphical User Interface for creating and running Scratch 3.0 projects.
https://scratchfoundation.github.io/scratch-gui/develop/
BSD 3-Clause "New" or "Revised" License
4.46k stars 3.55k forks source link

The AudioContext was not allowed to start. #4514

Open JinXJinX opened 5 years ago

JinXJinX commented 5 years ago

Expected Behavior

No warnings in console for production build

Actual Behavior

Keep raising warning (The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu) before user click the page.

And this problem is exists in the current online version https://scratch.mit.edu/projects/editor

screen shot 2019-02-07 at 5 37 19 pm

Steps to Reproduce

Operating System and Browser

related issue #2017

JinXJinX commented 5 years ago

Looks like Firefox is going to block audio autoplay too.

We expect to roll out audible autoplay blocking enabled by default, in Firefox 66, scheduled for general release on 19 March 2019

https://hacks.mozilla.org/2019/02/firefox-66-to-block-automatically-playing-audible-video-and-audio/

jakob-sikken commented 4 years ago

Why is this issue closed? The problem still exists in chrome 78 on mac and windows, not in firefox. The warnings are stopping, when you click in the project.

benjiwheeler commented 4 years ago

The issue seems to be unsolved; don't know what reasoning was behind closing it

benjiwheeler commented 4 years ago

Note that #5444 partially resolves this, but there needs to be a further change.

node_modules/scratch-audio/src/AudioEngine.js calls https://github.com/LLK/scratch-audio/blob/develop/src/StartAudioContext.js ; that also needs a fix

marron9999 commented 1 year ago

I fixed two sources and reduced the warning to only one occurrence.

class AudioEngine {
    constructor (audioContext = new AudioContext(), autoStart = true) {  /*FIXED: add 2nd arg*/
        if(audioContext == null) {  /*FIXED:  if null, set new instance*/
           audioContext = new AudioContext();
        }
        this.audioContext = audioContext;
        if(autoStart) {  /*FIXED: check 2nd arg*/
            StartAudioContext(this.audioContext);
        }
        componentDidMount () {
            if (!this.props.vm.initialized) {
                this.audioEngine = new AudioEngine(null, false); /*FIXED: not start*/

The fix applies to https://marron9999.github.io/scratch-gui/

jonahzheng commented 1 year ago

@marron9999 It doesn't seem to work. 4$O5HLGTWTA%IU LYD4~E84

jonahzheng commented 8 months ago

scratch the warn will stop when you drag any block into the stage!