# Question about openprocessing.org functionality

**URL:** <https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181>\
**Category:** Libraries\
**Created:** [August 4, 2019, 3:08pm UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181 "2019-08-04T15:08:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SheCurvesMobius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shecurvesmobius/32/7054_2.png) [@SheCurvesMobius](https://discourse.processing.org/u/SheCurvesMobius)\
**Post date:** [August 4, 2019, 3:08pm UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181/1 "2019-08-04T15:08:48Z")

</div>

Hello all,

If I place a sound in the setup function it will play when I hit the play button. However, if I navigate to the page through a link on my [openprocessing.org homepage](https://www.openprocessing.org/user/183916#sketches), then the sound won’t play. In that same scenario, if I place the sound in the draw function, though, it does play.

In [this thread](https://discourse.processing.org/t/keytyped-not-working-until-mouse-is-pressed/13151/4), someone pointed out that the you need to direct the browser to the canvas. I’m wondering why this particular nuance occurs though, depending on how you navigate to the page. Does anyone have any insight? (Thanks!)

Here’s the code:

```auto
let bell;

function preload() {
	soundFormats('mp3');
	bell = loadSound('doorbell.mp3'); 
}

function setup() {
	createCanvas(windowWidth, windowHeight);
	bell.setVolume(0.5); 
	bell.play();
	clickNotice();	
}

function clickNotice() {
	textSize(12);
	textAlign(CENTER);
	textFont("Helvetica");
	text("If sound doesn't play, click the canvas or hit the refresh button to activate the sketch", width / 2, height / 2);
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 4, 2019, 7:56pm UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181/2 "2019-08-04T19:56:37Z")

</div>

I just assume that the play button treats setup differently than the call via the browser. That’s not really an explanation.

Just out of curiosity: did you program a Moebius band?

---

<div class="post-metadata">

**Author:** ![SheCurvesMobius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shecurvesmobius/32/7054_2.png) [@SheCurvesMobius](https://discourse.processing.org/u/SheCurvesMobius)\
**Post date:** [August 4, 2019, 7:58pm UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181/3 "2019-08-04T19:58:39Z")

</div>

Thanks 🙂 And no, I’m afraid I didn’t. That nickname is from forever ago. I liked some of the connotations of the infinity symbol.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [August 5, 2019, 3:48pm UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181/4 "2019-08-05T15:48:16Z")

</div>

Hey There!

Just to add,  
I believe by default as well Google Chrome (if Chrome was used) doesn’t play sounds now if a page is entered.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 7, 2019, 9:03pm UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181/5 "2019-08-07T21:03:30Z")

</div>

> [@SheCurvesMobius](#):
>
> If I place a sound in the setup function it will play when I hit the play button. However, if I navigate to the page through a link on my [openprocessing.org homepage](https://www.openprocessing.org/user/183916#sketches), then the sound won’t play. In that same scenario, if I place the sound in the draw function, though, it does play.

> [@InferNova](#):
>
> I believe by default as well Google Chrome (if Chrome was used) doesn’t play sounds now if a page is entered.

Tricky. This sounds like it might be worth documenting in a p5.js issue, if there isn’t one already.

- [Issues · processing/p5.js · GitHub](https://github.com/processing/p5.js/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sound)

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [August 8, 2019, 11:53am UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181/6 "2019-08-08T11:53:47Z")

</div>

With the Google Chrome thing it a standard for all platforms. I made a HTML game 2 months back and sounds within the game to play had to have the button clicked they would not play by default.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 8, 2019, 5:18pm UTC](https://discourse.processing.org/t/question-about-openprocessing-org-functionality/13181/7 "2019-08-08T17:18:46Z")

</div>

> **[Reference](https://p5js.org/reference/#/p5.sound/getAudioContext)**
>
> Find easy explanations for every piece of p5.js code.

> [@Pls critique my code!](https://discourse.processing.org/t/pls-critique-my-code/12855/2):
>
> Not at all! Callback preload() is the single best place to load assets. star_struck BtW, you’ve got some missing indentation on your posted code. woozy_face We can use [Beautifier.io](http://Beautifier.io) in order to clean up our JS code. wink Here’s my own take on your sketch (Warning: Not fully tested!): sunglassesindex.html: \<!DOCTYPE html\> \<meta charset=utf-8\> \<meta name=viewport content=width=device-width,initial-scale=1\> \<script defer src=https://cdn.JsDelivr.net/npm/p5\>\</script\> \<script defer s…
