In this code I merely place the sound in the 'pause' state as I simply
want to unpause with the 'start()'. Doing a start on a paused
MediaPlayer instance does not reload the sound but simply changes
state back to 'Started' which makes it begin playing again thus waking
up the audio system. (see MediaPlayer state diagram at:
http://developer.android.com/reference/android/media/MediaPlayer.html)

Stopping the sound would be wasteful as it places the audio in the
'stopped' state which requires a 'prepare()' call followed by a start
() to get it going again. I simply want it to start playing in order
to wake up the audio system quickly.

On Jun 29, 1:56 pm, Marco Nelissen <marc...@android.com> wrote:
> On Sat, Jun 27, 2009 at 1:08 PM, Baratong<pwalter...@gmail.com> wrote:
>
> > I've found the audio subsystem is a little quirky. It's great if you
> > are playing songs, or video but if you are writing a game that plays
> > short sounds quickly it poses problems. After much work I found a
> > pretty cool solution to one of the annoying problems ofMediaPlayer
> > beingsluggishto play audio.
>
> > The problem is the audio system tends to go to sleep after 3 seconds.
> > When my application tries to play the next sound the phone's audio
> > system wakes up but seems to queue the sound instead of playing it.
> > When my application plays yet another sound -- as long as the sound
> > system hasn't gone back to sleep again -- it plays BOTH sounds at
> > once! This causes unacceptable behavior for any game.
>
> > What I ended up doing was this:
> > 1. Use Audacity to create a 1-second .wav of total silence and add the
> > wave into my manifest as a raw resource referenced in the app as
> > R.raw.silence.
> > 2. On startup, create aMediaPlayerinstance, load the R.raw.silence
> > resource and play in a loop constantly.
>
> > This worked great at keeping the audio system awake, however the phone
> > was now draining the battery quickly whenever the game was loaded.
> > Since Android (and most phones) don't have a great way for the user to
> > terminate a task, this meant if you played the game for a couple of
> > minutes in the morning, the battery would drain at an accelerated rate
> > for the rest of the day! A bit unacceptable.
>
> Indeed. It is unacceptable for an application to not clean up after
> itself. Why did you not simply stop the sound in your application's
> onPause() ?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to