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

Preloading sounds have become noticeable in Chrome #3536

Open
NeilFraser opened this issue Jan 3, 2020 · 7 comments
Open

Preloading sounds have become noticeable in Chrome #3536

NeilFraser opened this issue Jan 3, 2020 · 7 comments
Labels
component: audio issue: bug Describes why the code or behaviour is wrong
Milestone

Comments

@NeilFraser
Copy link
Contributor

We need to preload and cache all the sounds, otherwise when we play a sound the first instance will play a second late. The Audio API has a 'preload' attribute that's designed to provide exactly this. However, when tested back in 2014, this did not work across all browsers. So we chose to play all sounds at minimum volume upon page load. At a volume of just 1%, this didn't used to be audible.

However, this preloading is now audible. Crank your volume up, and load any of the demo pages in Chrome (at least on a Mac). On page load, one can clearly hear the click and delete sounds. Despite the code, there's no way that this is 1% volume.

I think it's time that Blockly take another look at sounds and determine if there are better ways of preloading sounds in the majority of browsers. We will probably need to keep the hacky low-volume preload technique for IE, but at a minimum I'd expect that Chrome and FF should have proper preloading abilities. Also be aware that iOS can apparently only play one sound. This is a swamp of browser-specific gotchas.

Surfaced due to google/blockly-games#171

@NeilFraser NeilFraser added issue: bug Describes why the code or behaviour is wrong issue: triage Issues awaiting triage by a Blockly team member labels Jan 3, 2020
@moniika moniika added this to the Bug Bash Backlog milestone Jan 6, 2020
@moniika moniika added component: audio and removed issue: triage Issues awaiting triage by a Blockly team member labels Jan 6, 2020
@samelhusseini
Copy link
Contributor

Let's look at using .preload = "auto". That leaves it up to the browser to decide whether or not to preload the audio file. It seemed to work quite well in the browsers I tested (Chrome, Firefox, Safari), but we should look at how some older browsers (that we still support) deal with that.

https://www.w3schools.com/tags/att_audio_preload.asp

@moniika
Copy link
Contributor

moniika commented Jan 22, 2020

A related issue. The current approach for preloading sounds seems to not work in firefox.
The preloading is not audible, warning is seen: "Autoplay is only allowed when approved by the user, the site is activated by the user, or media is muted", and a delay is heard for sounds.

@samelhusseini
Copy link
Contributor

I spent some time looking into this, and it seems adding the preload:auto attribute to the HTMLAudioElement is preferred way to notify the browser that we'd like an audio file preloaded, without actually enforcing it. If the browser has other reasons to ignore our "request" for preloading it, then so that seems fair to me.

Changing to this would require cross browser physical testing. I tried this on IOS, and it appears we're not handling click events quick enough thus not allowing us to play the audio (as now browsers require you to have an associated click even to play audio).

@tuzz
Copy link

tuzz commented Apr 21, 2021

We're also seeing that audio events are sometimes not being played in our Blockly workspace on iOS devices. It does seem to be the case that they're not being handled quickly enough and that is then triggering the browser's restriction that audio must be played in response to a user action.

In addition to preloading the audio, it might also help to wrap this call to mySound.play() in the same defensive code that is used above - although ideally, the audio should always work.

@jeroenvekemans
Copy link

We see the same behavior testing https://blockly.games/maze on iOS devices:

  1. at startup, the preload of one audio is noticable at normal volume
  2. the connect sound when you attach one block to another is not played at all on these devices

Are there any related issues/updates on this?

@cpcallen
Copy link
Contributor

I can verify that on iOS (specifically, Chrome on iOS 14 on iPhone SE 2016) the only sound that plays is the preloading click sound; no other sounds play at all AFAICT (so for example Pond is entirely silent while running).

Earlier @NeilFraser wrote:

Despite the code, there's no way that this is 1% volume.

Possibly true, but be aware that if 1% volume means 1% of amplitude that that is only -20dB; given that human hearing has a dynamic range of ~120dB that' not really particularly quiet. (Or to put it another way: a decrease in amplitude to 1% only quiets 7 bits of the typical 16 bits per sample.)

@Entkenntnis
Copy link

Entkenntnis commented Jun 15, 2023

This is happening in Firefox 112 for me. I can hear the preloading click - it's noticably quiter (possibly 1%), but still audible.

Can you set the volume to an even lower value?

sound.volume = 0.01;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: audio issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

No branches or pull requests

7 participants