Audio Out does not work on Iphone browsers

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

CODE:

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.

And where exactly have you got this code?

27/5000

I am using a function...

[{"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}]

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

post your flow 

and end with 3 backticks `

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

[{"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?

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

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!

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).

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:

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

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.