Loading...
Logo
Processing Forum

Android Audio Help

in Android Processing  •  1 month ago  
APMediaPlayer doesn't seem to work with Android. I'm following a standard procedure but every time it returns the error:

FATAL EXCEPTION: Animation Thread
java.lang.NullPointerException
at processing.test.screenpad2.screenpad2.setup(screenpad2.java:34)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:856)

The same error message came when we tried Minim library as well. Kindly suggest possible solution. We are in dire need.








Copy code
  1. import apwidgets.*;
  2. APMediaPlayer[] player;

  3. int flag, i, t=0, boxsize=200;
  4. PImage[] img = new PImage[12];
  5. void setup()
  6. {
  7.   size(displayWidth, displayHeight);
  8.   smooth();
  9.   //---------------AUDIO-----------------------------
  10.   for (int k=0;k<12;k++) {
  11.     player[k]= new APMediaPlayer(this);
  12.   }
  13.   //----------------LOADING AUDIO FILE--------------
  14.   for (int k=0;k<12;k++) {
  15.     player[k].setMediaFile("Greeting_5.mp3");
  16.   }
  17.   //----------------IMAGE---------------------------
  18.   for (int j=0;j<12;j++) {
  19.     String str =j+".jpg";
  20.     if (str!=null){
  21.       img[j] = loadImage(str);
  22.     println(str);
  23.   }
  24. }
  25. }
  26. //---------------
  27. public void onDestroy() {
  28.   super.onDestroy();
  29.   for (int k=0;k<12;k++) {
  30.     if (player != null) { 
  31.       player[k].release();
  32.     }
  33.   }
  34. }

  35. //----------------

  36. void draw()
  37. {
  38.   background(#00FF4E);
  39.   if (t==0)
  40.   {
  41.     menu0();
  42.     // delay(10500);
  43.   }

  44.   if (flag==0) {
  45.     menu1();
  46.   }
  47.   if (flag==1)
  48.   {
  49.     menu2();
  50.   }
  51.   if (flag==2)
  52.   {
  53.     menu3();
  54.   }
  55. }
  56. //--------------------------------------------------------------
  57. void menu0() {
  58.   player[0].start();
  59.   for (int x = 0; x < 3 ; x++) {
  60.     for (int y=0; y<4; y++) {
  61.       i = x + y*3;
  62.       fill(#FF0808);
  63.       stroke(0);
  64.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
  65.     }
  66.   }
  67. }

  68. //----------------------------------------------------------------
  69. void menu1() {
  70.   if ( player[0]==null) {
  71.     player[1].start();
  72.   }
  73.   for (int x = 0; x < 3 ; x++) {
  74.     for (int y=0; y<4; y++) {
  75.       i = x + y*3;
  76.       fill(#002CFC);
  77.       stroke(0);
  78.       strokeWeight(7);
  79.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
  80.       if (img[i]!= null) {
  81.         imageMode(CENTER);
  82.         image(img[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2);
  83.       }
  84.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
  85.       {
  86.         fill(255, 0, 0, 50);
  87.         noStroke();
  88.         rect(x*boxsize, y*boxsize, boxsize, boxsize);

  89.         if (mousePressed)
  90.         {
  91.           //println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
  92.           if ( 0<mouseX && mouseX<boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
  93.           {
  94.             flag=1;
  95.             println("MENU 2");
  96.           }
  97.           if ( boxsize<mouseX && mouseX<2*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
  98.           {
  99.             flag=2;
  100.             println("MENU 2" );
  101.           }
  102.         }
  103.       }
  104.       //textMode(CENTER);
  105.       fill(255);
  106.       textSize(24);
  107.       text(i, x*boxsize+boxsize/2, y*boxsize+boxsize/2);
  108.       if ( i==9)
  109.       {
  110.         textSize(12);
  111.         text(" GO MENU 2", x*boxsize+boxsize/2, y*boxsize+boxsize/4);
  112.       }
  113.       if ( i==10)
  114.       {
  115.         textSize(12);
  116.         text(" GO MENU 3", x*boxsize+boxsize/2, y*boxsize+boxsize/4);
  117.       }
  118.     }
  119.   }
  120. }
  121. //--------------------------------------------------------------
  122. void menu2() {
  123.   if ( player[1]==null) {
  124.     player[2].start();
  125.   }

  126.   for (int x = 0; x < 3 ; x++) {
  127.     for (int y=0; y<4; y++) {
  128.       i = x + y*3;
  129.       fill(#FF8E03);
  130.       stroke(0);
  131.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
  132.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
  133.       {
  134.         fill(255, 0, 0, 50);
  135.         noStroke();
  136.         rect(x*boxsize, y*boxsize, boxsize, boxsize);
  137.         if (mousePressed)
  138.         {
  139.           // println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
  140.           if ( 2*boxsize<mouseX && mouseX<3*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
  141.           {
  142.             flag=0;
  143.             println("MENU 1");
  144.           }
  145.           if ( boxsize<mouseX && mouseX<2*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
  146.           {
  147.             flag=2;
  148.             println("MENU 2" );
  149.           }
  150.         }
  151.       }
  152.       //textMode(CENTER);
  153.       fill(255);
  154.       textSize(24);
  155.       text(i, x*boxsize+50, y*boxsize+62);
  156.       if ( i==11)
  157.       {
  158.         textSize(12);
  159.         text(" GO MENU 1", x*boxsize+10, y*boxsize+3*boxsize/2);
  160.       }
  161.       if ( i==10)
  162.       {
  163.         textSize(12);
  164.         text(" GO MENU 3", x*boxsize+10, y*boxsize+3*boxsize/2);
  165.       }
  166.     }
  167.   }
  168. }
  169. //----------------------------------------------------------------
  170. void menu3() {
  171.    if ( player[2]==null) {
  172.     player[3].start();
  173.   }
  174.   
  175.   for (int x = 0; x < 3 ; x++) {
  176.     for (int y=0; y<4; y++) {
  177.       i = x + y*3;
  178.       fill(#03CAFF);
  179.       stroke(0);
  180.       rect(x*boxsize, y*boxsize, boxsize, boxsize);
  181.       if ( x*boxsize < mouseX  && mouseX < x*boxsize+boxsize && y*boxsize < mouseY  && mouseY < y*boxsize+boxsize)
  182.       {
  183.         fill(255, 0, 0, 50);
  184.         noStroke();
  185.         rect(x*boxsize, y*boxsize, boxsize, boxsize);
  186.         if (mousePressed)
  187.         {
  188.           // println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
  189.           if ( 2*boxsize<mouseX && mouseX<3*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
  190.           {
  191.             flag=0;
  192.             println("MENU 1");
  193.           }
  194.           if ( 0<mouseX && mouseX<boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
  195.           {
  196.             flag=1;
  197.             println("MENU 2");
  198.           }
  199.         }
  200.       }
  201.       //textMode(CENTER);
  202.       fill(255);
  203.       textSize(24);
  204.       text(i, x*boxsize+50, y*boxsize+62);
  205.       if ( i==11)
  206.       {
  207.         textSize(12);
  208.         text(" GO MENU 1", x*boxsize+10, y*boxsize+3*boxsize/2);
  209.       }
  210.       if ( i==9)
  211.       {
  212.         textSize(12);
  213.         text(" GO MENU 2", x*boxsize+10, y*boxsize+3*boxsize/2);
  214.       }
  215.     }
  216.   }
  217. }

Replies(1)

Csoundo works for Android, if your prepared to learn how to write a bit of Csound code you can do just about anything in terms of audio. Get in contact if your setting it up.  https://github.com/rorywalsh/Csoundo