Added in API level 21

Session


abstract class Session : KeyEvent.Callback
kotlin.Any
   ↳ android.media.tv.TvInputService.Session

Base class for derived classes to implement to provide a TV input session.

Summary

Public constructors
Session(context: Context!)

Creates a new Session.

Public methods
open Unit
layoutSurface(left: Int, top: Int, right: Int, bottom: Int)

Assigns a size and position to the surface passed in onSetSurface.

open Unit

Notifies the advertisement buffer is consumed.

open Unit

Notifies response for advertisement.

open Unit

Informs the app that the AIT (Application Information Table) is updated.

open Unit

Sends an updated list of all audio presentations available from a Next Generation Audio service.

open Unit
notifyAudioPresentationSelected(presentationId: Int, programId: Int)

Sends the presentation and program IDs of the selected audio presentation.

open Unit

Informs the app available speeds for time-shifting.

open Unit

Notifies response for broadcast info.

open Unit
notifyChannelRetuned(channelUri: Uri!)

Informs the application that the current channel is re-tuned for some reason and the session now displays the content from a new channel.

open Unit

Informs the application that the user is allowed to watch the current program content.

open Unit

Informs the application that the current program content is blocked by parent controls.

open Unit

Informs the application that cueing message is available or unavailable.

open Unit

Notifies signal strength.

open Unit

Informs the app that the time shift mode is set or updated.

open Unit

Informs the application that the time shift status is changed.

open Unit
notifyTrackSelected(type: Int, trackId: String!)

Sends the type and ID of a selected track.

open Unit

Sends the list of all audio/video/subtitle tracks.

open Unit
notifyTuned(channelUri: Uri)

Informs the application that this session has been tuned to the given channel.

open Unit
notifyTvMessage(type: Int, data: Bundle)

Sends the raw data from the received TV message as well as the type of message received.

open Unit

Informs the application that the video is now available for watching.

open Unit

Informs the application that the video became unavailable for some reason.

open Unit

Called when an advertisement buffer is ready for playback.

open Unit
onAppPrivateCommand(action: String, data: Bundle!)

Processes a private command sent from the application to the TV input.

open View!

Called when the application requests to create an overlay view.

open Boolean

Implement this method to handle generic motion events on the current input session.

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

Default implementation of KeyEvent.Callback.onKeyDown(): always returns false (doesn't handle the event).

open Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)

