class MKPlayer: LifeCycleEvent, MKPlayerApi, UserActionApi, MKPEventHandler, MKPBufferApi, OnMKProgramLoadListener, MKPictureInPictureApi, Any
Fields
Name | Description |
---|---|
val isPictureInPictureAvailable: Boolean
|
Whether Picture-In-Picture (PiP) mode is available. |
val isPictureInPicture: Boolean
|
Whether the view is currently in Picture-In-Picture (PiP) mode. |
Constructors
<init>
constructor(context: Context, rootView: RelativeLayout, configuration: MKPlayerConfiguration)
Pass the Context, RelativeLayout and MKPlayerConfiguration.
Parameters
Name | Description |
---|---|
context: Context
|
application context |
rootView: RelativeLayout
|
root view to which video view has to be added |
configuration: MKPlayerConfiguration
|
MKPlayerConfiguration |
<init>
constructor(context: Context)
The player itself. It implements the interface MKPlayerApi,LifeCycleEvent and UserActionApi which can be used to control the player. It also implements the interface MKPEventHandler which enables adding and removing of event listeners to this player instance. This class represents only the player logic.
Parameters
Name | Description |
---|---|
context: Context
|
application context |
Methods
load
fun load(sourceConfiguration: MKPSourceConfiguration?)
Loads playback content based on source configuration Use this api to load source url with license url or to play from MKP
Parameters
Name | Description |
---|---|
sourceConfiguration: MKPSourceConfiguration?
|
MKPSourceConfiguration defines necessary configurations values to play stream |
ReturnValue
Name | Description |
---|---|
Unit
|
onActivityCreated
fun onActivityCreated()
The method should be called on player when Activity#onCreate is called
ReturnValue
Name | Description |
---|---|
Unit
|
onActivityStarted
fun onActivityStarted()
The method should be called on player when Activity#onStart() is called
ReturnValue
Name | Description |
---|---|
Unit
|
onActivityResumed
fun onActivityResumed()
The method should be called on player when Activity#onResume() is called
ReturnValue
Name | Description |
---|---|
Unit
|
onActivityPaused
fun onActivityPaused()
The method should be called on player when Activity#onPause() is called
ReturnValue
Name | Description |
---|---|
Unit
|
onActivityStopped
fun onActivityStopped()
The method should be called on player when Activity#onStop() is called
ReturnValue
Name | Description |
---|---|
Unit
|
onActivityDestroyed
fun onActivityDestroyed()
This method should be called when Activity#onDestroy() is called
ReturnValue
Name | Description |
---|---|
Unit
|
enterFullscreen
fun enterFullscreen()
The playback will enter to the full screen on user action
ReturnValue
Name | Description |
---|---|
Unit
|
exitFullscreen
fun exitFullscreen()
The playback will leave/exit full screen on user action
ReturnValue
Name | Description |
---|---|
Unit
|
isFullscreen
fun isFullscreen(): Boolean?
This method will return state of the full screen
ReturnValue
Name | Description |
---|---|
Boolean?
|
state of full screen |
preload
fun preload()
Starts preloading the content of the currently loaded source. Applicable only for VoD assets and is not explicitly needed to be called as the player will preload for VoD assets by default.
ReturnValue
Name | Description |
---|---|
Unit
|
unload
fun unload()
This method will unload the loaded source
ReturnValue
Name | Description |
---|---|
Unit
|
destroy
fun destroy()
Destroys the player and releases all allocated resources.
The player instance must not be used after calling this method.
ReturnValue
Name | Description |
---|---|
Unit
|
getConfig
fun getConfig(): MKPlayerConfiguration?
Returns the current player configuration object of this player instance.
ReturnValue
Name | Description |
---|---|
MKPlayerConfiguration?
|
player configuration |
seek
fun seek(var1: Double)
Seeks to the given playback time.
Seeks to the given playback time specified by the parameter time in seconds. For VOD - Must not be greater than the total duration of the video.
To seek/timeshift on a LIVE stream, seekOffset should be either negative or 0.0, calculate seekOffset as in below example:
val SEEKING_OFFSET = 10
//seek back
val seekOffset = mkplayer.getCurrentTime()!! - SEEKING_OFFSET
OR
//seek forward
val seekOffset = mkplayer.getCurrentTime()!! + SEEKING_OFFSET
//check if seekOffset is in seekable range start/end
//based on requirement,
//if seekOffset is out of range for seekForward may goto Live, for seekBackward stay on beginning of buffer.
val seekRange = mkplayer.getSeekableRange()
//check seekOffset is in seekRange i.e. seekOffset in seekRange.start.rangeTo(seekRange.end))
//if seekOffset not in seekRange then can go to 0.0 (i.e.live edge)
mkplayer.seek(seekOffset.minus(seekRange.end))
Note if seekOffset is out of seekable range then position goes to Live.
To seek on a VOD stream, calculate seekOffset as in below example:
val SEEKING_OFFSET = 10
//seek back
val seekOffset = mkplayer.getCurrentTime()!! - SEEKING_OFFSET
OR
//seek forward
val seekOffset = mkplayer.getCurrentTime()!! + SEEKING_OFFSET
mkplayer.seek(seekOffset)
Parameters
Name | Description |
---|---|
var1: Double
|
The time to seek to. |
ReturnValue
Name | Description |
---|---|
Unit
|
getCurrentTime
fun getCurrentTime(): Double?
Returns the current playback time in seconds. For VoD streams the returned time ranges between 0 and the duration of the asset. For live streams a Unix timestamp denoting the current playback position is returned.
ReturnValue
Name | Description |
---|---|
Double?
|
The current playback time in seconds |
getDuration
fun getDuration(): Double?
Returns the total duration in seconds of the current video or INFINITY if it’s a live stream.
ReturnValue
Name | Description |
---|---|
Double?
|
The total duration in seconds of the current video |
isMuted
fun isMuted(): Boolean?
Returns mute state
ReturnValue
Name | Description |
---|---|
Boolean?
|
true if muted |
isPaused
fun isPaused(): Boolean?
Returns Paused state
ReturnValue
Name | Description |
---|---|
Boolean?
|
true if paused |
isPlaying
fun isPlaying(): Boolean?
Returns Playing state
ReturnValue
Name | Description |
---|---|
Boolean?
|
true if playing |
isStalled
fun isStalled(): Boolean?
Returns Stall state
ReturnValue
Name | Description |
---|---|
Boolean?
|
true if stall |
isLive
fun isLive(): Boolean?
Returns playback mode type
ReturnValue
Name | Description |
---|---|
Boolean?
|
true if live |
play
fun play()
The state of the player should be PREPARED, or PAUSED state to start playing. Play the prepared media item by the player. Playback is started from its current time Successful invoke of this method changes state to PLAYING
ReturnValue
Name | Description |
---|---|
Unit
|
pause
fun pause()
The state of the player should be PLAYING Pauses the media item being played Successful invoke of this method changes state to PAUSED
ReturnValue
Name | Description |
---|---|
Unit
|
setVolume
fun setVolume(level: Int)
Sets the volume level on the player. Range 0(mute) to 100 including.
Parameters
Name | Description |
---|---|
level: Int
|
volume level to be set |
ReturnValue
Name | Description |
---|---|
Unit
|
getVolume
fun getVolume(): Int?
This method returns the current volume level set. Range 0(mute) to 100 including.
ReturnValue
Name | Description |
---|---|
Int?
|
the current volume level. |
mute
fun mute()
This method provides an way to mute the volume of the player
ReturnValue
Name | Description |
---|---|
Unit
|
unMute
fun unMute()
This method provides an way to un-mute and set volume level to previous
ReturnValue
Name | Description |
---|---|
Unit
|
addEventListener
fun addEventListener(eventListener: MKEventListener<*>?)
The method to add event listener for receiving callback
Parameters
Name | Description |
---|---|
eventListener: MKEventListener<*>?
|
events to listen |
ReturnValue
Name | Description |
---|---|
Unit
|
removeEventListener
fun removeEventListener(eventListener: MKEventListener<*>?)
The method to remove event listener , should be used during cleanup.
Parameters
Name | Description |
---|---|
eventListener: MKEventListener<*>?
|
listener to deregister event |
ReturnValue
Name | Description |
---|---|
Unit
|
setSubtitle
fun setSubtitle(trackId: String?)
Sets the selected language as sub title
Parameters
Name | Description |
---|---|
trackId: String?
|
id of subtitle to be set |
ReturnValue
Name | Description |
---|---|
Unit
|
getAvailableSubtitleTracks
fun getAvailableSubtitleTracks(): List<Subtitles>?
Queries the available subtitles from the media source
ReturnValue
Name | Description |
---|---|
List<Subtitles>?
|
list of Subtitles |
getCurrentSubtitleTrack
fun getCurrentSubtitleTrack(): Subtitles?
Returns currently used subtitle
ReturnValue
Name | Description |
---|---|
Subtitles?
|
current Subtitle |
setAudio
fun setAudio(trackId: String?)
Sets the selected audio track
Parameters
Name | Description |
---|---|
trackId: String?
|
id of audio |
ReturnValue
Name | Description |
---|---|
Unit
|
getAvailableAudioTracks
fun getAvailableAudioTracks(): List<AudioTrack>?
Gets available audios
ReturnValue
Name | Description |
---|---|
List<AudioTrack>?
|
list of audios |
getCurrentAudioTrack
fun getCurrentAudioTrack(): AudioTrack?
Returns the currently used audio track.
ReturnValue
Name | Description |
---|---|
AudioTrack?
|
current audio |
getPlayerConfiguration
fun getPlayerConfiguration(): MKPlayerConfiguration?
Returns instance of MKPlayerConfiguration
ReturnValue
Name | Description |
---|---|
MKPlayerConfiguration?
|
current player configuration |
getMKSourceConfiguration
fun getMKSourceConfiguration(): MKPSourceConfiguration?
Returns the MKPSourceConfiguration
ReturnValue
Name | Description |
---|---|
MKPSourceConfiguration?
|
current active MKPSourceConfiguration |
setFullScreenHandler
fun setFullScreenHandler(fullscreenHandler: MKPFullscreenHandler)
Parameters
Name | Description |
---|---|
fullscreenHandler: MKPFullscreenHandler
|
ReturnValue
Name | Description |
---|---|
Unit
|
getAvailableVideoQualities
fun getAvailableVideoQualities(): List<VideoQuality>
Gets available video qualities
ReturnValue
Name | Description |
---|---|
List<VideoQuality>
|
list of video qualities |
getAvailableAudioQualities
fun getAvailableAudioQualities(): List<AudioQuality>
Gets available audio qualities
ReturnValue
Name | Description |
---|---|
List<AudioQuality>
|
list of audio qualities |
setVideoQuality
fun setVideoQuality(value: String)
Sets the selected VideoQuality
Parameters
Name | Description |
---|---|
value: String
|
qualityId of selected Video |
ReturnValue
Name | Description |
---|---|
Unit
|
setAudioQuality
fun setAudioQuality(value: String)
Sets the selected AudioQuality
Parameters
Name | Description |
---|---|
value: String
|
qualityId of selected AudioQuality |
ReturnValue
Name | Description |
---|---|
Unit
|
getCurrentVideoQuality
fun getCurrentVideoQuality(): VideoQuality
Returns the currently set VideoQuality
ReturnValue
Name | Description |
---|---|
VideoQuality
|
current video quality of asset being played |
getCurrentAudioQuality
fun getCurrentAudioQuality(): AudioQuality
Returns the currently set AudioQuality
ReturnValue
Name | Description |
---|---|
AudioQuality
|
current audio quality of asset being played |
setTargetLevel
fun setTargetLevel(type: MKBufferType, value: Double)
Sets the target buffer level for the chosen buffer type across all media types.
Parameters
Name | Description |
---|---|
type: MKBufferType
|
|
value: Double
|
|
ReturnValue
Name | Description |
---|---|
Unit
|
getLevel
fun getLevel(btype: MKBufferType, mtype: MKMediaType): MKPBufferLevel
Returns the current and target buffer level for the given buffer type and media type.
Parameters
Name | Description |
---|---|
btype: MKBufferType
|
|
mtype: MKMediaType
|
|
ReturnValue
Name | Description |
---|---|
MKPBufferLevel
|
The current and target buffer level for the given buffer type and media type. |
updateAuthToken
fun updateAuthToken(authToken: String)
Update the previously initialized authToken. Please see MKPBackendConfiguration.
Parameters
Name | Description |
---|---|
authToken: String
|
refreshed STS token |
ReturnValue
Name | Description |
---|---|
Unit
|
onMKProgramStartTimeListener
fun onMKProgramStartTimeListener(programStartTime: String?)
Parameters
Name | Description |
---|---|
programStartTime: String?
|
ReturnValue
Name | Description |
---|---|
Unit
|
getTimeShift
fun getTimeShift(): Double?
Applicable only for LIVE streams.
ReturnValue
Name | Description |
---|---|
Double?
|
current time shift in seconds of the live video. |
setTimeShift
fun setTimeShift(offset: Double)
Shifts the time to the given offset in seconds from the live edge. Has to be within getMaxTimeShift() (which is a negative value) and 0. Only works in live streams. The offset can be positive and is then interpreted as a UNIX timestamp in seconds. The value has to be within the timeShift window, as specified by getMaxTimeShift().
Parameters
Name | Description |
---|---|
offset: Double
|
The amount to shift. |
ReturnValue
Name | Description |
---|---|
Unit
|
getMaxTimeShift
fun getMaxTimeShift(): Double?
Applicable only for LIVE streams.
ReturnValue
Name | Description |
---|---|
Double?
|
the limit in seconds for time shift. Is either negative or 0. |
getVideoBufferLength
fun getVideoBufferLength(): Double?
Returns seconds of already buffered video data.
ReturnValue
Name | Description |
---|---|
Double?
|
the seconds of already buffered video data. |
getAudioBufferLength
fun getAudioBufferLength(): Double?
Returns seconds of already buffered audio data.
ReturnValue
Name | Description |
---|---|
Double?
|
the seconds of already buffered audio data. |
getDroppedVideoFrames
fun getDroppedVideoFrames(): Int?
Returns total number of dropped frames.
ReturnValue
Name | Description |
---|---|
Int?
|
the total number of dropped frames since playback started. |
getCurrentVideoFrameRate
fun getCurrentVideoFrameRate(): Float?
Returns the currently playing video frame rate.
ReturnValue
Name | Description |
---|---|
Float?
|
the currently playing video frame rate as frames per second |
setMaxSelectableVideoBitrate
fun setMaxSelectableVideoBitrate(maxSelectableVideoBitrate: Int)
Sets upper bitrate boundary for video qualities. All qualities above this threshold will not be selected by the ABR logic. These qualities are still available for manual quality selection. For no limitation set to Integer#MAX_VALUE.
Parameters
Name | Description |
---|---|
maxSelectableVideoBitrate: Int
|
video bitrate |
ReturnValue
Name | Description |
---|---|
Unit
|
isStereo
fun isStereo(): Boolean?
Returns true, if stereo is enabled
ReturnValue
Name | Description |
---|---|
Boolean?
|
true, if stereo is enabled |
setStereo
fun setStereo(stereo: Boolean)
If true, stereo mode will be enabled. Applicable to VR content.
Parameters
Name | Description |
---|---|
stereo: Boolean
|
true/false to enable/disable stereo |
ReturnValue
Name | Description |
---|---|
Unit
|
setPlaybackSpeed
fun setPlaybackSpeed(speed: Float)
Sets the playback speed of the player. Fast forward as well as slow motion is supported. Slow motion is used by values between 0 and 1. Fast forward by values greater than 1. Values less or equal zero are ignored.
Parameters
Name | Description |
---|---|
speed: Float
|
playback speed |
ReturnValue
Name | Description |
---|---|
Unit
|
getPlaybackSpeed
fun getPlaybackSpeed(): Float?
Returns the current playback speed of the player. Value 1 is the default playback speed. Values between 0 and 1 refer to slow motion. Values greater than 1 refer to fast forward.
ReturnValue
Name | Description |
---|---|
Float?
|
current playback speed |
getLatency
fun getLatency(): Double?
Low latency settings and to query the current low latency
Returns the current latency.
ReturnValue
Name | Description |
---|---|
Double?
|
the current latency. |
setTargetLatency
fun setTargetLatency(latency: Double)
Low latency settings Sets target latency on the player should try to reach and maintain.
Parameters
Name | Description |
---|---|
latency: Double
|
target latency the player should try to reach and maintain. |
ReturnValue
Name | Description |
---|---|
Unit
|
getTargetLatency
fun getTargetLatency(): Double?
Low latency settings and to query the current target latency
Returns the current target latency.
ReturnValue
Name | Description |
---|---|
Double?
|
the current target latency or -1 if not set. |
setScalingMode
fun setScalingMode(scalingMode: MKPScalingMode)
Sets a new MKPScalingMode.
Parameters
Name | Description |
---|---|
scalingMode: MKPScalingMode
|
Scaling mode value |
ReturnValue
Name | Description |
---|---|
Unit
|
getScalingMode
fun getScalingMode(): MKPScalingMode
Returns the current ScalingMode.
ReturnValue
Name | Description |
---|---|
MKPScalingMode
|
current scaling mode |
getSeekableRange
fun getSeekableRange(): MKPTimeRange
Returns the time range that is currently valid for seeking. For VoD streams, the returned time ranges between 0..duration of the asset. For Live streams a value relative to the playback start..current live position is returned.
ReturnValue
Name | Description |
---|---|
MKPTimeRange
|
MKPTimeRange returns the range, default values are 0.0. |
getPlaybackVideoData
fun getPlaybackVideoData(): VideoQuality
The VideoQuality that is currently being played back or null if no video is currently being played back. The returned quality always represents the actual current video quality, while getCurrentVideoQuality represents what the player is working towards playing (e.g. a new quality can be selected even though it is not being played yet).
ReturnValue
Name | Description |
---|---|
VideoQuality
|
getPlaybackAudioData
fun getPlaybackAudioData(): AudioQuality
The AudioQuality that is currently being played back or null if no audio is currently being played back. The returned quality always represents the actual current audio quality, while getCurrentAudioQuality represents what the player is working towards playing (e.g. a new quality can be selected even though it is not being played yet).
ReturnValue
Name | Description |
---|---|
AudioQuality
|
setPictureInPictureHandler
fun setPictureInPictureHandler(activity: Activity)
Set a interface internally to handle Picture-In-Picture (PiP) mode. Initially, no interface is set to handle PictureInPicture mode actions.
Parameters
Name | Description |
---|---|
activity: Activity
|
instance of Activity class from where the MKPlayer is initialised |
ReturnValue
Name | Description |
---|---|
Unit
|
enterPictureInPicture
fun enterPictureInPicture()
Puts the view into Picture-In-Picture (PiP) mode. Has no effect if isPictureInPictureAvailable is false or if the view is already in PiP mode.
ReturnValue
Name | Description |
---|---|
Unit
|
exitPictureInPicture
fun exitPictureInPicture()
Pulls the view out of Picture-In-Picture (PiP) mode. Has no effect if isPictureInPictureAvailable is false or if the view is currently not in PiP mode.
ReturnValue
Name | Description |
---|---|
Unit
|
onPictureInPictureModeChanged
fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration?)
When using Picture-in-Picture feature, this method has to be called from Activity.
Parameters
Name | Description |
---|---|
isInPictureInPictureMode: Boolean
|
True if the activity is in picture-in-picture mode. |
newConfig: Configuration?
|
The new configuration of the activity with the state |
ReturnValue
Name | Description |
---|---|
Unit
|
The player itself. It implements the interface MKPlayerApi,LifeCycleEvent and UserActionApi which can be used to control the player. It also implements the interface MKPEventHandler which enables adding and removing of event listeners to this player instance. This class represents only the player logic.