-
-
Notifications
You must be signed in to change notification settings - Fork 682
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
RFC: p5.initSound method #402
Conversation
Hi @therewasaguy thanks for jumping on this! Sorry for the delay, I was taking a brief break from the computer. This is really exciting! I wonder if the automatic adding of a button will feel obtrusive at times. I like it as an option but I wonder if there is a way that
would I see a button push the canvas down for a brief second? My only other concern is the member method dot syntax for |
Thanks for taking a look @stalgiag ! Really appreciate your perspective here.
Yes, probably! Some options come to mind, option 1 is my favorite, but I would love some input.
Another path...
I like the clarity of 4, the main downside is that this would really clutter the examples.
I hadn't considered this, thanks for bringing it up. I guess this could lead to some confusion because the way we instantiate p5 sound object (i.e. This could be a reason to lean towards 4... |
I like the flexibility of 4. It might crowd some examples, but perhaps it would be possible to simplify some examples by making the arguments to Which I guess brings up some questions about how someone would write a simple sketch that played a sound upon mouse click. Would it look like this?
The meaning of Definitely a tough design decision. Perhaps @lmccart @outofambit @limzykenneth or any other contributors have thoughts? |
From what I can come up with, there's obtrusive and unobtrusive methods. Obtrusive ones will be once the coder include I wonder can we combine the two so that if it is called in |
To me, having at minimum an unobtrusive version, similar to @stalgiag's snippet above makes sense. Maybe the name Additionally having an obtrusive method, that is, putting up default element to prompt user interaction, is an interesting idea. I do like the simplicity of being able to put |
Thank you everyone for your thoughtful comments, and happy 2020! For now, I'm going to continue down the unobtrusive route and just revise all the examples to demonstrate the best practice of waiting for a user gesture to make any noise as described in https://github.com/processing/p5.js-sound/issues/388 I'm pretty sure this can work without any explicit call to For the inline documentation examples, I think we also should include some feedback to the user about how to start audio, and that it should be tied to canvas mousePressed events rather than anywhere on the page (otherwise sounds toggle while editing the example). So that example would look something like
For the long run, there are a few reasons I think it would be useful to have an
I like exploring this hybrid direction! |
I'm going to close this for now and keep working on revising the examples to use best practices with the api we already have, PR in progress here #403 |
add initSound method
p5.initSound
on the global p5 object. It starts the AudioContext on a user gesture. The user can specify which element should listen for a user gesture, otherwise it falls back to creating a button on the first p5 sketch like this:^ that's the easiest usage, to call it before preload.
But it can also be used with arguments specifying which element should be used to initialize audio, and it returns a promise, or calls a callback.
or
or, similar to a custom preload, we can create a custom HTML element and stylize it however we want.
deprecate userStartAudio method
p5.prototype.userStartAudio
, which historically the same thing as initSound, but is on the prototype so cannot be called before preload. There is no need to have this method on the p5 instance, because the audio context is shared across instances (there should only be one audio context on the page)Testing
To test in Chrome, go to People --> Add Person before loading a site so that (this resets your Media Engagement Index, which is used to determine whether autoplay is allowed on a given domain)