-
Notifications
You must be signed in to change notification settings - Fork 20
C2LC-253: Ensure that Tone is started on the first user action. #96
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
Conversation
I'm still seeing the warnings in Chrome with this branch. I think what we'd need to do is call the Tone.js |
The general approach seems sound to me: create a Promise that we can wait on and then tie that Promise resolution/rejection to the Promise from starting Tone.js. However, I'm still seeing the warnings in Chrome in the console. The warnings are generated at page load, before any user interaction. It looks like we need to delay more of the work until Tone.js has been started. I also have some notes (which may not be relevant after refactoring to delay more work):
|
Just to be sure I wasn't missing anything, I tried making a double-promise system. The first promise was for Tone itself, at which point I would try to create the I went back to a single promise approach where I create the I also relocated the promise check to |
Just to comment further, sadly there is no promise infrastructure within Tone.js to wait for the load to complete. We could create something with polling, but if we can live with what I have that seems less fiddly. |
This PR is still not addressing the issue: the warnings in Chrome continue to be displayed at page load. You have moved the code to set up the audio objects to a new method Could you also edit this PR to change the target branch to |
@simonbates, I have updated with I previously tried tying the sound initialisation to the start promise, but had trouble with the first sound that should be played not playing. I reset things back to the earlier approach and committed for your review. |
I'm still seeing the "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page." warnings on page load in Chrome Developer Tools console when I open https://deploy-preview-96--c2lc-build.netlify.app/ |
OK, so we're now in a state where the audio components are not created until after the first user action. For keyboard navigation this is fine, as there's generally enough time to load the actual sounds before the user gets to something that should trigger a sound. However, it's pretty easy using a mouse to click something and not have the first sound play. We need to discuss how to handle this, perhaps adding a promise wrapper with polling so that we can start the sound once it's loaded. We also need to figure out a couple of issues. First, @chosww was reporting not being able to hear sounds at all when using the preview site. Second, and more critically, even though I don't see any errors locally, I do indeed see "The AudioContext was not allowed to start" messages when loading the deployed preview site. I added a breakpoint at the point where I call Tone.start, and confirmed that I wasn't managing to trigger that on startup or anything. Looking at the stack traces, I can't see anywhere in our code that's actually performing the action that results in the error. |
Those files are "tests" as in "checks", not tests as in unit, integration, etc. The files come from the package |
Pretty sure we're hitting this known and unfixed issue with Tone.js. His assertion is that these are warnings and should not affect playback. I will work on at least getting the first sound working. |
…cing first sound played.
OK, I added the promise wrapper I had in mind around the I suspect we've eliminated as many of the warnings as we can at this point, as far as I know this is ready for review. |
Once deployed, the load time for the sounds goes up high enough that there is a noticeable delay if you immediately trigger a sound. We should review together and discuss whether / how to address it. The easiest way to reproduce is to shift+reload and click one of the action buttons with the mouse. The "move" announcement will be delayed. |
As we discussed this morning, we won't continue working any more on this issue for now. It looks like the warnings are triggered by Tone.js code that is out of our control. If Tone.js is changed in the future to remove these warnings, at that time we can see if we need to make any code changes. |
@sbates-idrc, I think we may need to revisit this, as the work I'm doing with Julien is often resulting in unplayed first sounds. |
Interesting. We also experienced issues with delayed sound playing due to audio file download time. Is it possible that what you are seeing with Julien is caused by that? |
I don't think so, the new approach doesn't use any samples at all. |
Got it. |
As discussed, we will handle this (if needed) in the alternate tuning work. |
See C2LC-253 for details.