Android OpenTV Player SDK  4.23.3.1610362082
NMPVideoView Class Reference

Inherits RelativeLayout, MediaPlayerControl, and PlayerInterface.

Public Member Functions

 NMPVideoView (Context context)
 Simple constructor to use when creating a view from code. More...
 
 NMPVideoView (Context context, AttributeSet attrs)
 Constructor that is called when inflating a view from XML. More...
 
 NMPVideoView (Context context, AttributeSet attrs, int defStyle)
 Perform inflation from XML and apply a class-specific base style from a theme attribute. More...
 
String toString ()
 Returns a string containing a concise, human-readable description of this object. More...
 
void setVideoPath (String path)
 Sets the video path. More...
 
void setVideoPath (String path, int contentType)
 Sets the video path with content type. More...
 
void setVideoURI (Uri uri)
 Sets the video URI. More...
 
void stopPlayback ()
 Stops playback and releases the media player ready for next playback. More...
 
void setMediaController (MediaController controller)
 Sets the media controller to be used by the VideoView to interface with playback. More...
 
void start ()
 Starts playback. More...
 
void pause ()
 Pauses playback. More...
 
void resume ()
 Resumes paused content. More...
 
int getDuration ()
 Get the duration of the content. More...
 
int getCurrentPosition ()
 Get the current playback position. More...
 
void seekTo (int msec)
 Tells the player to seek to a specific time. More...
 
boolean isPlaying ()
 Check if content is currently playing back. More...
 
int getBufferPercentage ()
 Gets the current buffer percentage. More...
 
boolean canPause ()
 Check if the content being played can be paused. More...
 
boolean canSeekBackward ()
 Check if the content being played can seek backwards. More...
 
boolean canSeekForward ()
 Check if the content being played can seek forwards. More...
 
Date getCurrentDate ()
 This method gets the date and time information in HLS content when the HLS tag "EXT-X-PROGRAM-DATE-TIME" is included. More...
 
void setOnPreparedListener (OnPreparedListener listener)
 Register a callback to be invoked when the media file is loaded and ready to go. More...
 
void setOnCompletionListener (OnCompletionListener listener)
 Register a callback to be invoked when the end of a media file has been reached during playback. More...
 
void setOnErrorListener (OnErrorListener listener)
 Register a callback to be invoked when an error occurs during playback or setup. More...
 
void setOnInfoListener (OnInfoListener listener)
 Register a callback to be invoked when an informational event occurs during playback or setup. More...
 
void setOnTimedMetaDataAvailableListener (OnNMPTimedMetadataAvailableListener listener)
 Register a callback to be invoked when a selected track has timed metadata available. More...
 
void setOnOutputControlListener (OutputControlListener listener)
 Register a callback to be invoked when an OutputControl state has changed. More...
 
long [] getSeekableRangeInfo ()
 This method returns the range of the current content that can seek. More...
 
void setMaxBandwidth (int bandwidth)
 Set the maximum bandwidth for content playback, in bits per second. More...
 
void setMaxResolution (int width, int height)
 Set the maximum resolution for content playback, in pixels. More...
 
void setVideoScalingMode (int mode)
 Sets video scaling mode. More...
 
int getVideoScalingMode ()
 return video scaling mode that player are using. More...
 
void setSourceTimeout (int timeout)
 Set the source timeout for a playback, in seconds. More...
 
int getSourceTimeout ()
 Get the source timeout for a playback, in seconds. More...
 
int getMaxBandWidth ()
 Get the maximum bandwidth. More...
 
NMPTrackInfo [] getNMPTrackInfo ()
 Returns an array of track information. More...
 
void selectTrack (int index)
 Selects and activates the track referenced by index. More...
 
void deselectTrack (int index)
 Deactivates the current caption. More...
 
void setTrackDown (boolean enabled)
 This Allows NMP SDK to switch to a lower bandwidth track if the resolution or bitrate of the current track is too high for the device to play smoothly. More...
 
void setTrackDownThreshold (float ratio)
 Set track down ratio. More...
 
float getTrackDownThreshold ()
 Get track down threshold ratio. More...
 
boolean addSubtitleSource (String url, String mimeType, String language)
 Adds an external subtitle source to the content. More...
 
boolean addSubtitleSource (byte[] content, String mimeType, String language)
 Adds an external subtitle source to the content. More...
 
int getBufferSize ()
 Gets the buffer size. More...
 
void addTagListener (List< String > xTagsToParse, NMPTagListener xListener)
 Register tags listener. More...
 
void removeTagListener (NMPTagListener xListener)
 Remove tags listener. More...
 
void setVolumeGain (int xTargetGain)
 Amplify audio Volume The default value is 1 which means audio volume won't be changed If set input value to be 2 the output volume will be twice of the original The maximum input value is 8 to avoid distortion. More...
 
