Audio Player using Processing

15 06 2014

Minim Player

The following code utilizes the Processing IDE and the Minim audio library to play an mp3 file in Processing. This was created as an example for a lab I was running.

  

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer player;
AudioMetaData meta;
void setup()
{
size(1024, 200);
minim = new Minim(this);
//This audio file MUST be in the same folder as the saved Processing (.pde) file
player = minim.loadFile(".mp3", 1024);
meta = player.getMetaData();
print("MetaData = " + meta);
print("\nFile Name: " + meta.fileName());
print("\nLength in milliseconds: " + meta.length());
print("\nTitle: " + meta.title());
}
void draw()
{
background(0);
stroke(0, 255, 0);
//player.play();
/****************************************
For loop below is for a stereo waveform
****************************************/
noFill();
for (int i = 0; i < player.bufferSize () -1; i++)
{
line(i, 50+ player.left.get(i), i+1, 50 + player.left.get(i+1)*50);
line(i, 150+ player.right.get(i), i+1, 150 + player.right.get(i+1)*50);
}
/****************************************
For loop below is for a mono waveform
****************************************/
/*
for(int i = 0; i < player.bufferSize() -1; i++)
{
line(i, 100+player.mix.get(i)*100, i+1, 100+player.mix.get(i+1)*100);
}
*/
}
/***************************************************************************
If mouse button is clicked while audio file is playing then pause the song.
If button is clicked while audio file is paused then resume playing.
****************************************************************************/
void mousePressed()
{
if (player.isPlaying())
player.pause();
else
player.play();//Resumes playing the paused audio file
//player.loop(); //starts audio file over from the start
}


Actions

Information




%d bloggers like this: