androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.72k stars 413 forks source link

What is the recommended maximum number of ExoPlayer instances that can be created safely in an Android application? #1880

Open Luke830 opened 1 week ago

Luke830 commented 1 week ago

I'm interested in understanding the maximum recommended limit for creating multiple ExoPlayer instances within an Android application. Given that each instance uses significant resources like memory and decoder capacity, is there a general guideline or known maximum for the number of ExoPlayer instances that can be created safely without affecting app stability across various devices?

The purpose of creating multiple instances of ExoPlayer is to play multiple videos simultaneously, and the only way to do this is to create multiple ExoPlayer instances.

Any insights or recommendations would be greatly appreciated.

marcbaechinger commented 1 week ago

There isn't a good way to find this I'm afraid. It depends on many factors and specifically on the device you are using.

Besides the device, the reason is that an app is sharing codec resources with other apps. It can well be that you can create N codec instanced at time T, but then at T' you can create less instances because another app is using an instance already. It also is related to what media is played, so if you are playing a high quality video already you may be able to get a second instance for a low resolution video but not for another high-res video.

There is [getMaxNumberOfInstances()](https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities#getMaxSupportedInstances()) but its JavaDoc says pretty much what I say above (or vice versa).

The above relates to HW backed (video) codecs that are limited in this way. Audio codecs are in software, so there is probably less of an issue if you want to have many players for audio playback only.