I have an audio visualizer applet I created with processing and minim using fft to analyze the audio. Now I want to feed in songs to the program dynamically with php as the user clicks on a song. I have read about JavaBridge and have it up and running with Tomcat. Would I need to store the song variable values in an xml file and send it over to the .java file? Is that the right approach? And if so, any idea what this would look like? I'm completely new to java and processing. Any help would be incredibly appreciated!

- 168,117
- 40
- 217
- 433

- 769
- 13
- 21
-
3if i may offer you a tip while developing java applets that need to be run in a webpage because they interact with javascript, open the "java control panel" on your computer, then advanced > console>show console. Now a java console will pop up in the browser when you visit a webpage that has an applet. Helpful for debugging and seeing messages/exceptions. ALso, you may need to press the 'x' command often. – goat May 12 '12 at 15:23
2 Answers
feed in songs to the program dynamically with php as the user clicks on a song.
Translations presumed for answer:
- PHP to HTML.
- 'clicks on a song' to 'clicks on a link'.
Since the HTML has links to songs, add an onclick()
handler and in the called function, use JavaScript to call an applet method to load the required song.
So long as the applet is loading the song from the code base or document base, this should be allowable in a sand-boxed applet. Unfortunately doing so from a method called from JS complicates matters slightly, since the security sand-box is tightened even further.
If that is the case here, it will be necessary to wrap the call in a PrivilegedAction
and call it using AccessController.doPrivileged(PrivilegedAction)

- 168,117
- 40
- 217
- 433
-
If you had the javascript invoked method just enqueue the action, and a pre created seperate thread doing the network ops by polling the queue, would that get rid of the need to wrap with PriveledgedAction? – goat May 12 '12 at 15:27
-
yes thank you that should work perfectly! What if the stream is coming from an outside source like Soundcloud? Most Soundcloud songs have a stream_url attribute that links to a 128kbs mp3 stream. Would integration there be possible? – Dante Cullari May 12 '12 at 16:58
-
The applet would require trust (not sand-boxed), unless you can arrange for a proxy at your site - to redirect the source. – Andrew Thompson May 12 '12 at 17:05
-
Just read that Soundcloud's Javascript SDK has a SC.stream method which will prepare a soundManager2 sound object for the passed track. The soundObject object provides all soundManager2 sound properties and methods like play(), stop(), pause(), setVolume(), etc. This should be easy to pass to the applet in the onclick function, no? – Dante Cullari May 12 '12 at 17:31
-
1I actually realized that I could send in a song url to the processing applet as a param, so that when the user clicks on a song, it calls a javascript function that does an ajax call to a php script where I have passed the song url/id. Then I plug the url into an applet param and it gets read inside the applet with String url = this.getParameter("streamurl"); , and it works beautifully. Thanks for all of your help!! – Dante Cullari Jun 06 '12 at 13:50
-
1Also btw, the integration with the 128kbps Soundcloud stream url works great. Minim accepts urls or mp3 files as source, so the "stream_url" provided by Soundcloud's api works great with Minim! – Dante Cullari Jun 06 '12 at 14:00
-
-
Yes! especially when you're just pulling it out of ur a**! You really did help me get to where I was going, thanks again!! – Dante Cullari Jun 06 '12 at 14:17
The fundamental sequence is as follows:
- The user request a .php page in the browser.
- The web server lets PHP write the page. It can write HTML with an applet specified, the applet HTML can be written with parameter with values filled in by PHP.
- The client receives an HTML page, which starts the applet.
So a click on the page cannot be handled by PHP, in a simple direct way. Follow @AndrewThompson in this.

- 107,315
- 7
- 83
- 138