所以我在网上找到了这段代码,但由于某种原因,它不起作用。我的意思是它没有崩溃,但它只是无法播放文件代码:
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("calm1.mp3");//which is in the data folder
mp.setDataSource(afd.getFileDescriptor());
mp.prepare();
}
catch(IOException e) {
println("file did not load"+e);
}
mp.start();
};
void draw() {
};
输出是:
file did not load java.io.FileNotFoundException: calm1.mp3
pssst 我正在使用处理