Default implementation of KeyEvent.Callback.onKeyLongPress(): always returns false (doesn't handle the event).

open Boolean
onKeyMultiple(keyCode: Int, count: Int, event: KeyEvent!)

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

Default implementation of KeyEvent.Callback.onKeyUp(): always returns false (doesn't handle the event).

open Unit
onOverlayViewSizeChanged(width: Int, height: Int)

Called when the size of the overlay view is changed by the application.

abstract Unit

Called when the session is released.

open Unit

Called when broadcast info is removed.

open Unit

Called when advertisement request is received.

open Unit

Called when broadcast info is requested.

open Boolean
onSelectAudioPresentation(presentationId: Int, programId: Int)

Selects an audio presentation.

open Boolean
onSelectTrack(type: Int, trackId: String?)

Selects a given track.

abstract Unit

Enables or disables the caption.

open Unit

Enables or disables interactive app notification.

abstract Unit

Sets the relative stream volume of the current TV input session.

abstract Boolean
onSetSurface(surface: Surface?)

Called when the application sets the surface.

open Unit
onSetTvMessageEnabled(type: Int, enabled: Boolean)

Called when the application enables or disables the detection of the specified message type.

open Unit
onSurfaceChanged(format: Int, width: Int, height: Int)

Called after any structural changes (format or size) have been made to the surface passed in onSetSurface.

open Long

Returns the current position for time shifting, in milliseconds since the epoch.

open Long

Returns the start position for time shifting, in milliseconds since the epoch.

open Unit

Called when the application requests to pause playback.

open Unit
onTimeShiftPlay(recordedProgramUri: Uri!)

Called when the application requests to play a given recorded TV program.

open Unit

Called when the application requests to resume playback.

open Unit

Called when the application requests to seek to a specified time position.

open Unit

Called when the application sets time shift mode.

open Unit

Called when the application sets playback parameters containing the speed and audio mode.

open Boolean

Implement this method to handle touch screen motion events on the current input session.

open Boolean

Implement this method to handle trackball events on the current input session.

abstract Boolean
onTune(channelUri: Uri!)

Tunes to a given channel.

open Boolean
onTune(channelUri: Uri!, params: Bundle!)

Tunes to a given channel.

open Unit
onTvMessage(type: Int, data: Bundle)

Called when a TV message is received

open Unit
onUnblockContent(unblockedRating: TvContentRating!)

Requests to unblock the content according to the given rating.

open Unit

Enables or disables the overlay view.

Public constructors

Session

Added in API level 21
Session(context: Context!)

Creates a new Session.

Parameters
context Context!: The context of the application

Public methods

layoutSurface

Added in API level 23
open fun layoutSurface(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit

Assigns a size and position to the surface passed in onSetSurface. The position is relative to the overlay view that sits on top of this surface.

Parameters
left Int: Left position in pixels, relative to the overlay view.
top Int: Top position in pixels, relative to the overlay view.
right Int: Right position in pixels, relative to the overlay view.
bottom Int: Bottom position in pixels, relative to the overlay view.

notifyAdBufferConsumed

Added in API level 34
open fun notifyAdBufferConsumed(buffer: AdBuffer): Unit

Notifies the advertisement buffer is consumed.

Parameters
buffer AdBuffer: the AdBuffer that was consumed. This value cannot be null.

notifyAdResponse

Added in API level 33
open fun notifyAdResponse(response: AdResponse): Unit

Notifies response for advertisement.

Parameters
response AdResponse: advertisement response. This value cannot be null.

notifyAitInfoUpdated

Added in API level 33
open fun notifyAitInfoUpdated(aitInfo: AitInfo): Unit

Informs the app that the AIT (Application Information Table) is updated.

This method should also be called when onSetInteractiveAppNotificationEnabled(boolean) is called to send the first AIT info.

Parameters
aitInfo AitInfo: This value cannot be null.

notifyAudioPresentationChanged

Added in API level 34
open fun notifyAudioPresentationChanged(audioPresentations: MutableList<AudioPresentation!>): Unit

Sends an updated list of all audio presentations available from a Next Generation Audio service. This is used by the framework to maintain the audio presentation information for a given track of TvTrackInfo#TYPE_AUDIO, which in turn is used by TvView#getAudioPresentations for the application to retrieve metadata for the current audio track. The TV input service must call this method as soon as the audio track presentation information becomes available or is updated. Note that in a case where a part of the information for the current track is updated, it is not necessary to create a new TvTrackInfo object with a different track ID.

Parameters
audioPresentations MutableList<AudioPresentation!>: A list of audio presentation information pertaining to the selected track. This value cannot be null.

notifyAudioPresentationSelected

Added in API level 34
open fun notifyAudioPresentationSelected(
    presentationId: Int,
    programId: Int
): Unit

Sends the presentation and program IDs of the selected audio presentation. This is used to inform the application that a specific audio presentation is selected. The TV input service must call this method as soon as an audio presentation is selected either by default or in response to a call to onSelectTrack. The selected audio presentation ID for a currently selected audio track is maintained in the framework until the next call to this method even after the entire audio presentation list for the track is updated (but is reset when the session is tuned to a new channel), so care must be taken not to result in an obsolete track audio presentation ID.

Parameters
presentationId Int: The ID of the selected audio presentation for the current track.
programId Int: The ID of the program providing the selected audio presentation.

notifyAvailableSpeeds

Added in API level 34
open fun notifyAvailableSpeeds(speeds: FloatArray): Unit

Informs the app available speeds for time-shifting.

This should be called when time-shifting is enabled.

Parameters
speeds FloatArray: An ordered array of playback speeds, expressed as values relative to the normal playback speed (1.0), at which the current content can be played as a time-shifted broadcast. This is an empty array if the supported playback speeds are unknown or the video/broadcast is not in time shift mode. If currently in time shift mode, this array will normally include at least the values 1.0 (normal speed) and 0.0 (paused). This value cannot be null.

notifyBroadcastInfoResponse

Added in API level 33
open fun notifyBroadcastInfoResponse(response: BroadcastInfoResponse): Unit

Notifies response for broadcast info.

Parameters
response BroadcastInfoResponse: broadcast info response. This value cannot be null.

notifyChannelRetuned

Added in API level 21
open fun notifyChannelRetuned(channelUri: Uri!): Unit

Informs the application that the current channel is re-tuned for some reason and the session now displays the content from a new channel. This is used to handle special cases such as when the current channel becomes unavailable, it is necessary to send the user to a certain channel or the user changes channel in some other way (e.g. by using a dedicated remote).

Parameters
channelUri Uri!: The URI of the new channel.

notifyContentAllowed

Added in API level 21
open fun notifyContentAllowed(): Unit

Informs the application that the user is allowed to watch the current program content.

Each TV input service is required to query the system whether the user is allowed to watch the current program before showing it to the user if the parental controls is enabled (i.e. TvInputManager.isParentalControlsEnabled() returns true). Whether the TV input service should block the content or not is determined by invoking TvInputManager.isRatingBlocked(TvContentRating) with the content rating for the current program. Then the TvInputManager makes a judgment based on the user blocked ratings stored in the secure settings and returns the result. If the rating in question turns out to be allowed by the user, the TV input service must call this method to notify the application that is permitted to show the content.

Each TV input service also needs to continuously listen to any changes made to the parental controls settings by registering a broadcast receiver to receive TvInputManager#ACTION_BLOCKED_RATINGS_CHANGED and TvInputManager#ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED and immediately reevaluate the current program with the new parental controls settings.

notifyContentBlocked

Added in API level 21
open fun notifyContentBlocked(rating: TvContentRating): Unit

Informs the application that the current program content is blocked by parent controls.

Each TV input service is required to query the system whether the user is allowed to watch the current program before showing it to the user if the parental controls is enabled (i.e. TvInputManager.isParentalControlsEnabled() returns true). Whether the TV input service should block the content or not is determined by invoking TvInputManager.isRatingBlocked(TvContentRating) with the content rating for the current program or TvContentRating#UNRATED in case the rating information is missing. Then the TvInputManager makes a judgment based on the user blocked ratings stored in the secure settings and returns the result. If the rating in question turns out to be blocked, the TV input service must immediately block the content and call this method with the content rating of the current program to prompt the PIN verification screen.

Each TV input service also needs to continuously listen to any changes made to the parental controls settings by registering a broadcast receiver to receive TvInputManager#ACTION_BLOCKED_RATINGS_CHANGED and TvInputManager#ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED and immediately reevaluate the current program with the new parental controls settings.

Parameters
rating TvContentRating: The content rating for the current TV program. Can be TvContentRating#UNRATED. This value cannot be null.

notifyCueingMessageAvailability

Added in API level 34
open fun notifyCueingMessageAvailability(available: Boolean): Unit

Informs the application that cueing message is available or unavailable.

The cueing message is used for digital program insertion, based on the standard ANSI/SCTE 35 2019r1.

Parameters
available Boolean: true if cueing message is available; false if it becomes unavailable.

notifySignalStrength

Added in API level 33
open fun notifySignalStrength(strength: Int): Unit

Notifies signal strength.

Parameters
strength Int: Value is android.media.tv.TvInputManager#SIGNAL_STRENGTH_LOST, android.media.tv.TvInputManager#SIGNAL_STRENGTH_WEAK, or android.media.tv.TvInputManager#SIGNAL_STRENGTH_STRONG

notifyTimeShiftStatusChanged

Added in API level 23
open fun notifyTimeShiftStatusChanged(status: Int): Unit

Informs the application that the time shift status is changed.

Prior to calling this method, the application assumes the status TvInputManager#TIME_SHIFT_STATUS_UNKNOWN. Right after the session is created, it is important to invoke the method with the status TvInputManager#TIME_SHIFT_STATUS_AVAILABLE if the implementation does support time shifting, or TvInputManager#TIME_SHIFT_STATUS_UNSUPPORTED otherwise. Failure to notifying the current status change immediately might result in an undesirable behavior in the application such as hiding the play controls.

If the status TvInputManager#TIME_SHIFT_STATUS_AVAILABLE is reported, the application assumes it can pause/resume playback, seek to a specified time position and set playback rate and audio mode. The implementation should override onTimeShiftPause, onTimeShiftResume, onTimeShiftSeekTo, onTimeShiftGetStartPosition, onTimeShiftGetCurrentPosition and onTimeShiftSetPlaybackParams.

Parameters
status Int: The current time shift status. Should be one of the followings. Value is android.media.tv.TvInputManager#TIME_SHIFT_STATUS_UNKNOWN, android.media.tv.TvInputManager#TIME_SHIFT_STATUS_UNSUPPORTED, android.media.tv.TvInputManager#TIME_SHIFT_STATUS_UNAVAILABLE, or android.media.tv.TvInputManager#TIME_SHIFT_STATUS_AVAILABLE

notifyTrackSelected

Added in API level 21
open fun notifyTrackSelected(
    type: Int,
    trackId: String!
): Unit

Sends the type and ID of a selected track. This is used to inform the application that a specific track is selected. The TV input service must call this method as soon as a track is selected either by default or in response to a call to onSelectTrack. The selected track ID for a given type is maintained in the framework until the next call to this method even after the entire track list is updated (but is reset when the session is tuned to a new channel), so care must be taken not to result in an obsolete track ID.

Parameters
type Int: The type of the selected track. The type can be TvTrackInfo#TYPE_AUDIO, TvTrackInfo#TYPE_VIDEO or TvTrackInfo#TYPE_SUBTITLE.
trackId String!: The ID of the selected track.

See Also

notifyTracksChanged

Added in API level 21
open fun notifyTracksChanged(tracks: MutableList<TvTrackInfo!>!): Unit

Sends the list of all audio/video/subtitle tracks. The is used by the framework to maintain the track information for a given session, which in turn is used by TvView#getTracks for the application to retrieve metadata for a given track type. The TV input service must call this method as soon as the track information becomes available or is updated. Note that in a case where a part of the information for a certain track is updated, it is not necessary to create a new TvTrackInfo object with a different track ID.

Parameters
tracks MutableList<TvTrackInfo!>!: A list which includes track information.

notifyTuned

Added in API level 33
open fun notifyTuned(channelUri: Uri): Unit

Informs the application that this session has been tuned to the given channel.

Parameters
channelUri Uri: The URI of the tuned channel. This value cannot be null.

notifyTvMessage

Added in API level 34
open fun notifyTvMessage(
    type: Int,
    data: Bundle
): Unit

Sends the raw data from the received TV message as well as the type of message received.

Parameters
type Int: The of message that was sent, such as TvInputManager#TV_MESSAGE_TYPE_WATERMARK Value is android.media.tv.TvInputManager#TV_MESSAGE_TYPE_WATERMARK, android.media.tv.TvInputManager#TV_MESSAGE_TYPE_CLOSED_CAPTION, or android.media.tv.TvInputManager#TV_MESSAGE_TYPE_OTHER
data Bundle: The raw data of the message. The bundle keys are: TvInputManager#TV_MESSAGE_KEY_STREAM_ID, TvInputManager#TV_MESSAGE_KEY_GROUP_ID, TvInputManager#TV_MESSAGE_KEY_SUBTYPE, TvInputManager#TV_MESSAGE_KEY_RAW_DATA. See TvInputManager#TV_MESSAGE_KEY_SUBTYPE for more information on how to parse this data. This value cannot be null.

notifyVideoAvailable

Added in API level 21
open fun notifyVideoAvailable(): Unit

Informs the application that the video is now available for watching. Video is blocked until this method is called.

The TV input service must call this method as soon as the content rendered onto its surface is ready for viewing. This method must be called each time #onTune is called.

notifyVideoUnavailable

Added in API level 21
open fun notifyVideoUnavailable(reason: Int): Unit

Informs the application that the video became unavailable for some reason. This is primarily used to signal the application to block the screen not to show any intermittent video artifacts.

Parameters
reason Int: The reason why the video became unavailable: Value is android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_UNKNOWN, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_TUNING, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_BUFFERING, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_AUDIO_ONLY, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_NOT_CONNECTED, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_INSUFFICIENT_RESOURCE, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_INSUFFICIENT_OUTPUT_PROTECTION, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_PVR_RECORDING_NOT_ALLOWED, android.media.tv.TvInputManager.VIDEO_UNAVAILABLE_REASON_CAS_NO_LICENSE, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_LICENSE_EXPIRED, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_NEED_ACTIVATION, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_NEED_PAIRING, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_NO_CARD, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_CARD_MUTE, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_CARD_INVALID, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_BLACKOUT, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_REBOOTING, android.media.tv.TvInputManager#VIDEO_UNAVAILABLE_REASON_CAS_UNKNOWN, or android.media.tv.TvInputManager.VIDEO_UNAVAILABLE_REASON_STOPPED

onAdBufferReady

Added in API level 34
open fun onAdBufferReady(buffer: AdBuffer): Unit

Called when an advertisement buffer is ready for playback.

Parameters
buffer AdBuffer: The AdBuffer that became ready for playback. This value cannot be null.

onAppPrivateCommand

Added in API level 24
open fun onAppPrivateCommand(
    action: String,
    data: Bundle!
): Unit

Processes a private command sent from the application to the TV input. This can be used to provide domain-specific features that are only known between certain TV inputs and their clients.

Parameters
action String: Name of the command to be performed. This must be a scoped name, i.e. prefixed with a package name you own, so that different developers will not create conflicting commands. This value cannot be null.
data Bundle!: Any data to include with the command.

onCreateOverlayView

Added in API level 21
open fun onCreateOverlayView(): View!

Called when the application requests to create an overlay view. Each session implementation can override this method and return its own view.

Return
View! a view attached to the overlay window

onGenericMotionEvent

Added in API level 21
open fun onGenericMotionEvent(event: MotionEvent!): Boolean

Implement this method to handle generic motion events on the current input session.

Parameters
event MotionEvent!: The motion event being received.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyDown

Added in API level 21
open fun onKeyDown(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Default implementation of KeyEvent.Callback.onKeyDown(): always returns false (doesn't handle the event).

Override this to intercept key down events before they are processed by the application. If you return true, the application will not process the event itself. If you return false, the normal application processing will occur as if the TV input had not seen the event at all.

Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyLongPress

Added in API level 21
open fun onKeyLongPress(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Default implementation of KeyEvent.Callback.onKeyLongPress(): always returns false (doesn't handle the event).

Override this to intercept key long press events before they are processed by the application. If you return true, the application will not process the event itself. If you return false, the normal application processing will occur as if the TV input had not seen the event at all.

Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyMultiple

Added in API level 21
open fun onKeyMultiple(
    keyCode: Int,
    count: Int,
    event: KeyEvent!
): Boolean

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

Override this to intercept special key multiple events before they are processed by the application. If you return true, the application will not itself process the event. If you return false, the normal application processing will occur as if the TV input had not seen the event at all.

Parameters
keyCode Int: The value in event.getKeyCode().
count Int: The number of times the action was made.
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

Added in API level 21
open fun onKeyUp(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Default implementation of KeyEvent.Callback.onKeyUp(): always returns false (doesn't handle the event).

Override this to intercept key up events before they are processed by the application. If you return true, the application will not itself process the event. If you return false, the normal application processing will occur as if the TV input had not seen the event at all.

Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onOverlayViewSizeChanged

Added in API level 23
open fun onOverlayViewSizeChanged(
    width: Int,
    height: Int
): Unit

Called when the size of the overlay view is changed by the application.

This is always called at least once when the session is created regardless of whether the overlay view is enabled or not. The overlay view size is the same as the containing TvView. Note that the size of the underlying surface can be different if the surface was changed by calling layoutSurface.

Parameters
width Int: The width of the overlay view.
height Int: The height of the overlay view.

onRelease

Added in API level 21
abstract fun onRelease(): Unit

Called when the session is released.

onRemoveBroadcastInfo

Added in API level 33
open fun onRemoveBroadcastInfo(requestId: Int): Unit

Called when broadcast info is removed.

onRequestAd

Added in API level 33
open fun onRequestAd(request: AdRequest): Unit

Called when advertisement request is received.

Parameters
request AdRequest: advertisement request received This value cannot be null.

onRequestBroadcastInfo

Added in API level 33
open fun onRequestBroadcastInfo(request: BroadcastInfoRequest): Unit

Called when broadcast info is requested.

Parameters
request BroadcastInfoRequest: broadcast info request This value cannot be null.

onSelectAudioPresentation

Added in API level 34
open fun onSelectAudioPresentation(
    presentationId: Int,
    programId: Int
): Boolean

Selects an audio presentation.

On successfully selecting the audio presentation, notifyAudioPresentationSelected is invoked to provide updated information about the selected audio presentation to applications.

Parameters
presentationId Int: The ID of the audio presentation to select.
programId Int: The ID of the program providing the selected audio presentation.
Return
Boolean true if the audio presentation selection was successful, false otherwise.

onSelectTrack

Added in API level 21
open fun onSelectTrack(
    type: Int,
    trackId: String?
): Boolean

Selects a given track.

If this is done successfully, the implementation should call notifyTrackSelected to help applications maintain the up-to-date list of the selected tracks.

Parameters
trackId String?: The ID of the track to select. null means to unselect the current track for a given type.
type Int: The type of the track to select. The type can be TvTrackInfo#TYPE_AUDIO, TvTrackInfo#TYPE_VIDEO or TvTrackInfo#TYPE_SUBTITLE.
Return
Boolean true if the track selection was successful, false otherwise.

onSetCaptionEnabled

Added in API level 21
abstract fun onSetCaptionEnabled(enabled: Boolean): Unit

Enables or disables the caption.

The locale for the user's preferred captioning language can be obtained by calling CaptioningManager.getLocale().

Parameters
enabled Boolean: true to enable, false to disable.

onSetInteractiveAppNotificationEnabled

Added in API level 33
open fun onSetInteractiveAppNotificationEnabled(enabled: Boolean): Unit

Enables or disables interactive app notification.

This method enables or disables the event detection from the corresponding TV input. When it's enabled, the TV input service detects events related to interactive app, such as AIT (Application Information Table) and sends to TvView or the linked TV interactive app service.

Parameters
enabled Boolean: true to enable, false to disable.

onSetStreamVolume

Added in API level 21
abstract fun onSetStreamVolume(volume: Float): Unit

Sets the relative stream volume of the current TV input session.

The implementation should honor this request in order to handle audio focus changes or mute the current session when multiple sessions, possibly from different inputs are active. If the method has not yet been called, the implementation should assume the default value of 1.0f.

Parameters
volume Float: A volume value between 0.0f to 1.0f. Value is between 0.0 and 1.0 inclusive

onSetSurface

Added in API level 21
abstract fun onSetSurface(surface: Surface?): Boolean

Called when the application sets the surface.

The TV input service should render video onto the given surface. When called with null, the input service should immediately free any references to the currently set surface and stop using it.

Parameters
surface Surface?: The surface to be used for video rendering. Can be null.
Return
Boolean true if the surface was set successfully, false otherwise.

onSetTvMessageEnabled

Added in API level 34
open fun onSetTvMessageEnabled(
    type: Int,
    enabled: Boolean
): Unit

Called when the application enables or disables the detection of the specified message type.

Parameters
type Int: The type of message received, such as TvInputManager#TV_MESSAGE_TYPE_WATERMARK Value is android.media.tv.TvInputManager#TV_MESSAGE_TYPE_WATERMARK, android.media.tv.TvInputManager#TV_MESSAGE_TYPE_CLOSED_CAPTION, or android.media.tv.TvInputManager#TV_MESSAGE_TYPE_OTHER
enabled Boolean: true if TV message detection is enabled, false otherwise.

onSurfaceChanged

Added in API level 21
open fun onSurfaceChanged(
    format: Int,
    width: Int,
    height: Int
): Unit

Called after any structural changes (format or size) have been made to the surface passed in onSetSurface. This method is always called at least once, after onSetSurface is called with non-null surface.

Parameters
format Int: The new PixelFormat of the surface.
width Int: The new width of the surface.
height Int: The new height of the surface.

onTimeShiftGetCurrentPosition

Added in API level 23
open fun onTimeShiftGetCurrentPosition(): Long

Returns the current position for time shifting, in milliseconds since the epoch. Returns TvInputManager#TIME_SHIFT_INVALID_TIME if the position is unknown at the moment.

The current position for time shifting is the same as the current position of playback. It should be equal to or greater than the start position reported by onTimeShiftGetStartPosition(). When playback is completed, the current position should stay where the playback ends, in other words, the returned value of this mehtod should be equal to the start position plus the duration of the program.

onTimeShiftGetStartPosition

Added in API level 23
open fun onTimeShiftGetStartPosition(): Long

Returns the start position for time shifting, in milliseconds since the epoch. Returns TvInputManager#TIME_SHIFT_INVALID_TIME if the position is unknown at the moment.

The start position for time shifting indicates the earliest possible time the user can seek to. Initially this is equivalent to the time when the implementation starts recording. Later it may be adjusted because there is insufficient space or the duration of recording is limited by the implementation. The application does not allow the user to seek to a position earlier than the start position.

For playback of a recorded program initiated by onTimeShiftPlay(android.net.Uri), the start position should be 0 and does not change.

onTimeShiftPause

Added in API level 23
open fun onTimeShiftPause(): Unit

Called when the application requests to pause playback.

onTimeShiftPlay

Added in API level 24
open fun onTimeShiftPlay(recordedProgramUri: Uri!): Unit

Called when the application requests to play a given recorded TV program.

Parameters
recordedProgramUri Uri!: The URI of a recorded TV program.

onTimeShiftResume

Added in API level 23
open fun onTimeShiftResume(): Unit

Called when the application requests to resume playback.

onTimeShiftSeekTo

Added in API level 23
open fun onTimeShiftSeekTo(timeMs: Long): Unit

Called when the application requests to seek to a specified time position. Normally, the position is given within range between the start and the current time, inclusively. The implementation is expected to seek to the nearest time position if the given position is not in the range.

Parameters
timeMs Long: The time position to seek to, in milliseconds since the epoch.

onTimeShiftSetPlaybackParams

Added in API level 23
open fun onTimeShiftSetPlaybackParams(params: PlaybackParams!): Unit

Called when the application sets playback parameters containing the speed and audio mode.

Once the playback parameters are set, the implementation should honor the current settings until the next tune request. Pause/resume/seek request does not reset the parameters previously set.

Parameters
params PlaybackParams!: The playback params.

onTouchEvent

Added in API level 21
open fun onTouchEvent(event: MotionEvent!): Boolean

Implement this method to handle touch screen motion events on the current input session.

Parameters
event MotionEvent!: The motion event being received.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onTrackballEvent

Added in API level 21
open fun onTrackballEvent(event: MotionEvent!): Boolean

Implement this method to handle trackball events on the current input session.

Parameters
event MotionEvent!: The motion event being received.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onTune

Added in API level 21
abstract fun onTune(channelUri: Uri!): Boolean

Tunes to a given channel.

No video will be displayed until notifyVideoAvailable() is called. Also, notifyVideoUnavailable(int) should be called when the TV input cannot continue playing the given channel.

Parameters
channelUri Uri!: The URI of the channel.
Return
Boolean true if the tuning was successful, false otherwise.

onTune

Added in API level 24
open fun onTune(
    channelUri: Uri!,
    params: Bundle!
): Boolean

Tunes to a given channel. Override this method in order to handle domain-specific features that are only known between certain TV inputs and their clients.

The default implementation calls onTune(android.net.Uri).

Parameters
channelUri Uri!: The URI of the channel.
params Bundle!: Domain-specific data for this tune request. Keys must be a scoped name, i.e. prefixed with a package name you own, so that different developers will not create conflicting keys.
Return
Boolean true if the tuning was successful, false otherwise.

onTvMessage

Added in API level 34
open fun onTvMessage(
    type: Int,
    data: Bundle
): Unit

Called when a TV message is received

Parameters
type Int: The type of message received, such as TvInputManager#TV_MESSAGE_TYPE_WATERMARK Value is android.media.tv.TvInputManager#TV_MESSAGE_TYPE_WATERMARK, android.media.tv.TvInputManager#TV_MESSAGE_TYPE_CLOSED_CAPTION, or android.media.tv.TvInputManager#TV_MESSAGE_TYPE_OTHER
data Bundle: The raw data of the message. The bundle keys are: TvInputManager#TV_MESSAGE_KEY_STREAM_ID, TvInputManager#TV_MESSAGE_KEY_GROUP_ID, TvInputManager#TV_MESSAGE_KEY_SUBTYPE, TvInputManager#TV_MESSAGE_KEY_RAW_DATA. See TvInputManager#TV_MESSAGE_KEY_SUBTYPE for more information on how to parse this data. This value cannot be null.

onUnblockContent

Added in API level 21
open fun onUnblockContent(unblockedRating: TvContentRating!): Unit

Requests to unblock the content according to the given rating.

The implementation should unblock the content. TV input service has responsibility to decide when/how the unblock expires while it can keep previously unblocked ratings in order not to ask a user to unblock whenever a content rating is changed. Therefore an unblocked rating can be valid for a channel, a program, or certain amount of time depending on the implementation.

Parameters
unblockedRating TvContentRating!: An unblocked content rating

setOverlayViewEnabled

Added in API level 21
open fun setOverlayViewEnabled(enable: Boolean): Unit

Enables or disables the overlay view.

By default, the overlay view is disabled. Must be called explicitly after the session is created to enable the overlay view.

The TV input service can disable its overlay view when the size of the overlay view is insufficient to display the whole information, such as when used in Picture-in-picture. Override onOverlayViewSizeChanged to get the size of the overlay view, which then can be used to determine whether to enable/disable the overlay view.

Parameters
enable Boolean: true if you want to enable the overlay view. false otherwise.