Reputation: 758
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?
Upvotes: 1
Views: 660
Reputation: 758
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.
Upvotes: 1
Reputation: 342
//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
Upvotes: 0