We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I downloaded the apwidgets library so I can play sounds on my android phone, but it isn't quite working. I can import the library and declare a new APMediaPlayer variable, but if I so much as try to initialize it, it crashes as soon as it launches and I get this error:
FATAL EXCEPTION: Animation Thread
Process: processing.test.android_sound_test, PID: 5490
java.lang.NoSuchMethodError: No virtual method getAssets()Landroid/content/res/AssetManager; in class Lprocessing/core/PApplet; or its super classes (declaration of 'processing.core.PApplet' appears in /data/app/processing.test.android_sound_test-1/base.apk)
at apwidgets.APMediaPlayer.setMediaFile(APMediaPlayer.java:81)
at processing.test.android_sound_test.android_sound_test.setup(android_sound_test.java:28)
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:762)
Here is my code, if it helps. It's basically the example in the wiki:
import apwidgets.*;
APMediaPlayer player;
void setup () {
fullScreen ();
player = new APMediaPlayer(this); //create new APMediaPlayer
player.setMediaFile("Hope you have a good day.mp3"); //set the file (files are in data folder)
player.setLooping(true); //restart playback end reached
player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0
player.start(); //start play back
}
void draw () {
background (0);
}
public void onDestroy() {
super.onDestroy(); //call onDestroy
if (player != null) { //must be checked because or else crash when return from landscape mode
player.release(); //release the player
}
}
Answers
You posted your topic in arduino, but I think you meant Android (Tagging @koogs or @quark)
I don't think apwidgets is compatible with Android. I suggest you check this instead:
https://developer.android.com/guide/topics/media-apps/audio-app/building-an-audio-app.html https://developer.android.com/guide/topics/media/mediaplayer.html
Any available implementation in java can be incorporated in Processing.
You can also explore previous posts in the Android section.
Kf
My bad; actually meant to post in Libraries. Fixed now.
I thought apwidgets was originally meant for Android...? What else would it be for? I looked at those links and it seems a bit unnecessary, but if that's the route I need to go, how would I go about implementing it in Processing? (I'm not too familiar with the bridges between Java, Processing IDE, and Android)
Check these:
https://forum.processing.org/two/search?Search=mediaplayer
https://forum.processing.org/two/discussion/comment/89102/#Comment_89102
You can actually use the cassette lib. It works in Android. I haven't used it recently in the newer Android mode versions but it would be a good starting point.
Kf
Cassette library seems to do the trick after some poking around. Thanks mate :)