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;
}
}
}