Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound problems #368

Open
tvoybro opened this issue Jan 9, 2021 · 5 comments
Open

Sound problems #368

tvoybro opened this issue Jan 9, 2021 · 5 comments

Comments

@tvoybro
Copy link

tvoybro commented Jan 9, 2021

Strange sound problems with Chrome browser. There is no sound if you open the ROM page directly. But if you go to the ROM page from another page, the sound appears.

@tvoybro
Copy link
Author

tvoybro commented Jan 10, 2021

I believe I have figured that out. "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page."

@tvoybro tvoybro closed this as completed Jan 10, 2021
@tvoybro
Copy link
Author

tvoybro commented Jan 10, 2021

Solution for me:

document.documentElement.addEventListener(
  "mousedown", function(){
    mouse_IsDown = true;
    if (audio_ctx.state !== 'running') {
    audio_ctx.resume();
  }});

document.documentElement.addEventListener(
  "keydown", function(){
    if (audio_ctx.state !== 'running') {
    audio_ctx.resume();
  }});

@bfirsh
Copy link
Owner

bfirsh commented Jan 10, 2021

Do you think we need this on jsnes.org?

@bfirsh bfirsh reopened this Jan 10, 2021
@tvoybro
Copy link
Author

tvoybro commented Jan 10, 2021

Do you think we need this on jsnes.org?

I think I do, sir, since it seemed like an annoying thing to me as I was really puzzled at first and couldn't find the reason as I am a complete javascript (and debugging it) noob. It looked like a real bug, and it will definitely scare the user away.
With the solution above, the sound turns on whenever the user has a real interest in a web page and tries to intuitively press keyboard buttons or clicks the mouse button. If the user wants to mute the sound, he can reload the page or press the emulator button, if there is one. Until the user takes any action, the emulator runs in quiet like attract mode.

By the way, it will be nice if you update your page with new things for the NES. During this time, good demos and games were released.

@hdb
Copy link

hdb commented Mar 21, 2021

thanks for this project! I'm also noticing sound issues in Safari and webkit-based browsers (seems like this could be the case on jsnes.org too). Adding the webkit prefix to AudioContext fixed it for me:

var AudioContext = window.AudioContext
    || window.webkitAudioContext
    || false;

if (AudioContext) {
    var audio_ctx = new AudioContext;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants