play audio in processing by pressing button arduin

Hi,
I am a newbie with processing and arduino but i need it to make a project for school.
I linked a button to my arduino and if it is pressed i want it to play an audio file with processing but when it is pressed again i want it to play the next audio file. But i don't have a clue to make it and i don't know where to find a code to do so. Has anyone a suggestion where to search or does anyone know how make a code like that ?
Sorry for my horrible english

The Processing application comes with a number of examples. Use File + Examples + Libraries + Minim (Sound) + LoadFile to see an example of how to load and play an audio file (an mp3, in the example).

Look at File + Examples + Libraries + Serial for several examples of reading and writing serial data.

The Arduino can read and write serial data, too.

You could have the Arduino send a message to the serial port - something like "PlayNextTrack" - when the button is pushed. The Arduino IDE comes with examples, too. Look at File + Examples + Digital + Debounce for how to deal with switches. Look at File + Examples + Stubs for some examples on how to send serial data.

It shouldn't take more than an hour to figure out how to connect a switch, read it's state, and send a serial command, using the examples. That hour should allow plenty of time to get one of the Processing examples modified to read the serial data, and play several songs.

If you get stuck, come on back here. Let us know how it goes, whether you get stuck, or not.

By the way, your English was just fine.

Hey, thanks for your help, it was very useful :slight_smile: . i have copy paste a code together that works pretty well. but i still have the problem that i cannot play multiple tracks, i try to solve it with an array.

this is working code till now but it only plays one track

import ddf.minim.;
import processing.serial.
;

Serial port;
int val = 0;
int oldval = 0;

Minim minim;
AudioPlayer groove;

void setup()
{
minim = new Minim(this);
groove = minim.loadFile("monster-1.mp3", 2048);

println(Serial.list());

port = new Serial(this, Serial.list()[0], 9600);

size(10, 10);

minim = new Minim(this);
}

void draw()
{

println(val);
if (1 < port.available()) {
val = port.read();
}

if (val == 1) groove.play();

}

void stop()
{

groove.close();

minim.stop();

super.stop();
}

But maybe there is a better way to import multiple tracks so if anyone has a suggestion your very welcome. Thanks in advance

Playing multiple tracks is a problem at the Processing end not the arduino end. Therefore I think you might get better advice asking on the Processing forum.
It might be a matter of using a playing library that can handle multiple instances.

You have two initializations for minim. That results in a memory leak, since you can no longer delete the first occurrence.

Are you trying to play two files, one after the other, or two files at the same time?

Hello there, I am so sorry to barge in on your thread, mallebadjas23, but I have a similar question like yours also..

I have basically no knowledge of arduino/processing and am trying to do the same thing - press a button in arduino to play tracks by processing.

Thing is, I do not know how to make them talk to each other.. with all these serial thingies.

I read PaulS's reply - there are no Processing examples that I can open either: I go to File and the 'Examples' is greyed out, therefore un-click-able. No idea why??

And I really don't understand the Serial thing either - I've tried to read up on so many websites but they are filled with jargon which I don't get.

So please please please please if you guys can help me, I will be eternally grateful :frowning: :frowning:

Thanks so much.

Hi, I'm new to Arduino, but am trying to do the exact same thing this thread addresses: playback of multiple audio files from a single button. As in, playing the next track with each press. Has anyone figured out how to do this yet? Thanks a lot.

Just post the code you have so far and show us the place where you have questions...

Is there a better way to go about it then? I'm just starting here, and could easily switch plans.