I've been trying to use SoundPool to play the default ringtone without success. In the code below
String ringtone = Settings.System.DEFAULT_RINGTONE_URI.getPath();
SoundPool ringPhone = new SoundPool(2, AudioManager.STREAM_RING, 1);
int soundID = ringPhone.load(Settings.System.DEFAULT_RINGTONE_URI.getPath(), 1);
int soundID = ringPhone.load(ringtone, 1);
ringPhone.play(soundID, 0.99f, 0.99f, 1, 0, 1);
I get the message "error loading content /system/ringtone sample 0 not READY". Replacing the URI with a hard path to an existing mp3 file on the sd card yields similar results.
What am I doing wrong? Thanks,
kyle
This option allows you to set the default ringtone to be played when you receive a text message or other notification for which you have enabled sounds, such as an incoming email.
On an Android phone, the process is very similar. Go to Settings and then tap on Sounds and vibration. Tap on Ringtone or Phone Ringtone and choose from the preset choices.
Alexander Graham Bell's first useful ringer was ironically a bell that was struck by a solenoid controlled hammer. Fast forward to the iPhone's original "marimba" ringtone, an audio file of a wooden key struck by a mallet.
You probably don't want to be using the SoundPool for this type of audio playing. SoundPool is usually used to play very small snippets of audio, stored as local files, even smaller than most ringtones. You should consider MediaPlayer instead. The following ought to work very nicely:
MediaPlayer player = MediaPlayer.create(this,
Settings.System.DEFAULT_RINGTONE_URI);
player.start();
Although if you don't have permission to access that ringtone from your application, you could get a FileNotFoundException.
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