Maximum number of MediaPlayer instances

2,128 views
Skip to first unread message

Baptiste Gaillard

unread,
Feb 16, 2012, 4:28:36 AM2/16/12
to android-platform
Hi,

On an application we need to play multiple sounds at a time using
PhoneGap.

I've created a simple test and it appears that my Phone only allow to
play 8 sounds time simultaneously.

If I open a 9th sound I encounter the problem "Exceeds maximum number
of OpenCore instances" problem. This problem is described hear :
http://stackoverflow.com/questions/2432191/exceeds-maximum-number-of-opencore-instances-in-android.

Is this number of OpenCore instances limit (8 on my phone) the same on
all Smart Phones and all Android versions ?

We have to write a commercial proposition for this application and we
need to know exactly how many OpenCore instances we can instanciate
(we can force a minimum Android version).

Do you know where can I find details about this number of OpenCore
instances limit ?

Thanks,

Baptiste

Glenn Kasten

unread,
Feb 17, 2012, 10:21:48 AM2/17/12
to android-platform
I'm not familiar with the earlier versions of Android that use
OpenCore, so I can't address your specific question re: OpenCore.
However, I'll answer a related question of "how many audio players can
I use" for more recent versions of Android ...

For android.media.AudioTrack API, there's a theoretical limit of 32
tracks due to a hard-coded limit within the AudioFlinger mixer.
However, the practical limit is likely to be somewhat smaller
depending on CPU model, CPU speed, number of CPU cores, CPU load from
other apps, where there is sample rate conversion, available memory,
etc.

For Android native media based on OpenSL ES, the theoretical limit is
30 (not 32) AudioPlayers in PCM buffer queue mode. But again, the
practical limit is likely to be somewhat less.

For android.media.MediaPlayer API on recent Android that use
Stagefright media framework instead of OpenCore, I'm not aware of any
theoretical limit imposed by MediaPlayer per se when playing audio.
But since it uses an AudioTrack internally, it is subject to the 32
track limit.

If you need a very large number of audio tracks, and find that your
device doesn't have the CPU/memory capacity to handle this, you should
consider writing a custom app-level mixer. A well-written app-level
mixer that is optimized _exactly_ for your needs might fit within your
device's limits.

Summary:
- use AudioTrack directly not MediaPlayer to bypass any OpenCore
limit
(not necessary when using recent Android based on Stagefright)
- measure CPU/memory load
- consider custom app-level mixer

On Feb 16, 1:28 am, Baptiste Gaillard <baptiste.gaill...@gomoob.com>
wrote:
> Hi,
>
> On an application we need to play multiple sounds at a time using
> PhoneGap.
>
> I've created a simple test and it appears that my Phone only allow to
> play 8 sounds time simultaneously.
>
> If I open a 9th sound I encounter the problem "Exceeds maximum number
> of OpenCore instances" problem. This problem is described hear :http://stackoverflow.com/questions/2432191/exceeds-maximum-number-of-....
Reply all
Reply to author
Forward
0 new messages