We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i'm doing a mute button for my application on android mode. currently i'm using a controlp5 button, the media function found it online somewhere(forgotton where i got it) I can't seem to fully mute it, my code does off it for a while, but while later it will on again. I don't need anything complicated function, Just a normal mute button will do. I'm new in Processing Language, please reply me in simple english term. Thanks
void setup() {
orientation(LANDSCAPE);
imageMode(CENTER);
cp5 = new ControlP5(this);
cp5.addButton("Off")
.setValue(0)
.setPosition(0, 470)
.setSize(250, 250)
;
}
public void Off(int theValue) {
try {
MediaPlayer snd = new MediaPlayer();
AssetManager assets = this.getAssets();
AssetFileDescriptor fd = assets.openFd("");
snd.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
snd.prepare();
snd.start();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
void draw() {
try {
MediaPlayer snd = new MediaPlayer();
AssetManager assets = this.getAssets();
AssetFileDescriptor fd = assets.openFd("");
snd.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
snd.prepare();
snd.start();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Answers
Have you tried using the APWidgets media player? It is easy to use and works really well. Also, you can implement a mute button lowering the volume of your mediaplayer -this is really easy with APWidgets, I don't know with the one you are using.
Here: http://code.google.com/p/apwidgets/
And here is a media player example: http://code.google.com/p/apwidgets/wiki/APMediaPlayer_example