1

I've created a dialog for selecting a notification sound for an app. I'm querying the notification sounds by getting a cursor from the RingtoneManager:

RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();

I then store the full path to it by concatenating the sound path with the name.

This works fine when I set the selected sound as the notification sound but I can't get media player to play it on selection:

MediaPlayer mp = MediaPlayer.create(this, Uri.parse(path));

This throws an IllegalStateException:

java.lang.IllegalStateException: Unknown URL: content://media/internal/audio/media/Capella

Any ideas on how to get the correct path to a specific notification sound?

Nick
  • 748
  • 1
  • 5
  • 23
  • what value does path variable contain ? – Umair Mar 06 '15 at 09:31
  • @Darkie "content://media/internal/audio/media/Capella" – Nick Mar 06 '15 at 09:35
  • 1
    What I think is that after media/ you should be getting an id of the track not a name because when you access the path it gives you the path of the track with the id not with the name. you should check it ... – Umair Mar 06 '15 at 09:38
  • How do you get the path? –  Mar 06 '15 at 09:41

2 Answers2

1

The correct way to play a sound is to use it's ID and not the name:

cursor.getInt(RingtoneManager.ID_COLUMN_INDEX)

Thanks Darkie for pointing me to the right direction.

Nick
  • 748
  • 1
  • 5
  • 23
0

//in order to play the ringtone, you need to create a new Ringtone with RingtoneManager and pass it to a variable

Ringtone rt = mRingtoneManager.getRingtone(this, uri); rt.play();

Thanks

Sulabh Jain
  • 342
  • 1
  • 9