<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with play() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=play%28%29</link>
      <pubDate>Sun, 08 Aug 2021 21:15:06 +0000</pubDate>
         <description>Tagged with play() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedplay%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Play .mp3s in Sequence with onended()?</title>
      <link>https://forum.processing.org/two/discussion/27896/play-mp3s-in-sequence-with-onended</link>
      <pubDate>Tue, 01 May 2018 23:33:27 +0000</pubDate>
      <dc:creator>sammy</dc:creator>
      <guid isPermaLink="false">27896@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
Continuing n00b adventures with p5.sound here. I'm trying to create a shuffle player in the browser.  This code preloads a list of .mp3s called 1.mp3, 2.mp3, etc., up to 5.mp3, and then plays one file chosen with random() on mousePressed().</p>

<p>My questions: how to trigger each randomly selected file from the end of the previous file? How to loop this process, so that one randomly chosen file plays from the end of the previous one, on and on?</p>

<p>I suspect <a rel="nofollow" href="https://p5js.org/reference/#/p5.MediaElement/onended">onended()</a> will help. <a rel="nofollow" href="https://forum.processing.org/two/discussion/comment/55753/#Comment_55753">This thread</a> addresses the use of onended() to trigger messages. I appreciate any clues you can provide! Thanks.</p>

<pre><code>//Create array of .mp3s numbered 1 to 5.
const FOLDER = '1to5/', EXT = '.mp3',
      INDEX_START = 1, INDEX_END = 5,
      INDEX_TOTAL = 1 + INDEX_END - INDEX_START,
      sounds = Array(INDEX_TOTAL);

//Preload those files.
function preload() {
  for (let i = 0; i &lt; INDEX_TOTAL; ++i) {
    sounds[i] = loadSound(FOLDER + (i + INDEX_START) + EXT);
    print("i = " + i);
  }

}

function setup() {
  createCanvas(200, 200);
  textAlign(CENTER);
  fill(100);
  noStroke();
  text("CLICK TO PLAY", width/2, height/2);
}