void clearTagListeners ()
 clear all tags listener More...
 

Detailed Description

Replaces the android.widget.VideoView class

NMPVideoView class is used to control playback of audio/video files and streams served from NMP assets server. The NMPVideoView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling and tinting.

Note: NMPVideoView does not retain its full state when going into the background. In particular, it does not restore the current play state & play position. Applications should save and restore these on their own in onSaveInstanceState(Bundle) and onRestoreInstanceState(Bundle).

MediaPlayerStateDiagram.jpg

Constructor & Destructor Documentation

◆ NMPVideoView() [1/3]

NMPVideoView ( Context  context)

Simple constructor to use when creating a view from code.

◆ NMPVideoView() [2/3]

NMPVideoView ( Context  context,
AttributeSet  attrs 
)

Constructor that is called when inflating a view from XML.

◆ NMPVideoView() [3/3]

NMPVideoView ( Context  context,
AttributeSet  attrs,
int  defStyle 
)

Perform inflation from XML and apply a class-specific base style from a theme attribute.

Member Function Documentation

◆ addSubtitleSource() [1/2]

boolean addSubtitleSource ( String  url,
String  mimeType,
String  language 
)

Adds an external subtitle source to the content.

An external subtitle/caption source can be added to the content to play back via this method. Currently only SRT subs are supported.

Parameters
urlthe remote url of the subtitles
mimeTypethe mime type of the subtitles (must be "application/x-subrip" currently)
languagethe language identifier of the subtitles (will appear in subtitle track selection)
Returns
false if no one video path/url has been set or the url can't be parsed or the mime type is not understood, true otherwise
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ addSubtitleSource() [2/2]

boolean addSubtitleSource ( byte []  content,
String  mimeType,
String  language 
)

Adds an external subtitle source to the content.

An external subtitle/caption source can be added to the content to play back via this method. Currently only SRT subs are supported.

Parameters
contentthe array of subtitle data
mimeTypethe mime type of the subtitles (must be "application/x-subrip" currently)
languagethe language identifier of the subtitles (will appear in subtitle track selection)
Returns
false if no one video path/url has been set or the mime type is not understood, true otherwise
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ addTagListener()

void addTagListener ( List< String >  xTagsToParse,
NMPTagListener  xListener 
)

Register tags listener.

Parameters
xTagsToParsethe tags list which contains all tags that are required
xListenerthe listener object

◆ canPause()

boolean canPause ( )

Check if the content being played can be paused.

Returns
true if content can be paused, false otherwise
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ canSeekBackward()

boolean canSeekBackward ( )

Check if the content being played can seek backwards.

Returns
true if content can be seek backwards, false otherwise
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ canSeekForward()

boolean canSeekForward ( )

Check if the content being played can seek forwards.

Returns
true if content can be seek forwards, false otherwise
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ clearTagListeners()

void clearTagListeners ( )

clear all tags listener

◆ deselectTrack()

void deselectTrack ( int  index)

Deactivates the current caption.

Parameters
indexthe index of the track to deactivate
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ getBufferPercentage()

int getBufferPercentage ( )

Gets the current buffer percentage.

Returns
the buffer percentage.
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE
Note
currently will always return zero

◆ getBufferSize()

int getBufferSize ( )

Gets the buffer size.

Returns
The maximum buffer size for the content in second.
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE
Note
Currently for all content, the default buffer size is 60 seconds

◆ getCurrentDate()

Date getCurrentDate ( )

This method gets the date and time information in HLS content when the HLS tag "EXT-X-PROGRAM-DATE-TIME" is included.

Returns
Current program date time if tag exist, null otherwise
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ getCurrentPosition()

int getCurrentPosition ( )

Get the current playback position.

Returns
the current playback position in milliseconds
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE
Note
after an onSeekComplete callback, the current position may take up to a second to update to the accurate position

◆ getDuration()

int getDuration ( )

Get the duration of the content.

Returns
the duration of the content in milliseconds
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ getMaxBandWidth()

int getMaxBandWidth ( )

Get the maximum bandwidth.

0 means no maximum bandwidth limit.

Returns
the capped bitrate, in bits/second.
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ getNMPTrackInfo()

NMPTrackInfo [] getNMPTrackInfo ( )

Returns an array of track information.

Returns
Array of track info. The total number of tracks is the array length. Must be called again if MEDIA_INFO_METADATA_UPDATE of MEDIA_INFO has been called.
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ getSeekableRangeInfo()

long [] getSeekableRangeInfo ( )

This method returns the range of the current content that can seek.

This method is used to allow NMPVideoView to support timeshifting playback within HLS Live Streaming content. Based on the amount of content available from the server at a particular time, it determines the seek range within the playing content which also indicates the range where playback may be timeshifted.

