Android ExoPlayer What Does "prepare()" Exactly Do?
Asked Answered
C

1

7

The only difference I notice is that, if I call prepare() before play(), I will see the the process indicator and it pre-loads data in the PlayerView, besides that I can't tell the difference if I just call play() without prepare().

Also the documentation says nothing: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/SimpleExoPlayer.html

public void prepare()

Description copied from interface: Player

Prepares the player.    //<- ???

Specified by:
prepare in interface Player
Cartography answered 30/3, 2021 at 12:45 Comment(4)
prepare tells the player to acquire all the resources required for playbackMarleenmarlen
@Usama Altaf What's the advantages of calling it before play()?Cartography
It starts loading file from the source (filling the buffer). You might not notice it when playing a local file but for remote streams it will reduce initial delay.Beagle
@Beagle That make sense.Cartography
M
0

You can find some clue in the javadoc

This will move the player out of idle state and the player will start loading media and acquire resources needed for playback.

There is also another case where you want to call prepare.

Failed or stopped playbacks can be retried by calling ExoPlayer.prepare Source

Mcroberts answered 24/10, 2023 at 18:35 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.