//Play one randomly chosen file.
function mousePressed() {
    var j = int(random(5));
    print("j = " + j);
    sounds[j].play();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>SoundSaturation</title>
      <link>https://forum.processing.org/two/discussion/27873/soundsaturation</link>
      <pubDate>Sun, 29 Apr 2018 00:02:22 +0000</pubDate>
      <dc:creator>DDv2FF</dc:creator>
      <guid isPermaLink="false">27873@/two/discussions</guid>
      <description><![CDATA[<p>Im using a sound effect to shoot in my game, and the problem is that when I shoot like 45 times the game begins to saturate, and the lag make it unplayable. I checked my code, and the problem is with the sound, without it I can shoot 100 times without problems. What could be the problem ? The sound is 3 seconds long. To play it I have something like this.</p>

<pre><code>let sound;
let Shoots = [];
function preload() { 
sound = loadsound("shootSound.mp3);
}
function setup(){
createCanvas(1000, 650);
}
function draw(){
  for(shoots of Shoots){
   shoots.show();
   shoots.move();  
 }
}
function keyPressed(){
  if(keyCode === 32){
    Shoots.push(new Bullet());
    sound.play();
  }
}
</code></pre>

<p>Is it a common problem ? Or there is something wrong in my game code ? Thankss</p>
]]></description>
   </item>
   <item>
      <title>Trouble Assigning ASCII Values to Jump Points in Audio File</title>
      <link>https://forum.processing.org/two/discussion/27870/trouble-assigning-ascii-values-to-jump-points-in-audio-file</link>
      <pubDate>Sat, 28 Apr 2018 18:17:30 +0000</pubDate>
      <dc:creator>sammy</dc:creator>
      <guid isPermaLink="false">27870@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I am trying to make a simple audio sampler by triggering 1 second segments of a 10 second audio file from the computer keyboard. In the code below, I'm trying to trigger second 1 of the file with the 'a' key, second 2 with the 's' key, and so on.</p>

<p>At the moment, this code doesn't make any sound, though I got the keyTyped() <a rel="nofollow" href="https://p5js.org/reference/#/p5/keyTyped">example</a> to trigger changes in a sketch. Is the problem in my use of <code>song.playMode('restart')</code>? Or should I <code>preload()</code> the sound? Or do I need to assign number ASCII values to the samples?</p>

<p>Thanks for any help!</p>

<pre><code>var song;

function setup(){
  song = loadSound('10sec.mp3');
}

function keyTyped() {
    song.playMode('restart');
    if (keyCode === 'a') {
        song.jump(0, 1);
    } else if (keyCode === 's') {
        song.jump(5, 1);
    } else if (keyCode === 'd') {
        song.jump(2, 1);
    }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can i create a mask from a shape??</title>
      <link>https://forum.processing.org/two/discussion/27757/can-i-create-a-mask-from-a-shape</link>
      <pubDate>Fri, 13 Apr 2018 17:54:32 +0000</pubDate>
      <dc:creator>RafaelAzevedo</dc:creator>
      <guid isPermaLink="false">27757@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>Can i create a mask from a shape (in this case an ellipse) and change background color but keep the mask untouched?
This ellipse would have its size changed according to the screen and i would have a function windowResized()</p>

<p><img src="https://i.imgur.com/qxNRnXB.jpg" alt="image" /></p>

<p>Thanks! :)</p>
]]></description>
   </item>
   <item>
      <title>p5.js sound: Playing back files in sync</title>
      <link>https://forum.processing.org/two/discussion/26197/p5-js-sound-playing-back-files-in-sync</link>
      <pubDate>Wed, 31 Jan 2018 15:47:17 +0000</pubDate>
      <dc:creator>Andreas_Ref</dc:creator>
      <guid isPermaLink="false">26197@/two/discussions</guid>
      <description><![CDATA[<p>Hi</p>

<p>I have a p5js sketch, where I want to play back four individual mp3 tracks in sync. 
I can get them to play, but they are of in terms of sync when I run the sketch. I know that the files themselves are in perfect sync.</p>

<p>Here is my code so far.</p>

<pre><code>var bass, drums, guitar, vox;

function preload() {

bass = loadSound('data/bass.mp3');
drums = loadSound('data/drums.mp3');
guitar = loadSound('data/guitar.mp3');
vox = loadSound('data/vox.mp3');

}

function setup() {
createCanvas(1350, 1045);

bass.play();
drums.play();
guitar.play();
vox.play();
}

function draw() {

}
</code></pre>

<p>Any ideas?</p>
]]></description>
   </item>
   <item>
      <title>Childrens game</title>
      <link>https://forum.processing.org/two/discussion/17859/childrens-game</link>
      <pubDate>Tue, 16 Aug 2016 14:52:56 +0000</pubDate>
      <dc:creator>Yami89</dc:creator>
      <guid isPermaLink="false">17859@/two/discussions</guid>
      <description><![CDATA[<p>Hi I've made this small game, when a letter is pressed its displayed on screen as an image and a sound plays. When I run the code and press a letter it shows the letter and plays the sound, but when I press the letter again it displays the letter but doesn't play the sound. I've tried using .rewind(); and what happens after that it first time I press a letter it plays the sound and displays the letter, and if I press the same letter again it displays the letter and when i release the key it plays the sound :S.</p>

<pre><code>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 ha;
AudioPlayer sh;
AudioPlayer no;
AudioPlayer ra;
AudioPlayer ba;
AudioPlayer lh;

PImage[] letters = new PImage[6];

void setup() {
  size(400, 400);
  background(0);

  minim = new Minim(this);
  ha = minim.loadFile("0.mp3");
  sh = minim.loadFile("1.mp3");
  no = minim.loadFile("2.mp3");
  ra = minim.loadFile("3.mp3");
  ba = minim.loadFile("4.mp3");
  lh = minim.loadFile("5.mp3");

  imageMode(CENTER);

  for (int i = 0; i&lt;letters.length; i++) {
    letters[i] = loadImage(+i+".jpg");
  }
}
void draw() {
  background(0);
  if ((keyPressed == true)&amp;&amp;(key == 'h')) {
    image(letters[0], width/2, height/2, 200, 200);   
    ha.play();
  }
  if ((keyPressed == true)&amp;&amp;(key == 's')) {
    image(letters[1], width/2, height/2, 200, 200);
    sh.play();
  }
  if ((keyPressed == true)&amp;&amp;(key == 'n')) {
    image(letters[2], width/2, height/2, 200, 200);
    no.play();
  }
  if ((keyPressed == true)&amp;&amp;(key == 'r')) {
    image(letters[3], width/2, height/2, 200, 200);
    ra.play();
  }
  if ((keyPressed == true)&amp;&amp;(key == 'b')) {
    image(letters[4], width/2, height/2, 200, 200);
    ba.play();
  }
  if ((keyPressed == true)&amp;&amp;(key == 'l')) {
    image(letters[5], width/2, height/2, 200, 200);
    lh.play();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I make the text to sound?</title>
      <link>https://forum.processing.org/two/discussion/16862/how-can-i-make-the-text-to-sound</link>
      <pubDate>Sat, 28 May 2016 12:28:36 +0000</pubDate>
      <dc:creator>jeremy_wilde</dc:creator>
      <guid isPermaLink="false">16862@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys, I asked this once, but still can't make it works..</p>

<p>I want to make the sentence I make to convert little melody when enterkey pressed.</p>

<p>those are codes</p>

<pre><code>import ddf.minim.*;

Minim minim; 
AudioPlayer c, d, e, f, g, a, b;

PFont font; 
int num = 500; 
char t[] = new char[num]; 
int key_num = 0; 
int text_w_gap = 30; 
int text_h_gap = 50; 
int ypos = 50; 
int xpos = 10; 
int val;

boolean playSong=false;

void setup() { 
  size(500, 400); 
  font = createFont("whiteday10-48.vlw", 14); 
  textFont(font, 32); 
  fill(7,161,8);
  minim = new Minim(this);

  c = minim.loadFile("c.mp3"); 
  d = minim.loadFile("d.mp3"); 
  e = minim.loadFile("e.mp3"); 
  f = minim.loadFile("f.mp3"); 
  g = minim.loadFile("g.mp3"); 
  a = minim.loadFile("a.mp3");
}

void draw() { 
  background(0);

  if (playSong) { 
    for (int i=0; i&lt;key_num; i++) { 
      playNote(t[i]);
    }
  } else
  { 
    for (int i=0; i&lt;key_num; i++) { 
      text(t[i], 
        (xpos+(i*text_w_gap))%width, 
        ypos+( (int(xpos+(i*text_w_gap))) / width * text_h_gap));
    } 
    if (key_num &gt;= num) { 
      key_num = 0;
    }
  }
}

void keyPressed() { 
  if (key!=8) { 
    t[key_num] = key; 
    key_num++;
  } else if (key==RETURN||key==ENTER) { 
    playSong=true;
  } else if (key==8) { 
    key_num--;
  } 
  println("pressed " + int(key) + " " + keyCode);
}

void playNote(int KeyCode) { 
  if (KeyCode==65) { 
    c.play();
  }
  if (KeyCode==66) { 
    d.play();
  }
  if (KeyCode==67) { 
    e.play();
  }
  if (KeyCode==68) { 
    f.play();
  }
  if (KeyCode==69) { 
    g.play();
  }
  if (KeyCode==70) { 
    a.play();
  }
  if (KeyCode==71) {
    b.play();
  }
}
</code></pre>

<p>keycodes are just examples..</p>

<p>I hope someone shows me the functional code that I can understand.
thanks for reading..</p>
]]></description>
   </item>
   <item>
      <title>make a video background which works when a button stays pressed??</title>
      <link>https://forum.processing.org/two/discussion/14465/make-a-video-background-which-works-when-a-button-stays-pressed</link>
      <pubDate>Thu, 14 Jan 2016 23:49:51 +0000</pubDate>
      <dc:creator>CamilleB</dc:creator>
      <guid isPermaLink="false">14465@/two/discussions</guid>
      <description><![CDATA[<p>Hi everybody,</p>

<p>i write you from France so sorry for my english.</p>

<p>Because i want make my portfolios, I try to get a background video which play when the button"space" stays pressed. For few days i have read a lot of articles to find any solutions. Can you try to explain me how can i start this code?</p>

<p>Thanks you so much, this post is my last chance.</p>

<p>Camille :)</p>
]]></description>
   </item>
   <item>
      <title>Random video select code.</title>
      <link>https://forum.processing.org/two/discussion/14377/random-video-select-code</link>
      <pubDate>Sun, 10 Jan 2016 18:17:47 +0000</pubDate>
      <dc:creator>NewTheory</dc:creator>
      <guid isPermaLink="false">14377@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone! I have run into a problem with some code. The code is made so when the user presses A, S or D it will load one of three files assigned for each letter. However, when I press play it comes up with the error: "expecting RPAREN, found ';' syntax error, maybe a missing perenthesis?" for line 32.</p>

<p>does anyone know what the problem is here?
Thanks
:)</p>

