Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
MediaPlayer sluggish to play sounds
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Eric M. Burke  
View profile  
 More options Mar 31 2009, 8:35 pm
From: "Eric M. Burke" <burke.e...@gmail.com>
Date: Tue, 31 Mar 2009 17:35:48 -0700 (PDT)
Local: Tues, Mar 31 2009 8:35 pm
Subject: MediaPlayer sluggish to play sounds
I have an Activity that plays a brief OGG "pop" sound effect when
bubbles pop. To keep it fast and to ensure I can play several pops, I
create four MediaPlayer instances. I synchronize access to a pool of
instances, so I can play up to four pops at once. Once a sound
completes, I call seekTo(0) and return the MediaPlayer instance to my
pool.

Here is a rough sketch of the code:

// when the activity resumes...
for (int i=0; i<4; i++) {
  MediaPlayer mp = MediaPlayer.create(context, R.raw.pop);
  mp.setOnCompletionListener(this);
  mp.setVolume(1f, 1f);
  players.add(mp); // put into a pool of available players

}

// when a bubble pops...
MediaPlayer mp = ...get player instance from the pool
if (mp != null) {
  mp.start(); // works! plays the pop sound

}

// implement the OnCompletionListener interface
public void onCompletion(MediaPlayer mp) {
  // seek to the start so I can play the sound fast the next time
  mp.seekTo(0);
  ....return the MediaPlayer to the pool

}

Here is the problem. The pops all work so long as my game is active.
But if I let it sit there for just a few seconds, I see this in the
LogCat console: (on my G1 phone)

AudioHardwareMSM72xx Going to standby

Once this happens, the next several calls to MediaPlayer's start()
method play nothing...but they do cause the audio hardware to wake up
again, so then my sounds eventually (after a few seconds) start
playing again.

My question is, how do I prevent the AudioHardwareMSM72xx from going
to standby mode while my Activity is active?

One hacky idea...I could loop a continuous sound at extremely low
volume level in another MediaPlayer instance to force it to stay
awake. That's not appealing to me.

Ideas?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexey  
View profile  
 More options Apr 1 2009, 1:17 am
From: Alexey <goalstu...@gmail.com>
Date: Tue, 31 Mar 2009 22:17:28 -0700 (PDT)
Local: Wed, Apr 1 2009 1:17 am
Subject: Re: MediaPlayer sluggish to play sounds
I think you have to get WakeLock to avoid your media stop when phone
is going to sleep.
Try to use setWakeMode() method of MediaPlayer or if it won't help for
some reason, you can use PowerManager/WakeLock classes directly.

On 1 апр, 04:35, "Eric M. Burke" <burke.e...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Nelissen  
View profile  
 More options Apr 1 2009, 2:51 pm
From: Marco Nelissen <marc...@android.com>
Date: Wed, 1 Apr 2009 11:51:35 -0700
Local: Wed, Apr 1 2009 2:51 pm
Subject: Re: [android-developers] MediaPlayer sluggish to play sounds

I'm surprised that calling start() has no effect, and that it takes several
seconds for playback to work again.
Do you have the same issue when playing a file in the music player, for
example?

On Tue, Mar 31, 2009 at 5:35 PM, Eric M. Burke <burke.e...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Sparks  
View profile  
 More options Apr 1 2009, 6:14 pm
From: Dave Sparks <davidspa...@android.com>
Date: Wed, 1 Apr 2009 15:14:55 -0700 (PDT)
Local: Wed, Apr 1 2009 6:14 pm
Subject: Re: MediaPlayer sluggish to play sounds
Agreed. It takes about 100 msecs to spin up the audio output once it
goes to standby. You will seeing something like this in the log:

W/AudioFlinger(   35): write blocked for 103 msecs

If it's taking several seconds, there must be something else involved.

On Apr 1, 11:51 am, Marco Nelissen <marc...@android.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »