Hey all!
I have gone through every topic on the subject and tried every example, but I always get the exception message and sound fails to load. I have tried the go-to example:
import android.media.MediaPlayer;
import android.content.res.AssetFileDescriptor;
import android.content.Context;
import android.app.Activity;
/////////////////////////////////////////////////////////
MediaPlayer mp;
Context context;
Activity act;
AssetFileDescriptor afd;
void setup() {
act = this.getActivity();
context = act.getApplicationContext();
try {
mp = new MediaPlayer();
afd = context.getAssets().openFd("MYSOUND.mp3");//which is in the data folder
mp.setDataSource(afd.getFileDescriptor());
mp.prepare();
}
catch(IOException e) {
println("file did not load");
}
mp.start();
};
void draw() {
};
As well as the more complex examples:
import java.io.File;
import java.io.IOException;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.content.res.AssetManager;
import android.content.Context;
import android.app.Activity;
import android.os.Bundle;
import android.app.Application;
/////////////////////////////////////////////////////////
MediaPlayer mp;
public boolean loop = true;
AssetManager am;
Context context;
boolean premiere = false;
Activity act;
AssetFileDescriptor afd;
boolean AppliAndroid = false;
public void setup(){
orientation(PORTRAIT);
background(255,0,0);
fill(255);
textSize(24);
text("SONG IS PLAYING", 200,300);
act = this.getActivity();
context = act.getApplicationContext();
// testClass();
try {
mp = new MediaPlayer();
afd = context.getAssets().openFd("MYSOUND.mp3");//which is in the data folder
mp.setDataSource(afd.getFileDescriptor());
mp.prepare();
} catch(IOException e) {
println("j'arrive pas à préparer");
}
mp.setLooping(loop);
mp.start();
};
public void draw(){
};
Sound just refuses to load. I get the exception message every time.