Note that this requires an external .ogg file. I thought you were looking for something like a sound synthesizer, which I believe would require a JavaScript library.
Indeed. That's what I want. As I said in question title, "Playing a sound from a URL". Sorry I didn't make this clear by repeating it in the body.
Thanks anyway for your link to the embedded solution. Good to know that I can embed the sound in the page.
GoToLoop, thanks for the HTML5 .play()o solution. It works fine here on desktop, but fails on Android tablet with both browsers I tried (inc. Chrome) saying "Fail to execute ... The event is already being dispatched." Same with a minimal program of mine having .play() in draw(), also on openprocessing.org. https://www.openprocessing.org/sketch/499777
Answers
What do you mean by not using a separate file? Does an
.mp3
file count as a separate file?But the general answer is going to be: you have to look for a JavaScript library that does what you're looking for.
Not using a separate file. I.e. any file other than the .pde.
Can a .pde call a JS library, then? I thought not.
This is probably not going to be possible. You need to use a JavaScript library.
Not in Java mode, no. But you're presumably using Processing.js.
Please check out this guide: http://processingjs.org/articles/jsQuickStart.html#accessingjsobjectsfrompjs
I have found it is possible taking advantage of this from near your link http://processingjs.org/articles/jsQuickStart.html#mixingjsandprocessing
I just add e.g.
Thanks.
Note that this requires an external
.ogg
file. I thought you were looking for something like a sound synthesizer, which I believe would require a JavaScript library.Although doing some googling now, it appears you can play sounds from base64 files: https://stackoverflow.com/a/23395136/873165
https://OpenProcessing.org/sketch/385738
https://www.Reddit.com/r/processing/comments/5b85k3/this_a_planetoids_game_i_made_with_sound_without/
Kevin
Indeed. That's what I want. As I said in question title, "Playing a sound from a URL". Sorry I didn't make this clear by repeating it in the body.
Thanks anyway for your link to the embedded solution. Good to know that I can embed the sound in the page.
GoToLoop, thanks for the HTML5 .play()o solution. It works fine here on desktop, but fails on Android tablet with both browsers I tried (inc. Chrome) saying "Fail to execute ... The event is already being dispatched." Same with a minimal program of mine having .play() in draw(), also on openprocessing.org. https://www.openprocessing.org/sketch/499777
Some other openprocessing programs can play sound on Android e.g. https://www.openprocessing.org/sketch/499363 but in setup() - not in draw().