This range will be constantly shifting as the live streaming content available from the server changes in real time, so this method will need to be repeatedly called to ensure accurate shifting of playback.

For local content this method will always return the same two values, and the second value indicating the end of the seek range, but this method is most relevant when playing live streaming content

Returns
An array of two longs in seconds, the first long being the timestamp indicating the start of the seek range,and the second being the timestamp indicating the end of the seek range. return null means that the player can't get the seek range information now
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ getSourceTimeout()

int getSourceTimeout ( )

Get the source timeout for a playback, in seconds.

This timeout value specifies how long the player waits (in seconds) when no media data is received.

Returns
int, the timeout in seconds

0 - no timeout (infinity)

>0 - timeout in seconds

<0 - not available or not implemented

Remarks
If you call this method before playing the stream, it returns -1. If you call it after a stream starts playing but before calling setSourceTimeout, it returns the default value. If it returns -1 after the stream starts playing, it means the stream type does not support setting a timeout.
See also
setSourceTimeout

◆ getTrackDownThreshold()

float getTrackDownThreshold ( )

Get track down threshold ratio.

Returns
float
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ getVideoScalingMode()

int getVideoScalingMode ( )

return video scaling mode that player are using.

The supported video scaling modes are:

Returns
video scaling mode

◆ isPlaying()

boolean isPlaying ( )

Check if content is currently playing back.

Returns
true if content is currently playing back, false if it is not or no content is loaded
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ pause()

void pause ( )

Pauses playback.

Remarks
Valid States: PLAYING

◆ removeTagListener()

void removeTagListener ( NMPTagListener  xListener)

Remove tags listener.

Parameters
xListenerthe listener object

◆ resume()

void resume ( )

Resumes paused content.

Remarks
Valid States: PAUSED

◆ seekTo()

void seekTo ( int  msec)

Tells the player to seek to a specific time.

Parameters
msecThe time, in milliseconds, to seek to. Limited to the range returned from getSeekableRangeInfo()
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ selectTrack()

void selectTrack ( int  index)

Selects and activates the track referenced by index.

Note: Must have got the track info first by calling getNMPTrackInfo()

Parameters
indexthe index of the track to activate
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ setMaxBandwidth()

void setMaxBandwidth ( int  bandwidth)

Set the maximum bandwidth for content playback, in bits per second.

When set, the NMP SDK will prevent the player from obtaining content streams above this bandwidth limit. If a playlist does not have any streams available with this limit, the lowest bandwidth stream will be used for playback.

Setting a maximum bandwidth of 0 or negative values will remove the limit.

The maximum bandwidth will remain in place until setMaxBandWidth is called again, or until the NMPVideoView is disposed of.

Parameters
bandwidththe bandwidth, in bits/second, to cap the content.
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ setMaxResolution()

void setMaxResolution ( int  width,
int  height 
)

Set the maximum resolution for content playback, in pixels.

When set, the NMP SDK will prevent the player from obtaining content streams above this resolution limit. If a playlist does not have any streams available with this limit, the lowest resolution stream will be used for playback. The content stream must have both width and height values below the set limits for a stream to be allowed

Setting a maximum resolution of 0 x 0 will remove the limit.

The maximum resolution will remain in place until setMaxResolution is called again, or until the NMPVideoView is disposed of.

Parameters
widththe width, in pixels, to cap the content.
heightthe height, in pixels, to cap the content.
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ setMediaController()

void setMediaController ( MediaController  controller)

Sets the media controller to be used by the VideoView to interface with playback.

Parameters
controllerthe MediaController object to be used

◆ setOnCompletionListener()

void setOnCompletionListener ( OnCompletionListener  listener)

Register a callback to be invoked when the end of a media file has been reached during playback.

Parameters
listenerThe callback that will be run

◆ setOnErrorListener()

void setOnErrorListener ( OnErrorListener  listener)

Register a callback to be invoked when an error occurs during playback or setup.

Parameters
listenerThe callback that indicate an error will be run:

boolean onError(MediaPlayer mp, int what, int extra);

mp the NMPMediaPlayer the error pertains to

what the type of error that has occurred:

extra an extra code, specific to the error. Typically implementation dependent.

◆ setOnInfoListener()

void setOnInfoListener ( OnInfoListener  listener)

Register a callback to be invoked when an informational event occurs during playback or setup.

Parameters
listenerThe callback that indicate an info or a warning, will be run:

boolean onInfo(MediaPlayer mp, int what, int extra):

mp the MediaPlayer the info pertains to.

what the type of info or warning.

    extra     an extra code, specific to the info. Typically implementation dependent.

