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