Today, I am going to show you guys how to add background music in Processing 3.0. Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. One of the aims of Processing is to allow non-programmers to start computer programming aided by visual feedback. As Processing is a fairly simple programming language that uses simplified syntax and a graphics user interface, some of the visual art school in Canada actually uses Processing to teach their students (who has no prior knowledge in programming) how to make things with code in an arts-oriented approach. I have to say that Processing is a very powerful tool and you can do a lot of really interesting things with it. Some of the amazing works by people around the world can be seen here. Pretty much anything you can think of visually, you can do it in Processing. The sky’s the limit. If you haven’t already, install Processing 3.0 before we continue on. Now, we can begin.
Processing code to start with
If you are new to Processing, there are two functions that are very important in Processing. One is setup and another one is draw. Think of setup as an one-time pad. It will only be called/runned once unless you restart the application. Draw is a function that will be consistently called/runned during the application and will continually to be running unless you terminate your program. Think of it as a while loop that does not break. Now, in order to add audio in Processing 3.0. We need to use a library called Sound by The Processing Foundation. Here are the steps to get it up and running.
First, you need to have your Processing software open,
Second, go to Sketch->Import Library->Add Library. Then, a Contribution Manager window should pop up.
Third, in the filter input box, type in “Sound” and select install and wait for a few moments.
And then, once it is installed completely. Close the window and lets add few lines of code to see if it is actually working.
Processing code to see if the Sound is actually working
Just like any other programming language, you need to import the library before you can use it. Here, for simplicity, add your audio/mp3 file within the same folder as your sketch_XXXXXXXX.pde file.
Processing code to add the audio
Now, when you run the application, you should hear your audio playing in the background. Pretty simple hul?! In the future tutorial, I will be teaching you guys how to draw simple things with Processing. Here is the full code to the solution.
Full Processing code to play audio in the background
source code hosted on GitHub
Hopefully this guide has given you the confidence to start building really simple things with Processing. I hope that this tutorial has helped you and thank you for reading!
I’ll try to keep this list current and up to date. If you know of a great resource you’d like to share or notice a broken link, please let us know.