I am trying to play media file, this code is working fine for below android N, but its not working for Nougat, please suggest me the best way to play media file on all android version.
private void Beep(String flag)
{
if(flag=="1")
{
if(beepPlay==null)
{
beepPlay= MediaPlayer.create(this, R.raw.alarmsound);
beepPlay.setLooping(true);
beepPlay.setVolume(100,100);
}
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
beepPlay.start();
((Vibrator)getSystemService(VIBRATOR_SERVICE)).vibrate(2000);
}
else
{
if(beepPlay!=null) {
beepPlay.stop();
beepPlay.release();
beepPlay = null;
}
}
}
I've resolved the issue. there was a silly mistake in my code that's why the code was not running in Nougat. I just have replaced this piece of code if(flag=="1") with if(flag.equals("1"))