Tuesday, 30 September 2014

2nd sketch using 2 audios

This sketch attempts to import 2 mp3 files at the same time by using an array list and display 2 audio players instead of 1

    import ddf.minim.*;
    AudioPlayer [] players = new AudioPlayer[2];
    Minim minim;

    void setup() {
      size(512, 250, P2D);
      minim = new Minim(this);
      players[0] = minim.loadFile("itstime.mp3");
      players[1] = minim.loadFile("Warriors.mp3");
      for (int i=0; i<players.length; i++) {
        players[i].play();
      }
    }

    void draw() {
      background(0);
      displayAudio(players[0], 50, color(0,0,255));
      displayAudio(players[1], 150, color(255,0,0));
    }

    void displayAudio(AudioPlayer player, int playerHeight, color c) {
      stroke(c);
      for(int i=0; i<player.left.size()-1; i++) {
        line(i, playerHeight + player.left.get(i)*50, i+1, playerHeight + player.left.get(i+1)*50);
        line(i, playerHeight + 25 + player.right.get(i)*50, i+1, playerHeight + 25 + player.right.get(i+1)*50);
      }
    }

    void stop() {
      for (int i=0; i<players.length; i++) {
        players[i].close();
      }
      minim.stop();
      super.stop();
    }

No comments:

Post a Comment