Hello i am working on little android app witch has some sounds. I am trying to make a toggle style button to enable/disable the audio. I tried it this way. The audio plays fine oncreate and when i click the button once it goes off like it's supposed to but it won't come back on
boolean volon = true;
player = MediaPlayer.create(this, R.raw.aud);
player.setLooping(true);
player.setVolume(100,100);
player.start();
volumebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (volon) {
player.setVolume(0, 0);
volumebtn.setImageResource(R.drawable.voff);
volon = false;
}else {
player.setVolume(100, 100);
volumebtn.setImageResource(R.drawable.von);
volon = true;
}
}
});
Log cat output:
07-21 15:36:36.363 29651-29651/maantje.com.gambleking I/ViewRootImpl﹕ ViewRoot's Touch Event : ACTION_DOWN
07-21 15:36:36.441 29651-29651/maantje.com.gambleking I/ViewRootImpl﹕ ViewRoot's Touch Event : ACTION_UP
07-21 15:36:36.443 29651-29651/maantje.com.gambleking V/MediaPlayer[Native]﹕ MediaPlayer::setVolume(0.000000, 0.000000)
07-21 15:36:37.220 29651-29651/maantje.com.gambleking I/ViewRootImpl﹕ ViewRoot's Touch Event : ACTION_DOWN
07-21 15:36:37.275 29651-29651/maantje.com.gambleking I/ViewRootImpl﹕ ViewRoot's Touch Event : ACTION_UP
07-21 15:36:37.276 29651-29651/maantje.com.gambleking V/MediaPlayer[Native]﹕ MediaPlayer::setVolume(100.000000, 100.000000)
The logcat confirms the audio is being toggled from 0 to 100 yet i don't hear any audio.
Try using a value between 0.0f and 1.0f