# Audio Out does not work on Iphone browsers

**URL:** <https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350>\
**Category:** General\
**Created:** [19 April 2019 04:09 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350 "2019-04-19T04:09:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcelo](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Marcelo](https://discourse.nodered.org/u/Marcelo)\
**Post date:** [19 April 2019 04:09 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/1 "2019-04-19T04:09:59Z")

</div>

"ReferenceError: window is not defined (line 1, col 1)"

CODE:

```auto
window.addEventListener('touchstart', function() {
	// create new buffer source for playback with an already
	// loaded and decoded empty sound file
	var source = myContext.createBufferSource();
	source.buffer = myDecodedBuffer;

	// connect to output (your speakers)
	source.connect(myContext.destination);

	// play the file
	source.noteOn(0);

}, false);

```

196/5000

I'm testing this code because Audio output does not work in IPhone browsers. Because this feature is apparently blocked in browsers, and needs to be enabled by the code.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 April 2019 07:27 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/2 "2019-04-19T07:27:44Z")

</div>

And where exactly have you got this code?

---

<div class="post-metadata">

**Author:** ![Marcelo](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Marcelo](https://discourse.nodered.org/u/Marcelo)\
**Post date:** [19 April 2019 13:40 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/3 "2019-04-19T13:40:54Z")

</div>

27/5000

I am using a function...

```auto
[{"id":"d6507d5.db6618","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"89139738.8efc68","type":"ui_button","z":"d6507d5.db6618","name":"","group":"41df6da4.9283d4","order":1,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"May Test","payloadType":"str","topic":"","x":205.5,"y":159,"wires":[["1e370710.fbb1d9","83557aa3.88c3c8"]]},{"id":"1e370710.fbb1d9","type":"function","z":"d6507d5.db6618","name":"","func":"window.addEventListener('touchstart', function() {\n\n\t// create new buffer source for playback with an already\n\t// loaded and decoded empty sound file\n\tvar source = myContext.createBufferSource();\n\tsource.buffer = myDecodedBuffer;\n\n\t// connect to output (your speakers)\n\tsource.connect(myContext.destination);\n\n\t// play the file\n\tsource.noteOn(0);\n\n}, false);","outputs":1,"noerr":0,"x":393,"y":110,"wires":[["21b1450a.258cfa"]]},{"id":"21b1450a.258cfa","type":"debug","z":"d6507d5.db6618","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":579,"y":111,"wires":[]},{"id":"83557aa3.88c3c8","type":"delay","z":"d6507d5.db6618","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":362,"y":182,"wires":[["e4ac0db1.160d6"]]},{"id":"e4ac0db1.160d6","type":"ui_audio","z":"d6507d5.db6618","name":"","group":"c41bfe3d.aa17c","voice":"pt-BR","always":true,"x":513.5,"y":187,"wires":[]},{"id":"41df6da4.9283d4","type":"ui_group","z":"","name":"Default","tab":"42562d98.3bd3e4","disp":true,"width":"6","collapse":false},{"id":"c41bfe3d.aa17c","type":"ui_group","z":"","name":"Default","tab":"42562d98.3bd3e4","disp":true,"width":"6","collapse":false},{"id":"42562d98.3bd3e4","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 April 2019 13:53 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/4 "2019-04-19T13:53:46Z")

</div>

The function node is executed in nodejs, there is no `window` in a server side script.  
Note: use 3 backticks: `

```auto
post your flow 

```

and end with 3 backticks `

---

<div class="post-metadata">

**Author:** ![Marcelo](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Marcelo](https://discourse.nodered.org/u/Marcelo)\
**Post date:** [19 April 2019 14:13 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/5 "2019-04-19T14:13:37Z")

</div>

Is there a way to run this script on the client?

```auto
[{"id":"d6507d5.db6618","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"89139738.8efc68","type":"ui_button","z":"d6507d5.db6618","name":"","group":"41df6da4.9283d4","order":1,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"May Test","payloadType":"str","topic":"","x":205.5,"y":159,"wires":[["1e370710.fbb1d9","83557aa3.88c3c8"]]},{"id":"1e370710.fbb1d9","type":"function","z":"d6507d5.db6618","name":"","func":"window.addEventListener('touchstart', function() {\n\n\t// create new buffer source for playback with an already\n\t// loaded and decoded empty sound file\n\tvar source = myContext.createBufferSource();\n\tsource.buffer = myDecodedBuffer;\n\n\t// connect to output (your speakers)\n\tsource.connect(myContext.destination);\n\n\t// play the file\n\tsource.noteOn(0);\n\n}, false);","outputs":1,"noerr":0,"x":393,"y":110,"wires":[["21b1450a.258cfa"]]},{"id":"21b1450a.258cfa","type":"debug","z":"d6507d5.db6618","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":579,"y":111,"wires":[]},{"id":"83557aa3.88c3c8","type":"delay","z":"d6507d5.db6618","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":362,"y":182,"wires":[["e4ac0db1.160d6"]]},{"id":"e4ac0db1.160d6","type":"ui_audio","z":"d6507d5.db6618","name":"","group":"c41bfe3d.aa17c","voice":"pt-BR","always":true,"x":513.5,"y":187,"wires":[]},{"id":"41df6da4.9283d4","type":"ui_group","z":"","name":"Default","tab":"42562d98.3bd3e4","disp":true,"width":"6","collapse":false},{"id":"c41bfe3d.aa17c","type":"ui_group","z":"","name":"Default","tab":"42562d98.3bd3e4","disp":true,"width":"6","collapse":false},{"id":"42562d98.3bd3e4","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

Or is there any other way to make the audio work in the browsers of the mobile?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 April 2019 14:58 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/6 "2019-04-19T14:58:06Z")

</div>

What is the purpose of the flow ? You want to play an audio file ?

---

<div class="post-metadata">

**Author:** ![Marcelo](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Marcelo](https://discourse.nodered.org/u/Marcelo)\
**Post date:** [19 April 2019 15:51 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/7 "2019-04-19T15:51:29Z")

</div>

I just need to make "Audio Out" work on some browser running on the iphone. Running an audio file would be an attempt to make "Audio Out" work, but I do not know if this will work.

Maybe I should change the problem from this topic to: "Audio does not work on Iphone browsers."

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 April 2019 16:20 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/8 "2019-04-19T16:20:40Z")

</div>

Node info:

> ## **To work the editor web page must be open.**

So only when you have the editor open you can hear it (it is not working on my iphone, correct, possibly not supported on safari mobile).

---

<div class="post-metadata">

**Author:** ![Marcelo](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Marcelo](https://discourse.nodered.org/u/Marcelo)\
**Post date:** [19 April 2019 16:52 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/9 "2019-04-19T16:52:25Z")

</div>

It does not work on Safari, Chrome or Mozilla on the phone.

All the possible solutions I've found seemingly need to use a script on the client. I think this was the best post I found on the problem:

> **[Unlocking Web Audio — the smarter way](https://hackernoon.com/unlocking-web-audio-the-smarter-way-8858218c0e09?gi=62042c1902ec)**
>
> The Web Audio API provides a powerful and versatile system for controlling audio on the Web, allowing developers to choose audio sources…

But I still do not know how to solve this problem...

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 February 2020 12:11 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/11 "2020-02-20T12:11:10Z")

</div>

Oops! Just noticed the date! Ignore me. Hopefully this will now trigger the thread close.

Safari is a typical Apple product and quite aggressive in locking things down so no real surprise that it doesn't work.

You will almost certainly need to use Dashboard or uibuilder to create a client page then send the audio stream or file to that.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 February 2020 13:30 UTC](https://discourse.nodered.org/t/audio-out-does-not-work-on-iphone-browsers/10350/12 "2020-02-20T13:30:15Z")

</div>


