I have URI of the notification sound, like content://media/internal/audio/media/122, but SoundPool doesn't work with URIs, it works with only apk resources of file paths.
Is there a way to get media file path from URI? I tried Uri.getPath(), which returns /internal/audio/media/122, but this isn't valid file path, and of course SoundPool doesn't work with such patch.
Actually the real path to the notification is /system/media/audio/notifications/allegro.ogg , and I see no way to get it from URI like content://media/internal/audio/media/122
Or should I use MediaPlayer for that? I tested, it works:
MediaPlayer mp = MediaPlayer.create(this, "content://media/internal/audio/media/122");
mp.start();
I'm confused because MediaPlayer seems to be too heavy to just play short notification sound, so I'd prefer to use SoundPool.
Please tell me if I'm wrong about MediaPlayer weight, and suggest correct way to play notification sound by its URI.
Well, I got the easiest way to play audio by URI:
RingtoneManager.getRingtone(this, Uri.parse("content://media/internal/audio/media/122")).play();
I think this is the best what i could achieve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With