Why the ringtone uri returned by RingtoneManager fails when being set as data source for a Media Player

-1

I am trying to set the data source for Anndroid Media Player. I am using the following code.

Uri alarmUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
// alarm_uri = null

if (alarmUri == null) {
   alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

  // alarm_uri = "content://settings/system/notification_sound"
}

alarmMediaPlayer = new MediaPlayer();
alarmMediaPlayer.setDataSource(this, alarmUri);

While setting data source, it throws the following error:

"setDataSource failed.: status=0x80000000"

When I test the same code on another phone, I get the value "content://media/internal/audio/media/44" for alarm_uri. I feel something wrong with the phone which is creating the problem.

Can someone tell what could be the issue?

android
android-mediaplayer
asked on Stack Overflow Aug 30, 2018 by Prashant • edited Aug 30, 2018 by Prashant

1 Answer

0

Both RingtoneManager.TYPE_NOTIFICATION and RingtoneManager.TYPE_ALARMwere returning invalid value as the URI because alarm and notification were set as none in the device. Once it was set to specific value, it started returning meaningful value.

answered on Stack Overflow Sep 4, 2018 by Prashant

User contributions licensed under CC BY-SA 3.0