Have you considered using a MediaPlayer instead of just a straight Ringtone object? You can pass the URI of the Ringtone to the MediaPlayer and have better functionality.
I use the MediaPlayer and create a MediaPlayer.OnCompletionListener to watch for the end of the playing. This doesn't always fire, so I also use a postDelayed to make sure I check for the end also. You can use MediaPlayer.getDuration() and use it to set the time for your postDelayed. Here are some of the APIs I make use of: http://developer.android.com/reference/android/media/MediaPlayer.html http://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener.html http://developer.android.com/reference/android/media/MediaPlayer.html#getDuration%28%29 It's worth upgrading to a more full featured audio player if you want better control. *Note:* I've experienced times where the audio just stops playing without posting back a callback like MediaPlayer.OnCompletionListener<http://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener.html>, MediaPlayer.OnErrorListener<http://developer.android.com/reference/android/media/MediaPlayer.OnErrorListener.html>or MediaPlayer.OnInfoListener<http://developer.android.com/reference/android/media/MediaPlayer.OnInfoListener.html>. Not sure if it was a hardware thing, but I tried everything and there would be times where I'd not get any notification of it stopping. Because of that fact, I do recommend the postDelayed with the duration (plus a slight time padding) of the audio to finish any clean-up after the audio. Steven Studio LFP http://www.studio-lfp.com On Monday, October 24, 2011 7:48:07 AM UTC-5, John Goche wrote: > > > On Mon, Oct 24, 2011 at 1:57 AM, John Goche <johng...@googlemail.com>wrote: > >> >> Well, here is what I am doing now: I acquire a wakelock inside the >> broadcast receiver >> and release it from my activity. The only problem I have is that the >> play() method is >> asynchronous. I would like to be notified when the sound stops playing via >> a callback >> but I see no method for doing so here: >> >> >> http://developer.android.com/reference/android/media/Ringtone.html#play%28%29 >> >> I wonder whether there is a way to detect this without having to poll >> calling isPlaying() >> every second or so. >> > > Well, here is the solution to turning off the wakelock when the sound stops > playing: > > Regards, > > John Goche > > this.ringtone = RingtoneManager.getRingtone(this, uri); > > if (this.ringtone != null) > > this.ringtone.play(); > > // check every five minutes if ringtone is done > // and release wake lock when done playing alarm sound > > final int checkInterval = 5000; > > final Runnable runnable = new Runnable() { > > public void run() { > > System.out.println("I'm running!!!"); > > System.out.println(!AlarmExpiredActivity.this.ringtone.isPlaying()); > System.out.println("OK."); > > if (AlarmExpiredActivity.this.ringtone != null && > !AlarmExpiredActivity.this.ringtone.isPlaying()) > > WakeLockManager.putWakeLock(); > > else > > AlarmExpiredActivity.this.view.postDelayed(this, checkInterval); > > } > > }; > > this.view.postDelayed(runnable, checkInterval); > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en