<pre><code>import processing.video.*;

String[] one = {
  "ag1.mov", "ag2.mov", "ag3.mov", "am1.mov", "am2.mov", "am3.mov",
  "tran1.mov", "tran2.mov", "tran3.mov"
};


Movie myMovie;

int a = 0;
float md = 0;
float mt = 0;

void setup()
{
  size(400, 400, P2D);
}


void draw()
{

  image(myMovie, 0, 0, width, height);

}

void keyPressed()
{
if (key == 'a' || key == 'A') 
  {
    myMovie = new Movie(this, int(random(1, 3));
    myMovie.play();
  }

  else if (key == 's' || key == 'S')
  {
    myMovie = new Movie(this, int(random(4, 6));
    myMovie.play();
  }

  else if (key == 'd' || key == 'D')
  {
    myMovie = new Movie(this, int(random(7, 9));
    myMovie.play();
  }

  else 
  {
    myMovie.stop();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Input mp3</title>
      <link>https://forum.processing.org/two/discussion/13240/input-mp3</link>
      <pubDate>Sun, 25 Oct 2015 11:56:49 +0000</pubDate>
      <dc:creator>theuselessuser</dc:creator>
      <guid isPermaLink="false">13240@/two/discussions</guid>
      <description><![CDATA[<p>How to input a mp3 file on the code please ?</p>
]]></description>
   </item>
   <item>
      <title>How to play an audio file sequentially.</title>
      <link>https://forum.processing.org/two/discussion/12966/how-to-play-an-audio-file-sequentially</link>
      <pubDate>Mon, 12 Oct 2015 16:35:21 +0000</pubDate>
      <dc:creator>JOSEPH</dc:creator>
      <guid isPermaLink="false">12966@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I'm working on a new piece where a random number generator is connected to sound files of a lady I know screaming the numbers. So when the generator hits 1 it plays her screaming 1 and so on. I'm having trouble because I want the code to be in "void draw", however the audio files play over each other when I place it into that section.</p>

<p>I imagine that I need a piece of code to tell the next audio file to wait until the end of the last before it plays but I am an absolute beginner at coding, so I have no idea how to write it.</p>

<p>I have attached what I have done so far for reference, there is only one audio file in so far as I felt it was best to start simply and then add more audio files as I go.</p>

<pre lang="java">
        import ddf.minim.*;
    
        Minim house;
        AudioPlayer player1;
    
        int christine;
    
        void setup(){
          size(100,100);
        }
    
        void draw(){
      
           house = new Minim(this);
      
          player1 = house.loadFile("u.wav");
      
      
          christine = (int)random(10);
      
          println("christine is "  + christine);
        player1.play();
        player1.isPlaying();
        for (int =
        }
    </pre>
]]></description>
   </item>
   <item>
      <title>minim question</title>
      <link>https://forum.processing.org/two/discussion/12700/minim-question</link>
      <pubDate>Sun, 27 Sep 2015 14:13:45 +0000</pubDate>
      <dc:creator>soulraven</dc:creator>
      <guid isPermaLink="false">12700@/two/discussions</guid>
      <description><![CDATA[<blockquote class="Quote">
  <p>I have this code:</p>
</blockquote>

<pre><code>import ddf.minim.*;

minim minim;
AudioPlayer s1;
AudioPlayer s2;
AudioPlayer s3;
AudioPlayer s4;
AudioPlayer s5;
AudioPlayer s6;
AudioPlayer s7;
AudioPlayer s8;
AudioPlayer s9;
AudioPlayer s10;
AudioPlayer s11;
AudioPlayer s12;
AudioPlayer s13;
AudioPlayer s14;
AudioPlayer s15;
AudioPlayer s16;
AudioPlayer s17;
AudioPlayer s18;
AudioPlayer s19;
AudioPlayer s20;
AudioPlayer s21;

int soundTimer = 0;
int soundInterval = 1000;


void loadSounds() {

  s1 = Minim.loadPlayer("data/your business is appreciated.wav");
  s2 = minim.loadSnippet("data/who's there.wav");
  s3 = minim.AudioPlayer("data/there you are.wav");
  s4 = minim.loadSnippet("data/there you are(2).wav");
  s5 = minim.loadSnippet("data/target lost.wav");
  s6 = minim.loadSnippet("data/target aquired.wav");
  s7 = minim.loadSnippet("data/sleep mode activated.wav");
  s8 = minim.loadSnippet("data/sentry mode activated.wav");
  s9 = minim.loadSnippet("data/no hard feelings.wav");
  s10 = minim.loadSnippet("data/is anyone there.wav");
  s11 = minim.loadSnippet("data/i see you.wav");
  s12 = minim.loadSnippet("data/i dont hate you.wav");
  s13 = minim.loadSnippet("data/i dont blame you.wav");
  s14 = minim.loadSnippet("data/hey its me.wav");
  s15 = minim.loadSnippet("data/hello.wav");
  s16 = minim.loadSnippet("data/gotcha.wav");
  s17 = minim.loadSnippet("data/dispensing product.wav");
  s18 = minim.loadSnippet("data/deploying.wav");
  s19 = minim.loadSnippet("data/could you come over here.wav");
  s20 = minim.loadSnippet("data/are you still there.wav");
  s21 = minim.loadSnippet("data/activated.wav");
}

void playSound(int sound) {
  if(soundEffects) {
    if(sound == 1) {
      s1.rewind();
      s1.play();
    }

    if(sound == 2) {
      s2.rewind();
      s2.play();
    }
    if(sound == 3) {
      s3.rewind();
      s3.play();
    }
    if(sound == 4) {
      s4.rewind();
      s4.play();
    }
    if(sound == 5) {
      s5.rewind();
      s5.play();
    }
    if(sound == 6) {
      s6.rewind();
      s6.play();
    }
    if(sound == 7) {
      s7.rewind();
      s7.play();
    }
    if(sound == 8) {
      s8.rewind();
      s8.play();
    }
    if(sound == 9) {
      s9.rewind();
      s9.play();
    }
    if(sound == 10) {
      s10.rewind();
      s10.play();
    }
    if(sound == 11) {
      s11.rewind();
      s11.play();
    }
    if(sound == 12) {
      s12.rewind();
      s12.play();
    }
    if(sound == 13) {
      s13.rewind();
      s13.play();
    }
    if(sound == 14) {
      s14.rewind();
      s14.play();
    }
    if(sound == 15) {
      s15.rewind();
      s15.play();
    }
    if(sound == 16) {
      s16.rewind();
      s16.play();
    }
    if(sound == 17) {
      s17.rewind();
      s17.play();
    }
    if(sound == 18) {
      s18.rewind();
      s18.play();
    }
    if(sound == 19) {
      s19.rewind();
      s19.play();
    }
    if(sound == 20) {
      s20.rewind();
      s20.play();
    }
    if(sound == 21) {
      s21.rewind();
      s21.play();
    }
  }
}


void randomIdleSound() {

  if(soundEffects) {

    int sound = int(random(1, 11));

    if(sound == 1) {
      s2.rewind();
      s2.play();
    }
    if(sound == 2) {
      s7.rewind();
      s7.play();
    }
    if(sound == 3) {
      s9.rewind();
      s9.play();
    }
    if(sound == 4) {
      s10.rewind();
      s10.play();
    }
    if(sound == 5) {
      s11.rewind();
      s11.play();
    }
    if(sound == 6) {
      s12.rewind();
      s12.play();
    }
    if(sound == 7) {
      s13.rewind();
      s13.play();
    }
    if(sound == 8) {
      s14.rewind();
      s14.play();
    }
    if(sound == 9) {
      s19.rewind();
      s19.play();
    }
    if(sound == 10) {
      s20.rewind();
      s20.play();
    }
  }
}
</code></pre>

<p>But I have problems:<br />
- It doesn't exist class minim line 3 (minim minim;)<br />
- It doesn't recognize the name minim line 32-52 (s1 = Minim.loadPlayer("data/your business is appreciated.wav");)<br />
- It doesn't exist function rewind() line 58,62,66,70,74,78,82... ( s1.rewind();)<br />
- It doesn't exist function play() line 59,63,67,71,75,79,83... (s1.play();)<br /></p>
]]></description>
   </item>
   <item>
      <title>Vídeo</title>
      <link>https://forum.processing.org/two/discussion/12636/video</link>
      <pubDate>Tue, 22 Sep 2015 13:09:08 +0000</pubDate>
      <dc:creator>lviensen</dc:creator>
      <guid isPermaLink="false">12636@/two/discussions</guid>
      <description><![CDATA[<p>Como faço para executar o vídeo toda vez que chamá-lo?</p>

<pre><code> import processing.video.*;
 int v = 1;
 Movie movie;

 void setup() {
       size(640, 360);
       background(0);
       movie = new Movie(this, "transit.mov");

 }

 void movieEvent(Movie m) {
       m.read();
 }

 void draw() {
      if(v==2)
       {
            movie.play();
            image(movie, 0, 0);
       }
       if(v==3)
       {
           movie.play();
           image(movie, 0, 0);
       }
  }

void mousePressed()
{
    print("v: "+v);
    if(v==1)
           print("v: "+v);
    if(v==2)
    {
           print("v: "+v);
    }  
    v++;

 }
</code></pre>
]]></description>
   </item>
   <item>
      <title>sound</title>
      <link>https://forum.processing.org/two/discussion/12450/sound</link>
      <pubDate>Wed, 09 Sep 2015 13:39:10 +0000</pubDate>
      <dc:creator>lviensen</dc:creator>
      <guid isPermaLink="false">12450@/two/discussions</guid>
      <description><![CDATA[<p>Como faço para executar um som, (som.play()), e depois executá-lo de novo?  Executá-lo sempre que eu chame a função que ele está.</p>
]]></description>
   </item>
   <item>
      <title>Processing Piano Help</title>
      <link>https://forum.processing.org/two/discussion/10931/processing-piano-help</link>
      <pubDate>Thu, 21 May 2015 10:22:28 +0000</pubDate>
      <dc:creator>Lulor</dc:creator>
      <guid isPermaLink="false">10931@/two/discussions</guid>
      <description><![CDATA[<p>Hi, so I've just recently learned how to program and I'm trying to make a project that you can play a piano with the keyboard.. I don't know much about processing but whenever i run the code, I can only play each note once and nothing else will work. Could someone please tell me what I'm doing wrong?</p>

<p>Many Thanks</p>

<p>(here's my code)</p>

<p>import ddf.minim.*;
int notes = 0; 
int i = 0;
int x = 25;
int y = 25;
int size = 20;
int xspeed = 1;
int yspeed = 1;
AudioPlayer c;
AudioPlayer csharp;
AudioPlayer d;
AudioPlayer dsharp;
AudioPlayer e;
AudioPlayer esharp;
AudioPlayer f;
AudioPlayer fsharp;
AudioPlayer g;
AudioPlayer gsharp;
AudioPlayer a;
AudioPlayer asharp;
AudioPlayer b;
AudioPlayer bsharp;
AudioPlayer c2;
AudioPlayer csharp2;
AudioPlayer d2;
AudioPlayer dsharp2;
AudioPlayer e2;</p>

<p>Minim minim;//audio context</p>

<p>void setup()
{
  frameRate (10); 
  size (380, 89);
  minim = new Minim(this);
  c = minim.loadFile("c.mp3", 2048);
  csharp = minim.loadFile("csharp.mp3", 2048);
  d = minim.loadFile("d.mp3", 2048);
  dsharp = minim.loadFile ("dsharp.mp3", 2048); 
  e = minim.loadFile ("e.mp3", 2048); 
  f = minim.loadFile ("f.mp3", 2048); 
  fsharp = minim.loadFile ("fsharp.mp3", 2048); 
  g = minim.loadFile ("g.mp3", 2048); 
  gsharp = minim.loadFile ("gsharp.mp3", 2048); 
  a = minim.loadFile ("a.mp3", 2048); 
  asharp = minim.loadFile ("asharp.mp3", 2048); 
  b = minim.loadFile ("b.mp3", 2048); 
  c2 = minim.loadFile ("c2.mp3", 2048); 
  csharp2 = minim.loadFile ("csharp2.mp3", 2048); 
  d2 = minim.loadFile ("d2.mp3", 2048);
}</p>

<p>void draw()
{<br />
  if (notes &lt; 20);
  {
    PImage img;
    img = loadImage("keyboard.jpg");
    size (380, 89);
    background(img);
    if (keyPressed &amp;&amp; key == 'a') //c
    {
      c.play ();
      notes ++;</p>

<pre><code>  text("c", 12, 60);
} else if (keyPressed &amp;&amp; key == 'w') //csharp
{
  notes ++;
  csharp.play ();
} else if (keyPressed &amp;&amp; key == 's')  //d
{
  notes ++;
  d.play ();
} else  if (keyPressed &amp;&amp; key == 'e') //dsharp
{
  notes ++;
  dsharp.play ();
} else  if (keyPressed &amp;&amp; key == 'd') //e
{
  notes ++;
  e.play ();
} else if (keyPressed &amp;&amp; key == 'f') //f
{
  notes ++;
  f.play ();
} else  if (keyPressed &amp;&amp; key == 't') //fsharp
{
  notes ++;
  fsharp.play ();
} else if (keyPressed &amp;&amp; key == 'g') //g
{
  notes ++;
  g.play ();
} else if (keyPressed &amp;&amp; key == 'y') //gsharp
{
  notes ++;
  gsharp.play ();
} else if (keyPressed &amp;&amp; key == 'h') //a
{
  notes ++;
  a.play ();
} else if (keyPressed &amp;&amp; key == 'u') //asharp
{
  notes ++;
  asharp.play ();
} else if (keyPressed &amp;&amp; key == 'j') //b
{
  notes ++;
  b.play ();
} else  if (keyPressed &amp;&amp; key == 'k') //c
{
  notes ++;
  c2.play ();
} else if (keyPressed &amp;&amp; key == 'o') //csharp
{
  notes ++;
  csharp2.play ();
} else if (keyPressed &amp;&amp; key == 'l') //d
{
  notes ++;
  d2.play ();
}
</code></pre>

<p>}
}</p>
]]></description>
   </item>
   <item>
      <title>What is wrong with this?</title>
      <link>https://forum.processing.org/two/discussion/10653/what-is-wrong-with-this</link>
      <pubDate>Tue, 05 May 2015 15:56:19 +0000</pubDate>
      <dc:creator>Space</dc:creator>
      <guid isPermaLink="false">10653@/two/discussions</guid>
      <description><![CDATA[<p>I want to play some sounds when i click the mouse, but I get a NullPointerException error at the line with "second.close();"
I know that this code can be done more easily, but I really need it like this, because I will add other things too. Can someone tell me what's wrong?</p>

<pre><code>import ddf.minim.*;
Minim minim;
AudioPlayer first, second, third, fourth, fifth;
int n=0;

void setup(){
  size(200,200);
  background(0);
  minim = new Minim(this);
  first = minim.loadFile("first.mp3");
  second = minim.loadFile("second.mp3");
  third = minim.loadFile("third.mp3");
  fourth = minim.loadFile("fourth.mp3");
  fifth = minim.loadFile("fifth.mp3");
}

void draw(){
}

void mouseClicked(){
  if(n==0){
    first.play();
  } else {
    first.close();
  }
  if(n==1){
    second.play();
  } else {
    second.close();
  }
  if(n==2){
    third.play();
  } else {
    third.close();
  }
  if(n==3){
    fourth.play();
  } else {
    fourth.close();
  }
  if(n==4){
    fifth.play();
  } else {
    fifth.close();
  }
  n++;  
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>