I'm making an application that makes a sound when a particulate thing happens,
I made an other Layout that contains a button to stop that sound but the problem is that whenever I say MediaPlayer.stop();
the application on the emulator or even on my mobile says
the application has stopped
The MediaPlayer
were imported from the original class,so what I'm thinking about is making a function that shuts all the sounds whether from my app or from outside of my app,any suggestion will be appreciated ;)
here is my code from the original class(which plays the sound)
public void alarm(){
alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
alarm_player = MediaPlayer.create(this, alarm);
if (Alarm_is_on == false){
alarm_player.setLooping(true);
alarm_player.start();
startActivity(new Intent(MainActivity.this, Cancel_alarm.class));
Alarm_is_on = true;
}
}
and this is the code from the class // where I stop/pause the sound
public void onClick(View button){
MainActivity access = new MainActivity();
access.alarm_player.pause();
}