Pre-Buffering
Players initialized with RECORDED
content can be buffered ahead of time.
This way an illusion of instantly starting videos can be achieved.
By the time a player is needed (PlayerView
is set and play()
is called) it is likely already in the Paused
state, and playback can start immediately.
This feature’s most obvious use-case is a newsfeed like playback experience,
when video contents are scrolling into the view and need to be started as soon as possible.
Usage
- Create a
Player
instance with an ID. (The ID can be thecontentDescriptors.toString()
value for simplicity, if duplicate contents are not required.) - Initialize the created player with a RECORDED content.
- Call
pause()
on the player. The Player will buffer the content then it will wait. At this stage it is not required to callsetPlayerListener()
,setErrorListener()
andattach()
if the callbacks are not relevant for you. But you are free to do so if you are interested in the callbacks, but make sure you calldetach()
before changing listeners or playerView on the player, and callattach()
again so these changes can take effect. - Later when the player is needed set your listeners and the
playerView
, callattach()
- Call
player.play()
and if it is buffered the playback will start instantly.
Example:
PlayerFactory playerFactory = new PlayerFactory(API_KEY, activity);ContentDescriptor contentDescriptor = new ContentDescriptor(ContentType.RECORDED, 123456L);Player player1 = playerFactory.createPlayer(contentDescriptor.toString());player1.initWithContent(contentDescriptor);player1.pause();//... AT A LATER POINT, WHEN THE PLAYER IS NEEDED:player1.setPlayerListener(playerListener);
Note:
- Only your device capabilities (mostly RAM) limit how many players you can pre-buffer. Keeping too many players can cause an OutOfMemoryError.
- When the players are no longer needed don’t forget to
destroy()
them.