Mute Sound when a button is pressed

edited December 2013 in Android Mode

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

Sign In or Register to comment.