when 'what' is NMPMediaPlayer.MEDIA_INFO_STALLED, Media playback is continuous pausing internally because of network is stalled

when 'what' is NMPMediaPlayer.MEDIA_INFO_METADATA_UPDATE, 'extra' could be

◆ setOnOutputControlListener()

void setOnOutputControlListener ( OutputControlListener  listener)

Register a callback to be invoked when an OutputControl state has changed.

Parameters
listenerThe callback that will indicate when OutputControl state has changed
See also
OutputControlListener::onDeviceConnected(int)
OutputControlListener::onDeviceDisconnected(int)
OutputControlListener::onAccessStateChanged(int)
OutputControlListener::onBitrateLimitCapped(int)
OutputControlListener::onResolutionLimitCapped(int,int)

◆ setOnPreparedListener()

void setOnPreparedListener ( OnPreparedListener  listener)

Register a callback to be invoked when the media file is loaded and ready to go.

Parameters
listenerThe callback that will be run

◆ setOnTimedMetaDataAvailableListener()

void setOnTimedMetaDataAvailableListener ( OnNMPTimedMetadataAvailableListener  listener)

Register a callback to be invoked when a selected track has timed metadata available.

Currently only HTTP live streaming data URI's embedded with timed ID3 tags generates NMPTimedMetaData.

See also
NMPMediaPlayer.OnNMPTimedMetadataAvailableListener
NMPTimedMetaData
Parameters
listenerthe callback that will be run

◆ setSourceTimeout()

void setSourceTimeout ( int  timeout)

Set the source timeout for a playback, in seconds.

For supported stream types, this specifies how long the player waits when no media data is received. For unsupported stream types, this timeout value is ignored.

Parameters
timeout

0 - no timeout (infinity)

>0 - timeout in seconds

<0 - not allowed (stream type does not support setting a timeout)

Remarks
If you call this method before playing the stream, the value will only be set after setVideoURI. This method is only available for RTP streams.
See also
getSourceTimeout

◆ setTrackDown()

void setTrackDown ( boolean  enabled)

This Allows NMP SDK to switch to a lower bandwidth track if the resolution or bitrate of the current track is too high for the device to play smoothly.

Under normal operation, NMP SDK switches tracks based solely on current network conditions. When this property is enabled, NMP SDK will also switch to a lower bandwidth track if too many frames are skipped during playback. This is useful for content that is targeted for a variety of devices, some of which may not be powerful enough to handle the higher quality streams. Enable track down by passing in true, NMP SDK will require that at least the ratio of the decoded frames be displayed which specified by the second parameter.

Parameters
enabledFlag of enable or disable track down.
Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ setTrackDownThreshold()

void setTrackDownThreshold ( float  ratio)

Set track down ratio.

Parameters
ratioratio of frames dropped, ranging [0.0f, 1.0f].
Remarks
Valid States: PREPARED, PLAYING, PAUSE, PLAYBACK_COMPLETE

◆ setVideoPath() [1/2]

void setVideoPath ( String  path)

Sets the video path.

Parameters
paththe String based path to the content to be played back.
Exceptions
NullPointerExceptionif the path parameter is null
Remarks
Valid States: IDLE

◆ setVideoPath() [2/2]

void setVideoPath ( String  path,
int  contentType 
)

Sets the video path with content type.

Parameters
paththe String based path to the content to be played back.
contentTypeindicate the stream content type. The available values are:
Exceptions
NullPointerExceptionif the path parameter is null
Remarks
Valid States: IDLE

◆ setVideoScalingMode()

void setVideoScalingMode ( int  mode)

Sets video scaling mode.

To make the target video scaling mode effective during playback, this method must be called after data source is set. If not called, the default video scaling mode is MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT.

The supported video scaling modes are:

Parameters
modetarget video scaling mode. Most be one of the supported video scaling modes; otherwise, IllegalArgumentException will be thrown.

◆ setVideoURI()

void setVideoURI ( Uri  uri)

Sets the video URI.

Parameters
urithe URI to the content to be played back.
Remarks
Valid States: IDLE

◆ setVolumeGain()

void setVolumeGain ( int  xTargetGain)

Amplify audio Volume The default value is 1 which means audio volume won't be changed If set input value to be 2 the output volume will be twice of the original The maximum input value is 8 to avoid distortion.

Parameters
xTargetGainthe target gain

◆ start()

void start ( )

Starts playback.

Remarks
Valid States: PLAYING, PLAYBACK_COMPLETE

◆ stopPlayback()

void stopPlayback ( )

Stops playback and releases the media player ready for next playback.

Remarks
Valid States: PREPARED, PLAYING, PAUSED, PLAYBACK_COMPLETE

◆ toString()

String toString ( )

Returns a string containing a concise, human-readable description of this object.