Control content playback


Playback Using TextureView

We give developers the ability to use either TextureView or SurfaceView. However, TextureView should be used only if SurfaceView does not meet your needs. One example is where smooth animations or scrolling of the video surface is required prior to Android N version. In this case, please ensure that SDK_INT is less than 24 (Android N), otherwise use SurfaceView. SurfaceView is a default option and you don't need to make any extra configurations. To use TextureView please see the example below:

// Create a new PlayerConfig using the Builder
PlayerConfig playerConfig = new PlayerConfig.Builder()
     .useTextureView(true)
     .build();

// Load the PlaylistItem into the player
player.load(item);

Playback Rate

float[] playbackRates = new float[] { 0.5f, 1f, 2f };

// To setup custom playback rates
PlayerConfig playerConfig = new PlayerConfig.Builder()
     .playbackRates(PlaybackRateConfig.Factory.createPlaybackRateConfig(playbackRates))
     .build();
        
// To use default playback rates
 PlayerConfig playerConfig = new PlayerConfig.Builder()
     .playbackRates(PlaybackRateConfig.Factory.createPlaybackRateConfig(true))
     .build();
     
getPlayer().setup(playerConfig);

Playback API Methods

MethodDescription
void load(List<PlaylistItem> playlist, AdvertisingBase advertising)
                                                                                                                                          
Loads a new playlist and advertising options into the player.
void load(List<PlaylistItem> playlist)Loads a new playlist into the player.
void load(PlaylistItem playlistItem)Loads media into the player.
PlayerState getState()Returns the player's current playback state
void play()Starts playback.
void pause()Pauses playback.
void stop()Stops the player and unloads the currently playing media file
void seek(double position)Seeks the currently playing media to the specified position, in seconds.
double getPosition()Returns the current playback position in seconds.
double getDuration()Returns the duration of the current media in seconds.
void next()Tells JW Player to immediately play the next playlist item.
void playlistItem(int index)Start playback of the playlist item at the specified index.

Playback Callbacks

CallbackDescription
onPlay(PlayEvent playEvent)
                                                                                                                                          
Fired when the player enters the PLAYING state.

See PlayEvent.
onPause(PauseEvent pauseEvent)Fired when the player enters the PAUSED state.

See PauseEvent.
onBuffer(BufferEvent bufferEvent)Fired when the player enters the BUFFERING state.

See BufferEvent.
onIdle(IdleEvent idleEvent)Fired when the player enters the IDLE state.

See IdleEvent.
onFirstFrame(FirstFrameEvent firstFrameEvent)Fired when playback begins.

See FirstFrameEvent.
onSeek(SeekEvent seekEvent)Fired after a seek has been requested either by scrubbing the controlbar or through the API.

See SeekEvent.
onSeeked(SeekedEvent seekedEvent)Fired after a seek operation has completed.

See SeekedEvent.
onTime(TimeEvent timeEvent)While the player is playing, this event is fired as the playback position gets updated. This may occur as frequently as 10 times per second.

See TimeEvent.
onDisplayClick(DisplayClickEvent displayClickEvent)Fired when the user clicks or taps the video display.

See DisplayClickEvent.


Did this page help you?