Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing default ringtone

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

like image 887
Kyle Banerjee Avatar asked Nov 01 '10 02:11

Kyle Banerjee


People also ask

What does default mean on a ringtone?

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.

How do I change the default ringtone on my Android?

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.

What's the default iPhone ringtone?

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.


1 Answers

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.

like image 131
Dave MacLean Avatar answered Sep 23 '22 01:09

Dave MacLean