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.
- import apwidgets.*;
- APMediaPlayer[] player;
- int flag, i, t=0, boxsize=200;
- PImage[] img = new PImage[12];
- void setup()
- {
- size(displayWidth, displayHeight);
- smooth();
- //---------------AUDIO-----------------------------
- for (int k=0;k<12;k++) {
- player[k]= new APMediaPlayer(this);
- }
- //----------------LOADING AUDIO FILE--------------
- for (int k=0;k<12;k++) {
- player[k].setMediaFile("Greeting_5.mp3");
- }
- //----------------IMAGE---------------------------
- for (int j=0;j<12;j++) {
- String str =j+".jpg";
- if (str!=null){
- img[j] = loadImage(str);
- println(str);
- }
- }
- }
- //---------------
- public void onDestroy() {
- super.onDestroy();
- for (int k=0;k<12;k++) {
- if (player != null) {
- player[k].release();
- }
- }
- }
- //----------------
- void draw()
- {
- background(#00FF4E);
- if (t==0)
- {
- menu0();
- // delay(10500);
- }
- if (flag==0) {
- menu1();
- }
- if (flag==1)
- {
- menu2();
- }
- if (flag==2)
- {
- menu3();
- }
- }
- //--------------------------------------------------------------
- void menu0() {
- player[0].start();
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- i = x + y*3;
- fill(#FF0808);
- stroke(0);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- }
- }
- }
- //----------------------------------------------------------------
- void menu1() {
- if ( player[0]==null) {
- player[1].start();
- }
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- i = x + y*3;
- fill(#002CFC);
- stroke(0);
- strokeWeight(7);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (img[i]!= null) {
- imageMode(CENTER);
- image(img[i], x*boxsize+boxsize/2, y*boxsize+boxsize/2);
- }
- if ( x*boxsize < mouseX && mouseX < x*boxsize+boxsize && y*boxsize < mouseY && mouseY < y*boxsize+boxsize)
- {
- fill(255, 0, 0, 50);
- noStroke();
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (mousePressed)
- {
- //println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
- if ( 0<mouseX && mouseX<boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
- {
- flag=1;
- println("MENU 2");
- }
- if ( boxsize<mouseX && mouseX<2*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
- {
- flag=2;
- println("MENU 2" );
- }
- }
- }
- //textMode(CENTER);
- fill(255);
- textSize(24);
- text(i, x*boxsize+boxsize/2, y*boxsize+boxsize/2);
- if ( i==9)
- {
- textSize(12);
- text(" GO MENU 2", x*boxsize+boxsize/2, y*boxsize+boxsize/4);
- }
- if ( i==10)
- {
- textSize(12);
- text(" GO MENU 3", x*boxsize+boxsize/2, y*boxsize+boxsize/4);
- }
- }
- }
- }
- //--------------------------------------------------------------
- void menu2() {
- if ( player[1]==null) {
- player[2].start();
- }
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- i = x + y*3;
- fill(#FF8E03);
- stroke(0);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if ( x*boxsize < mouseX && mouseX < x*boxsize+boxsize && y*boxsize < mouseY && mouseY < y*boxsize+boxsize)
- {
- fill(255, 0, 0, 50);
- noStroke();
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (mousePressed)
- {
- // println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
- if ( 2*boxsize<mouseX && mouseX<3*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
- {
- flag=0;
- println("MENU 1");
- }
- if ( boxsize<mouseX && mouseX<2*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
- {
- flag=2;
- println("MENU 2" );
- }
- }
- }
- //textMode(CENTER);
- fill(255);
- textSize(24);
- text(i, x*boxsize+50, y*boxsize+62);
- if ( i==11)
- {
- textSize(12);
- text(" GO MENU 1", x*boxsize+10, y*boxsize+3*boxsize/2);
- }
- if ( i==10)
- {
- textSize(12);
- text(" GO MENU 3", x*boxsize+10, y*boxsize+3*boxsize/2);
- }
- }
- }
- }
- //----------------------------------------------------------------
- void menu3() {
- if ( player[2]==null) {
- player[3].start();
- }
- for (int x = 0; x < 3 ; x++) {
- for (int y=0; y<4; y++) {
- i = x + y*3;
- fill(#03CAFF);
- stroke(0);
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if ( x*boxsize < mouseX && mouseX < x*boxsize+boxsize && y*boxsize < mouseY && mouseY < y*boxsize+boxsize)
- {
- fill(255, 0, 0, 50);
- noStroke();
- rect(x*boxsize, y*boxsize, boxsize, boxsize);
- if (mousePressed)
- {
- // println(" menu 1 " + "x = " + x + " y= " + y + " i = " + i);
- if ( 2*boxsize<mouseX && mouseX<3*boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
- {
- flag=0;
- println("MENU 1");
- }
- if ( 0<mouseX && mouseX<boxsize && 3*boxsize<mouseY && mouseY<4*boxsize)
- {
- flag=1;
- println("MENU 2");
- }
- }
- }
- //textMode(CENTER);
- fill(255);
- textSize(24);
- text(i, x*boxsize+50, y*boxsize+62);
- if ( i==11)
- {
- textSize(12);
- text(" GO MENU 1", x*boxsize+10, y*boxsize+3*boxsize/2);
- }
- if ( i==9)
- {
- textSize(12);
- text(" GO MENU 2", x*boxsize+10, y*boxsize+3*boxsize/2);
- }
- }
- }
- }
1