Playing sounds regardless of device volume level

后端 未结 2 481
南方客
南方客 2021-02-04 12:15

So on my 2.3 devices, I can play a sound with SoundPool or MediaPlayer at full volume, even if the device volume is set to 0/mute. It was my understanding that you had to manual

2条回答
  •  别那么骄傲
    2021-02-04 13:12

    An easy and alternative way for playing music from raw folder;

    try {
            String uri = "android.resource://" + getPackageName() + "/" + R.raw.beep;
            //Strign uri = "http://bla-bla-bla.com/bla-bla.wav"
            Uri notification = Uri.parse(uri);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
    

提交回复
热议问题