Processing: how to add background music

I made a small little game in Processing, but I need help. I have mp3 and would like to add it to my application to run it in the background.

Is it possible? Thank you very much.

+4
source share
2 answers

You can use the sound library. Processing already comes with Minim . Look in the file> Examples> Libraries> Minim Audio> LoadFile

import ddf.minim.*; AudioPlayer player; Minim minim;//audio context void setup() { minim = new Minim(this); player = minim.loadFile("file.mp3", 2048); player.play(); } void draw() { } void stop() { player.close(); minim.stop(); super.stop(); } 
+8
source

You can also use the Processing sound library. Go to Sketch> Import Library ...> Add Library ...>

Then find the โ€œsoundโ€ and download the sound library from the โ€œEducation Fundโ€.

 import processing.sound.*; SoundFile file; void setup() { size(640, 360); background(255); // Load a soundfile from the /data folder of the sketch and play it back file = new SoundFile(this, "sample.mp3"); file.play(); } void draw() { } 

The link can be found here: https://processing.org/reference/libraries/sound/index.html

0
source

All Articles