Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing: How to add background music

Tags:

processing

I've made a simple little game in Processing, but need some help. I have an mp3 and would like to add it to my app to run in a loop in the background.

Is this possible? Many thanks.

like image 617
capcom Avatar asked Feb 20 '23 15:02

capcom


1 Answers

You can use a sound library. Processing already comes with Minim included. Have a look in 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();
}
like image 133
George Profenza Avatar answered Mar 02 '23 18:03

George Profenza