Music Player

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

Minim minim;
AudioPlayer player, player2;
AudioMetaData meta;
boolean playing = true;

void setup()
{
  size(600, 500);
  minim = new Minim(this);
  player = minim.loadFile("201-rush-the_camera_eye.mp3");
  meta = player.getMetaData();
  player.play();
}

void draw()
{
  int ys = 15;
  int yi = 25;
  background(0);
  
  // display track info
  int y = ys;
  textSize(20);
  text("Length: " + meta.length()/1000/60 + " min. " + meta.length()/1000%60 + " sec.", 5, y+=yi);
  text("Title: " + meta.title(), 5, y+=yi);
  text("Author: " + meta.author(), 5, y+=yi);
  text("Album: " + meta.album(), 5, y+=yi);
  text("Date: " + meta.date(), 5, y+=yi);
  fill(255, 0, 0);
  
  // draw play/pause button
  if (!playing)
  {
    beginShape();
    vertex(120, 310);
    vertex(180, 325);
    vertex(120, 340);
    endShape(CLOSE);
  } 
  else
  {
    rect(130, 310, 15, 30);
    rect(160, 310, 15, 30);
  }  
  noFill();
  stroke(255, 0, 0);
  rect(100, 300, 100, 50);
  
  // draw progress bar
  float position = map(player.position(), 0, player.length(), 50, width - 60 );
  stroke(255);
  fill(255);
  rect(50, 400, width - 100, 10);
  fill(255, 0, 0);
  rect(position, 400, 10, 10);
}


void mouseReleased()
{
  int position;
  
  // play/pause button has been pressed
  if (mouseX >= 100 && mouseX <= 200 && mouseY >=300 && mouseY <= 350)
  
    // already playing so pause the song
    if (playing)
    {  
      player.pause();
      playing = false;
    } 
    // already paused so start playing the song
    else
    {
      player.play();
      playing = true;
    }
    // jump to appropriate position in the song
    else if (mouseX >= 50 && mouseX <= width - 50 && mouseY >= 400 && mouseY <= 410)
    {
      position = int( map( mouseX, 50, width-50, 0, player.length() ) );
      player.cue( position );
    }
}

// allow minim to clean up when program ends
void stop()
{
  player.close();
  minim.stop();
  super.stop();
}