We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there,
I'm making a game for my phone but I'm having trouble adding music. I tried using minim but it doesn't work for android. Instead I've used processing sound and while the sound plays find when I run it on my computer, when I try to run in on my phone I get this error message.
FATAL EXCEPTION: Animation Thread
Process: processing.test.generalbargus, PID: 5259
java.lang.UnsatisfiedLinkError: Couldn't load MethClaInterface from loader dalvik.system.PathClassLoader[dexPath=/data/app/processing.test.generalbargus-96.apk,libraryPath=/data/app-lib/processing.test.generalbargus-96]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at processing.sound.MethClaInterface.<clinit>(Unknown Source)
at processing.sound.Engine.<init>(Unknown Source)
at processing.sound.Engine.<init>(Unknown Source)
at processing.sound.Engine$LazyHolder.<clinit>(Unknown Source)
at processing.sound.Engine.start(Unknown Source)
at processing.sound.SoundFile.<init>(Unknown Source)
at processing.test.generalbargus.GeneralBargus.setup(GeneralBargus.java:56)
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:841)
I don't know what this means. Maybe some one else can help?
My code:
import processing.sound.*;
SoundFile file;
int level = 0;
int gameStatus = 0;
int playerReady = 0;
int laserStatus;
int timeCheck;
int timeCheck1;
int interval = 1600;
int intervalForShooting = 500;
int timeCheckLevel;
int laserInt = 5;
int level1 = 10000;
PImage player;
PImage boomButton;
PImage background;
PImage bottom;
PImage enemy;
PImage laser;
float scale = 1;
float laserX= (1800 -25)*scale;
float laserY = (400+40)*scale;
float playerX = 40*scale;
float playerY = 600*scale;
float speed = 9;
float enemyX = 1800*scale;
float enemyY = 400*scale;
boolean laserShoot = false;
boolean loss = false;
void setup() {
file = new SoundFile(this, "spaceinvaders.wav");
file.play();
size(int(1920*scale), int(1080*scale));
orientation(LANDSCAPE);
// PFont serp;
// serp = loadFont("SerpentineDEE-BoldItal-48.vlw");
laser = loadImage("laser.png");
enemy = loadImage("enemy.png");
player = loadImage("player.png");
boomButton = loadImage("boom.png");
background = loadImage("background.png");
bottom = loadImage("bottom.png");
timeCheck = millis();
timeCheck1 = millis();
background(0, 0, 0);
// textFont(serp);
textSize(150*scale);
fill(20, 110, 216);
text("Press Anywhere to Start", width/2 -800*scale, height/2*scale);
//textFont(serp);
textSize(100);
fill(255, 255, 255);
text("Attack on General Bargus!", (width /2 -600)*scale, (height/2 + 200)*scale);
}
void draw() {
//changes the game state from the ready menu and starts the game.
if (playerReady == 0 && mousePressed == true) {
gameStatus = 1;
level = 1;
playerReady = 1;
}
//This code sets up the background, buttons and player sprite
if (gameStatus == 1) {
noStroke();
fill(59, 94, 232);
image(background, 0, 0, width, 790*scale);
fill(11, 167, 3);
fill(100*scale, 100*scale, 100*scale);
image(bottom, 0, 800*scale, width, (280)*scale);
fill(0, 0, 0);
rect(0, 784*scale, width, 16*scale);
fill(255, 255, 255, 150);
triangle(140*scale, 1080*scale, 40*scale, 970*scale, 240*scale, 970*scale);
fill(255, 255, 255, 150);
triangle(140*scale, 820*scale, 40*scale, 940*scale, 240*scale, 940*scale);
image(player, playerX, playerY, 90*scale, 90*scale);
image(boomButton, 1500*scale, 840*scale, 200*scale, 200*scale);
image(enemy, enemyX, enemyY, 100*scale, 100*scale);
image(laser, laserX, laserY, 65, 30);
}
//This code allows for player movement up and down.
if (mousePressed == true && dist(mouseX, mouseY, 140*scale, 880*scale) < 45*scale && playerY > 0 ) {//Jumping
playerY = playerY - speed;
}
if (mousePressed == true && dist(mouseX, mouseY, 140*scale, 1020*scale ) < 45*scale && playerReady == 1 && playerY < 704*scale) {
playerY = playerY + speed;
}
//Code for enemy movement.
int passedTime = millis() - timeCheck; //variable constantly checking how much time has passed.
if (passedTime > interval && gameStatus == 1) { //If the passed time is greater than the interval and gameStatus is 1 then run
laserShoot = true; //boolean laser shoot is true
enemyY = random(0, 690*scale); //change the enemy y coord to a random coord every time
laserY = enemyY +25; //position the laser so it is alligned
timeCheck = millis(); //reset the time check
}
if (passedTime > laserInt && laserShoot == true) { //another timer this time for the laser.
laserX = (laserX - 50)*scale; //moving the laser
}
if (passedTime > interval) {
laserX = enemyX + 25; //everytime the enemy changes position set the laser back to the enemy
}
//Code for losing and winning.
// int passedTimeLevel = millis() - timeCheckLevel;
if (passedTime > level1 && loss == false) {
gameStatus = 0;
background(0, 0, 0);
text("You Won", (width /2 -400)*scale, (height/2)*scale);
}
if (dist((110*scale), ((playerY +44)*scale), (laserX*scale), (laserY+20)*scale) < 50) {
background(0, 0, 0);
text("You Lost", (width /2 -400)*scale, (height/2)*scale);
gameStatus = 0;
loss = true;
}
/*//THIS IS TO TEST THE HITBOXES FOR THE LASER AND PLAYER
//THIS ONE IS FOR TESTING THE PLAYER HIT BOX
if (dist((110*scale), ((playerY +44)*scale), (mouseX), (mouseY)) < 50) {
println("hit");
ellipse(110,playerY+44,50,50);
}*/
//THIS ONE IS FOR TESTING THE LASER HITBOX.
// if(dist((mouseX),(mouseY),(laserX*scale), (laserY+20)*scale) < 50){
// println("hit");
// ellipse(laserX, laserY+20, 50,50);
//}
}//this is the last bracket, do not touch
Answers
@Spicee=== from the error message i guess that there is a problem with a library which cannot be found or loaded; are you sure that your sound lib is compatible with android??? - And why not using the "standard" android mediaPlayer component which runs fine for playing sound files???
@akenaton To be honest I have no idea how to do that. Do you think you could show me how to get a wav file to play on android?
try moving size() to the top of setup() (line 36)
you are trying to load a file and it's possible that the default path hasn't been set up yet (because you're calling it before size())
(we can't run your code because we lack the sound and image files, so the above is largely a guess)
@koogs It's really hard to find a guide for importing music in android mode. I'll try what you suggested, thanks.!
@Spicee: have you verified wethher the sound library can be used with android??? - that is the first thing to do. As for media player see my code (in some cases you have to add mediaPlayer.prepare() in the init method. see the android doc.
@Spicee:: of course you have to find & load the lib apwidgets!!...