The PSDK supports seeking to a specific position (time) in live streams where the stream is either a sliding-window playlist or an event type and in VOD.
You can seek to a particular location in the stream.
Seeking in a live stream is allowed only for DVR.
Valid states are PREPARED, COMPLETE, PAUSED, and PLAYING. Being in a valid state ensures that the media resource has successfully loaded. If the player is not in a valid seekable state, attempting to call the following methods throws an IllegalStateException.
For example, wait for the PSDK to call your PlaybackEventListener.onPrepared callback.
This moves the play head to a different position in the stream. Note that the requested seek position might not coincide with the actual computed position.
void seek(long position) throws IllegalStateException;
This is important because the actual start position after the seek could be different than the requested position. Various rules might apply, including:
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean isFromUser) {
if (isFromUser) {
// Update the seek bar thumb, with the position provided by the user.
setPosition(progress);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
isSeeking = true;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
isSeeking = false;
// Retrieve the playback range.
TimeRange playbackRange = mediaPlayer.getPlaybackRange();
// Make sure to seek inside the playback range.
long seekPosition = Math.min(Math.round(seekBar.getProgress()), playbackRange.getDuration());
// Perform seek.
seek(playbackRange.getBegin() + seekPosition);
}
});
The seek operation is asynchronous, so the PSDK dispatches these events related to seeking:
The media player might readjust the seek position provided by the user. Therefore, check the QOSEventListener.onSeekComplete callback, which returns the adjusted seek position.
QOSEventListener.onOperationFailed passes the appropriate warning. Your application needs to decide how to proceed in this case. For instance, it could try to seek again or it could continue playback from the previous position.