Android MediaPlayer 在 Nougat 中不工作

Android MediaPlayer not working in Nougat

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

}

我已经解决了这个问题。我的代码中有一个愚蠢的错误,这就是为什么 Nougat 中的代码不是 运行 的原因。我刚刚将这段代码 if(flag=="1") 替换为 if(flag.equals("1"))