Methods and Events
  • 22 Aug 2023
  • 3 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Methods and Events

  • Dark
    Light
  • PDF

Article summary

List of supported Methods and events for the player

Method

ParametersNotes
play()
Plays the video or advertisement from a stopped/paused state
pause()
Pauses the video or advertisement from a playing state
destroy()
Destroys the video player, stops any processes, and does any necessary clean-up. (If a player instance is no longer needed, this method must be used
setAdUrladUrl: StringUse this method to show an ad on the video player
goFullScreen()videoID: StringUse this method to move the video player in full-screen mode
removeFullScreen()
Use this method to move the video player in small screen mode - If there is no small-screen player “mode”, this method will remove the full-screen video player from the screen
seekTo()milliseconds: longUse this method to seek current playing video to a specific position
getCurrentTime()
Return current time of video being played
getSource()
Return source of video being played. Returns dictionary - name and id
isMuted()
Return (true/ false) state of volume (mute or not)
getVolumeLevel()
Returns value of volume currently video is played (0~100)
getState()
Returns state of player - Paused, Playing, Playing+Casting, Buffering, Complete, Error, Advertisement
getPlayerVersion()
Returns version of Viewlift player SDK version
getCurrentVideoTimeLeft()
Returns time left of video playback in long
getCurrentVideoDuration()
Returns total video duration in long
hideController()
Hides the controller
showController()
Show the controller
getNetworkInfo()
Returns current network speed info. Returns dictionary - quality & speed
setCaptionsVisibility()captionsVisible: BoolShow/hide closed caption text
setFullscreenButtonOff()disable: BoolDisable the fullscreen button functionality
setNextVideo()videoID (String) - requiredAdd only one video in the queue, next in line to play when the current video is finished
playNextVideo()token (String) - optional; videoID (String) - optionalIf no params are entered it will play right away the next video in the queue if is any with the token entered from setSource method. If token or videoID params are entered it will play right away video based on these params.
playPreviousVideo()token (String) - optionalIf no token is entered it will play right away the previous video in the queue if is any with the token entered from setSource method. If the token is entered it will play right away the previous video with this token.
addVideos()videoIDs (List) - requiredAdd list of ids entered to the queue. (only unique values)
removeVideo()videoID (String) - required
removeAllVideos()
Remove all IDs in the queue except the current video ID
getCurrentPlayList()
Returns a List with all IDs from the queue
getCurrentPlayListPosition()
Returns an int which is the position in the queue of the current video
goLive()
This method works only when is a livestream video. If livestream is in a pause state this method can be called and it resumes the video in livestream state.
setAnimatePlaybackControls Enable()
Enables animation for playback controls whenever they show up or hide
setActivityInstance()
Sets activity instance to enable PIP. Must be called before pipClick
pipClick()
Bring player activity to picture-in-picture mode
setProgressBarSize()width(int) - required height(int) - requiredSets the size of progress bar
setProgressBarIcon()drawable (Drawable) - requiredSets Progress bar drawable
hideError()
Hide player error view

List of supported Events

In order to listen for these events, add this line after your activity class name:implement VLPlayerVideoEventListener class in your activity

implements VLPlayerVideoEventListener

...then implement its methods.

EventParameterDescription
videoStarted()playerTag: StringFired when the video starts playing
videoPaused()

currentTime: long
playerTag: String

Fired when playback is paused
videoResumed()

currentTime: long
playerTag: String

Fired when the video has resumed from a paused state

videoFinished()

currentTime:long
playerTag: String

Fired when the video has finished
videoPlaybackError()

currentTime: long
errorMessage: String
errorCode: String
playerTag: String

Fired when the player has an error playing the video

onFullScreenChange()

currentTime: long
isFullScreen: Bool

Fired when there is a change in player fit - small-screen player, full-screen player

onSeek()

currentTime: long
playerTag: String

Fired when the video is sought from the progress bar

onBuffer()currentTime: long
playerTag: String
When video playback is stalled due to buffering
onApiResponseBodyNull()error: String
playerTag: String
When API returns a null response
onFullscreenButtonClick()playerTag: StringWhen clicked on the fullscreen button


For Ad events

In order to listen for Ad events, implement VLPlayerAdEventListener:

implements VLPlayerAdEventListener
EventParameter
Description
onAdStarted()playerTag: StringFired when the ad starts
onAdPaused()playerTag: StringFired when the ad is paused
onAdResumed()playerTag: StringFired when the ad is resumed
onAdSkipped()playerTag: StringFired when the ad is skipped
onAdFinished()playerTag: StringFired when the ad has finished
onAdTapped()playerTag: StringFired when the ad is tapped
OnAdClicked()playerTag: StringFired when the ad is clicked
onAdError()

error: String
playerTag: String

Fired when an error happens in the ad

List of PlayList events

For PlayList events implement VLPlayerPlayListEventListener:

implements VLPlayerPlayListEventListener

Methods to be implemented are:

EventParameterDescription
onVideoRemove()

playerTag: String
List<String> : videoldPlayList

Fired when a single video ID is removed from the queue

onVideosRemove()

playerTag: String
List<String> : videoldPlayList

Fired when all video IDs are removed from the queue. (except the current video ID)

onVideosAdd()

playerTag: String
List<String> : videoldPlayList

Fired when one or more IDs are added to the queue

onVideoListFinished()playerTag: String

Fired when the current video is finished and there are no more video IDs next in the queue to play

List of Custom Player events

When custom player view is set these events can be used:

implements VLPlayerCustomEventListener

Methods to be implemented are

EventParameterDescription
onTitleTextSet()title: StringFired when the text is available from JSON.
onDurationViewChange()time: long
formattedTime: String
Fired in every second when the video is playing.
onPositionViewChange()time: long
formattedTime: String
Fired in every second when the video is playing.
onCurrentVideoTimeLeft()time: long
formattedTime: String
Fired in every second when the video is playing.

List of PIP Events

EventParameterDescription
onPictureInPictureModeChanged()Boolean:isInPictureInPictureMode, Configuration: newConfigFired when player activity enters or exits the pip mode.



Was this article helpful?

What's Next