1--- 2title: Battery consumption 3--- 4 5## How important is battery consumption due to media playback? ## 6 7Avoiding unnecessary battery consumption is an important aspect of developing a 8good Android application. Media playback can be a major cause of battery drain, 9however its importance for a particular app heavily depends on its usage 10patterns. If an app is only used to play small amounts of media each day, then 11the corresponding battery consumption will only be a small percentage of the 12total consumption of the device. In such it makes sense to prioritize feature 13set and reliability over optimizing for battery when selecting which player to 14use. On the other hand, if an app is often used to play large amounts of media 15each day, then optimizing for battery consumption should be weighted more 16heavily when choosing between a number of viable options. 17 18## How power efficient is ExoPlayer? ## 19 20The diverse nature of the Android device and media content ecosystems means that 21it’s difficult to make widely applicable statements about ExoPlayer’s battery 22consumption, and in particular how it compares with Android’s MediaPlayer API. 23Both absolute and relative performance vary by hardware, Android version and the 24media being played. Hence the information provided below should be treated as 25guidance only. 26 27### Video playback ### 28 29For video playback, our measurements show that ExoPlayer and MediaPlayer draw 30similar amounts of power. The power required for the display and decoding the 31video stream are the same in both cases, and these account for most of the power 32consumed during playback. 33 34Regardless of which media player is used, choosing between `SurfaceView` and 35`TextureView` for output can have a significant impact on power consumption. 36`SurfaceView` is more power efficient, with `TextureView` increasing total power 37draw during video playback by as much as 30% on some devices. `SurfaceView` 38should therefore be preferred where possible. Read more about choosing between 39`SurfaceView` and `TextureView` 40[here]({{ site.baseurl }}/ui-components.html#choosing-a-surface-type). 41 42Below are some power consumption measurements for playing 1080p and 480p video 43on Pixel 2, measured using a [Monsoon power monitor][]. As mentioned above, 44these numbers should not be used to draw general conclusions about power 45consumption across the Android device and media content ecosystems. 46 47| | MediaPlayer | ExoPlayer | 48|-------------------|:-----------:|:----------| 49| SurfaceView 1080p | 202 mAh | 214 mAh | 50| TextureView 1080p | 219 mAh | 221 mAh | 51| SurfaceView 480p | 194 mAh | 207 mAh | 52| TextureView 480p | 212 mAh | 215 mAh | 53 54### Audio playback ### 55 56For short audio playbacks or playbacks when the screen is on, using ExoPlayer 57does not have a significant impact on power compared to using MediaPlayer. 58 59For long playbacks with the screen off, ExoPlayer's audio offload mode needs to 60be used or ExoPlayer may consume significantly more power than MediaPlayer. 61Audio offload allows audio processing to be offloaded from the CPU to a 62dedicated signal processor. It is used by default by MediaPlayer but not 63ExoPlayer. ExoPlayer introduced support for audio offload in 2.12 as an 64experimental feature. See `DefaultRenderersFactory.setEnableAudioOffload` and 65`ExoPlayer.experimentalSetOffloadSchedulingEnabled` for more details on how 66to enable it. 67 68Due to SDK API limitations, ExoPlayer's audio offload mode is only available on 69devices running Android 10 and above. MediaPlayer can use audio offload on 70devices running earlier versions of Android. Whether the increased robustness, 71flexibility and feature set that ExoPlayer provides over MediaPlayer is worth 72the increased power consumption for audio only use cases on older devices is 73something an app developer must decide, taking their requirements and app usage 74patterns into account. 75 76[Monsoon power monitor]: https://www.msoon.com/battery-configuration 77