Once you have a player up and running is interesting to get the statistics about the url/local video you are playing, this can help to locate problems related to the content you are using and give you several hints about performance.
Through this guide you will learn all the tweaks for getting all your player data.
To monitor the playback statistics, after NexPlayer is created and initialized but before content is opened, the app must:
- Create an instance of the NexStatisticsMonitor class.
- Set a listener to receive the events reporting statistics information with
IStatisticsListener. - If desired, the time interval at which statistics are monitored can be changed with calls to setDuration.
First of all you need to import the classes that will provide you with the information related to the content playing. Here you can also see the 4 types of information that NexStatisticsMonitor will provide you for the playing content.
import com.nexstreaming.nexplayerengine.NexStatisticsMonitor;
import static com.nexstreaming.nexplayerengine.NexStatisticsMonitor.HttpStatisticsMetric;
import static com.nexstreaming.nexplayerengine.NexStatisticsMonitor.STATISTICS_GENERAL;
import static com.nexstreaming.nexplayerengine.NexStatisticsMonitor.STATISTICS_HTTP;
import static com.nexstreaming.nexplayerengine.NexStatisticsMonitor.STATISTICS_INITIAL;
import static com.nexstreaming.nexplayerengine.NexStatisticsMonitor.STATISTICS_SYSTEM;With this you can start receiving the information related to the content, when the related objects are created.
The NexStatisticsMonitor class defines a statistics monitoring module to be used during playback of HLS, DASH, or SS content with NexPlayer.
It should be used with IStatisticsListener interface. Here is some example code for how to implement and use the class.
- Create a new NexStatisticsMonitor in the app
NexStatisticMonitor mMonitor = new NexStatisticMonitor(mNexPlayer);- Set a listener for statistics-related events
mMonitor.setListener( listener );- Set the time interval at which general playback statistics should be requested (ie every 5 seconds)
mMonitor.setDuration(NexStatisticsMonitor.GeneralStatistic, 5);- Set the time interval at which system statistics during playback should be requested.
mMonitor.setDuration(NexStatisticsMonitor.SystemStatistic, seconds);The IStatisticsListener interface will be implemented by the developer and will receive all the information of the playing content.
Main method to override is onUpdate:
IStatisticsListener mStatisticsListener = new NexStatisticsMonitor.IStatisticsListener() {
@Override
public void onUpdated(int statisticsType, HashMap<IStatistics, Object> map) {
if( statisticType == STATISTICS_GENERAL) {
printGeneralStatistic( map );
}
else if( statisticType == STATISTICS_INITIAL) {
printInitialStatistic( map );
}
else if( statisticType == STATISTICS_HTTP) {
printHttpStatistic( map );
}
else if ...
}
};
mMonitor.setListener(mStatisticsListener);Method for printing the GeneralStatistics
private void printGeneralStatistic( HashMap<NexStatisticsMonitor.IStatistics, Object> map ) {
String str = "\n";
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
NexStatisticsMonitor.GeneralStatisticsMetric key = (NexStatisticsMonitor.GeneralStatisticsMetric)entry.getKey();
Object value = entry.getValue();
str += ( key.toString() + " : " + getString(value) + "\n\n" );
}
System.out.println(str);
}Instead of printing it into the debug console, it is recommended to create a view inside the app for showing the statistics while the content is running or a logs module for checking it later.
This class defines a statistics monitoring module to be used during playback of HLS, DASH, or SS content with NexPlayer.
Implementing this class in an application makes it easier to monitor different kinds of statistics at regular intervals during playback of HLS, DASH, or SS content in order to for example have more details about player performance.
To monitor HLS, DASH, or SS playback statistics, after NexPlayer is created and initialized but before content is opened, an application must:
- First, create an instance of this NexStatisticsMonitor class,
- Next, set a listener to receive the events reporting statistics information with IStatisticsListener,
- lastly, if desired, the time interval at which statistics are monitored can be changed with calls to setDuration.
Depending on what information about playback is needed, different statistics can be retrieved from NexPlayer, including general playback statistics (GeneralStatisticsMetric), statistics when initializing content (InitialStatisticsMetric), HTTP statistics(HttpStatisticsMetric), and system statistics during playback (SystemStatisticsMetric).
The available statistics are briefly summarized in the table below:
| Statistics Category | Metric | Data Type | Unit | |
|---|---|---|---|---|
| STATISTICS_GENERAL | PLAY_TIME_SEC | long | seconds | |
| BYTES_RECEIVED | long | Bytes | ||
| CUR_NETWORK_BW_BPS | int | bps | ||
| CUR_TRACK_BW_BPS | int | bps | ||
| NUM_SEG_REQUESTS | int | num | ||
| NUM_SEG_RECEIVED | int | num | ||
| NUM_SEG_DOWN_RATE | int | num | ||
| NUM_SEG_FAIL_TO_PARSE | int | num | ||
| NUM_SEG_IN_BUFFER | int | num | ||
| NUM_REQUEST_ERRORS | int | num | ||
| NUM_REQUEST_TIMEOUT | int | num | ||
| NUM_TRACK_SWITCH_UP | int | num | ||
| NUM_TRACK_SWITCH_DOWN | int | num | ||
| NUM_VIDEO_FRAME_RENDERED | int | num | ||
| NUM_VIDEO_FRAME_DECODED | int | num | ||
| NUM_HTTP_REQUESTS | int | num | ||
| STATISTICS_INITIAL | NUM_TRACK | int | num | |
| NUM_PREBUFFERED_SEGMENTS | int | num | ||
| NUM_REDIRECTS | int | num | ||
| MASTER_PLAYLIST | String | text | ||
| MASTER_PLAYLIST_URL | String | text | ||
| INITIAL_PLAYLIST | String | text | ||
| INITIAL_PLAYLIST_URL | String | text | ||
| START_SEGMENT_URL | String | text | ||
| CONTENT_DURATION | int | msec | ||
| STATISTICS_HTTP | DOWN_START | RESOURCE_URL | String | text |
| FILE_TYPE | FileType | FileType | ||
| SEG_NO | int | num | ||
| SEG_DURATION | int | msec | ||
| TRACK_BW | int | bps | ||
| MEDIA_COMPOSITION | int | MediaType | ||
| CONNECT | RESOURCE_URL | String | text | |
| CONNECTED | RESOURCE_URL | String | text | |
| HEADER_RECEIVED | RESOURCE_URL | String | text | |
| DATA_RECEIVED | RESOURCE_URL | String | text | |
| BYTE_RECEIVED | long | Bytes | ||
| CONTENT_LENGTH | long | Bytes | ||
| DOWN_END | RESOURCE_URL | String | text | |
| BYTE_RECEIVED | long | Bytes | ||
| ERROR | RESOURCE_URL | String | text | |
| STATISTICS_SYSTEM | CPU_USAGE | double | percentage (0 - 1) | |
| FREE_MEMORY_KB | long | kilobytes | ||
Example Code for how to implement and use NexStatisticsMonitor:
// Create a new NexStatisticsMonitor in the application
NexStatisticMonitor mMonitor = new NexStatisticMonitor(mNexPlayer);
IStatisticsListener listener =
{
void onUpdated(int statisticsType, HashMap<IStatistic, Object> map) {
if( statisticsType == STATISTICS_GENERAL ) {
while ( IStatistics key in map ) {
GeneralStatisticsMetric key = (GeneralStatisticsMetric)map.getKey();
Object value = map.getValue();
}
}
else if( statisticsType == STATISTICS_INITIAL ) {
while ( IStatistics key in map ) {
InitialStatisticsMetric key = (InitialStatisticsMetric)map.getKey();
Object value = map.getValue();
}
}
else if( statisticsType == STATISTICS_HTTP ) {
while ( IStatistics key in map ) {
HttpStatisticsMetric key;
HashMap<HttpStatisticsParamKey, Object> subMap;
key = (HttpStatisticsMetric)map.getKey();
subMap = (HashMap<HttpStatisticsParamKey,Object>)map.getValue();
while(HttpStatisticsParamKey key in subMap) {
HttpStatisticsParamKey paramkey = (HttpStatisticsParamKey)subMap.getKey();
Object value = entry.getValue();
}
}
}
else if ..
}
}
// Set a listener for statistics-related events
mMonitor.setListener( listener );
// Set the time interval at which general playback statistics should be requested (ie every 5 seconds)
mMonitor.setDuration(NexStatisticsMonitor.GeneralStatistic, seconds);
// Set the time interval at which system statistics during playback should be requested.
mMonitor.setDuration(NexStatisticsMonitor.SystemStatistic, seconds);Classes
-
enum FileTypeAn enumeration of the possible types of files being handled by NexPlayer during HLS, DASH, or SS playback. -
enum GeneralStatisticsMetricThis is an enumeration of the possible general statistics that can be requested during playback of HLS, DASH, or SS content in NexPlayer. -
enum HttpStatisticsMetricThis enumeration defines the possible HTTP statistics that can be requested during HLS, DASH, or SS playback by NexPlayer. -
enum HttpStatisticsParamKeyThis enumeration defines the parameter key, for parameters related to HTTP statistics monitored during HLS, DASH, or SS playback. -
enum InitialStatisticsMetricThis is an enumeration of the possible initial statistics that can be requested when initializing playback of HLS, DASH, or SS content in NexPlayer. -
interface IStatisticsThis interface defines a set of statistics to be received fromNexPlayer aboutHLS, DASH, or SS playback. -
interface IStatisticsListenerThis interface defines the listener that will be used to receive statistics related to playback. -
enum MediaTypeAn enumeration defining the possible types of HLS, DASH, or SS media can be played by NexPlayer. -
enum StatisticsErrorAn enumeration of the statistics-related errors possible when using theNexStatisticsMonitor. -
enum SystemStatisticsMetricThis is an enumeration of the possible system statistics that can be requested during playback of HLS, DASH, or SS content in NexPlayer.
Defines theNexStatisticsMonitormodule that an application can use to retrieve statistics about playback of HLS, DASH, or SS content in NexPlayer.
Parameters
| Name | Description |
|---|---|
| np | TheNexPlayerinstance that the statistics monitor will receive events from. |
This method sets the interval of time at which playback statistics will be reported and sent (for HLS, DASH, or SS content only).
After a statistics listener has been set, this method can be called to change the interval at which general playback and system statistics are monitored at any time before starting playback.
The default interval of time for monitoring general and system statistics during HLS, DASH, or SS playback is 5000 ms or 5 seconds.
Note The interval between statistics events can only be set for GeneralStatisticsMetric and SystemStatisticsMetric requests so an error will be returned if any other statisticsType is indicated because initial statistics and HTTP statistics are event-driven statistics.
Parameters
| Name | Description |
|---|---|
| statisticsType | statisticsType The type of statistics to be retrieved at the interval set here. This should be STATISTICS_GENERAL for general playback statistics or STATISTICS_SYSTEM for monitoring system statistics during playback. |
| seconds | The interval at which statistics will be monitored, in seconds, as a double. |
Returns
if successful or the relevant NexStatistics error code (for example, RETURN_ERROR_DURATION_INVALID)
See Also
- GeneralStatistics
- SystemStatistics
- StatisticsErrror
This method sets a listener to receive statistics events about HLS, DASH, or SS playback in NexPlayer.
A statistics listener should be set after NexPlayer has been created and initialized, but before content playback begins.
Parameters
| Name | Description |
|---|---|
| listener | The listener that will receive playback statistics events. |
See Also
- setDuration(int statisticsType, double seconds)
A possible argument value for the parameterstatisticsTypein the onUpdated() and setDuration() methods for the type of statistics being requested and received, for general playback statistics.
A possible argument value for the parameter statisticsType in the onUpdated() method for the type of statistics being requested and received, for HTTP statistics.
A possible argument value for the parameter statisticsType in the onUpdated() method for the type of statistics being requested and received, for initial statistics (statistics about when playback is initialized).
A possible argument value for the parameter statisticsType in the onUpdated() and setDuration() methods for the type of statistics being requested and received, for system statistics.
An enumeration of the statistics-related errors is possible when using theNexStatisticsMonitor.
The duration set is invalid or cannot be applied to the statistics being requested.
Playback statistics were successfully retrieved without error.
The type of statistics being requested is invalid.
This is an enumeration of the possible system statistics that can be requested during playback of HLS, DASH, or SS content in NexPlayer.
These statistics are only related to the system performance during playback. For other statistics specifically about the HLS, DASH, or SS content playback or HTTP statistics, monitor GeneralStatisticsMetric or HttpStatisticsMetricinstead.
See Also
- GeneralStatisticsMetric
- HttpStatisticsMetric
- setDuration
Sets the system statistics metric.
Gets the system statistics code, as an integer.
Returns
The system statistics code requested, as an integer.
Implements NexStatisticsMonitor.IStatistics.
The current CPU usage, as a percentage, is represented as a value between 0 and 1, where zero is 0 percent and 1 is 100 percent.
The current amount of memory free, in kilobytes, as a long.
An enumeration of the possible types of files being handled by NexPlayer during HLS, DASH, or SS playback.
These are possible values for the HTTP statistics parameter key, FILE_TYPE.
Sets the FileType.
Gets the FileType code as an integer.
Returns
The requested FileType code as an integer.
This method gets the FileType from the integer code of the FileType.
Returns
The FileType corresponding to the given integer code. This will be one of:
UNKNOWNfor an unknown filetype,MANIFESTfor a manifest file,SEGMENTfor a segment file,INITIAL_SEGMENTfor an initial segment file, orKEYfor a key file.
This is an enumeration of the possible general statistics that can be requested during playback of HLS, DASH, or SS content in NexPlayer.
The statistics defined here are for general playback of HLS, DASH, or SS content. If statistics about the initialization of content are required, please review InitialStatisticsMetric instead.
See Also
- InitialStatisticsMetric
- IStatistics
- setDuration
Sets the general statistic metric.
Gets the general statistic code, as an integer.
Returns
The general statistics code requested.
Implements NexStatisticsMonitor.IStatistics.
The bytes received, as a long.
This is the same as NexRTStreamInformation.mNumOfBytesRecv.
The current bandwidth of the network, in bps, as an integer.
This is the same as NexRTStreamInformation.mCurNetworkBw.
The current track bandwidth, in bps, as an integer.
This is the same as NexRTStreamInformation.mCurTrackBw.
This current number of HTTP requests that have been made, as an integer.
This is the same as the running count of onHttpRequest (NexPlayer mp, String msg) calls.
The current number of segments that the player failed to receive, as an integer.
This is the same as NexRTStreamInformation.mNumOfSegFailToReceive.
The current number of segment reads that resulted in a timeout, as an integer.
This is the same as NexRTStreamInformation.mNumOfSegTimeout.
The number of segments that have an actual read bitrate below the bitrate specified in the profile, where the read bitrate is the speed at which the segments are read from the network.
This is the same as NexRTStreamInformation.mNumOfSegDownRate.
The number of segment reads that were failed to be read and parsed, for example, due to HTTP errors, as an integer.
This is the same as NexRTStreamInformation.mNumOfSegFailToParse.
The current number of segments in the buffer, as an integer.
This is the same as NexRTStreamInformation.mNumOfSegInBuffer.
The current number of segments received, as an integer.
This is the same as NexRTStreamInformation.mNumOfSegReceived.
The current number of segment requests, as an integer.
This is the same as NexRTStreamInformation.mNumOfSegRequest.
The number of times the content profile has been changed to a profile with a lower bitrate, as an integer.
This is the same as NexRTStreamInformation.mNumOfTrackSwitchDown.
The number of times the content profile has been changed to a profile with a higher bitrate, as an integer.
This is the same as NexRTStreamInformation.mNumOfTrackSwitchUp.
The current number of frames that have been decoded, as an integer.
This is the same as getContentInfoInt (NexPlayer.CONTENT_INFO_INDEX_VIDEO_CODEC_DECODIN- G_TOTAL_COUNT).
The current number of frames that have been successfully rendered, as an integer.
This is the same as getContentInfoInt (NexPlayer.CONTENT_INFO_INDEX_VIDEO_RENDER_TOTAL_COUNT).
The current play time in seconds, as along.
This is the same as the count of NEXPLAYER_EVENT_TIME.
This enumeration defines the possible HTTP statistics that can be requested during HLS, DASH, or SS playback by NexPlayer.
For general playback statistics or system statistics during playback, please monitor GeneralStatisticsMetric or SystemStatisticsMetric instead.
Public Attributes
- DOWN_START = ( 0x00000000 )
- CONNECT = ( 0x00000001 )
- CONNECTED = ( 0x00000003 )
- HEADER_RECEIVED = ( 0x00000004 )
- DATA_RECEIVED = ( 0x00000005 )
- DOWN_END = ( 0x00000006 )
- ERROR = ( 0x00000007 )
See Also
- GeneralStatisticsMetric
- SystemStatisticsMetric
- HttpStatisticsParamKey
Sets the HTTP statistics metric.
Gets an HTTP statistic metric as an integer.
Returns
The requested HTTP statistic metric, as an integer.
Implements NexStatisticsMonitor.IStatistics.
This enumeration defines the parameter key, for parameters related to HTTP statistics monitored during HLS, DASH, or SS playback.
Public Attributes
- RESOURCE_URL = ( 0x00000000 ) The resource URL, as a String.
- FILE_TYPE = ( 0x00000001 )
The file type being received, as a
FileType. - SEG_NO = ( 0x00000002 ) The current segment number, as an integer.
- SEG_DURATION = ( 0x00000003 ) The duration of the current segment, as an integer.
- TRACK_BW = ( 0x00000004 ) The bandwidth of the current track, as an integer.
- MEDIA_COMPOSITION = ( 0x00000005 ) The media composition of the current content, as an integer.
- BYTE_RECEIVED = ( 0x00000006 ) The current number of bytes received, as a long.
- CONTENT_LENGTH = ( 0x00000007 ) The current length of the HLS, DASH, or SS content received so far, as a long.
- ERROR_CODE = ( 0x00000008 ) The error code.
Sets the HTTP statistics parameter key.
Gets the HTTP statistics parameter key as an integer code.
Returns
The HTTP statistics parameter key requested, as an integer.
The current number of bytes received, as a long.
A parameter for the HTTP statistics, DATA_RECEIVED and DOWN_END.
The current length of the HLS, DASH, or SS content received so far, as a long.
A parameter for the HTTP statistic, DATA_RECEIVED.
The error code.
A parameter for the HTTP statistic, ERROR.
The file type being received, as a FileType.
A parameter for the HTTP statistic, DOWN_START.
The media composition of the current content, as an integer.
A parameter for the HTTP statistic, DOWN_START.
The resource URL, as a String.
A possible parameter for the HTTP statistics, DOWN_START, CONNECT, CONNECTED, HEADER_RECEIVED, DATA_RECEIVED, DOWN_END, and ERROR.
The duration of the current segment, as an integer.
A parameter for the HTTP statistic, DOWN_START.
The current segment number, as an integer.
A parameter for the HTTP statistic, DOWN_START.
The bandwidth of the current track, as an integer.
A parameter for the HTTP statistic, DOWN_START.
This is an enumeration of the possible initial statistics that can be requested when initializing playback of HLS, DASH, or SS content in NexPlayer.
Since this statistics metric is only for monitoring the statistics related to the initialization of content, for more general playback statistics, monitor GeneralStatisticsMetric instead.
See Also
GeneralStatisticsMetric
Gets the initial statistic code, as an integer.
Returns
The initial statistics code, as an integer.
Implements
NexStatisticsMonitor.IStatistics.
The total duration of the current content, as an integer.
This is the same as NexContentInformation.mMediaDuration.
The full content of the initial manifest playlist, as a String.
This is the same as NexRTStreamInformation.mInitialMpd.
The actual URL (after all redirects) of the initial request for the manifest playlist, as a String.
This is the same as NexRTStreamInformation.mInitialMpdUrl.
The full content of the master manifest playlist, as a String.
This is the same as NexRTStreamInformation.mMasterMpd.
The URL of the master manifest playlist, as a String.
This is the same as NexRTStreamInformation.mMasterMpdUrl.
The total number of segments loaded in the buffer, as an integer.
This is the same as NexRTStreamInformation.mNumOfSegInBuffer.
The total number of redirects, as an integer.
This is the same as NexRTStreamInformation.mNumOfRedirect.
The total number of tracks in the current content, as an integer.
The description of the initially selected profile, as a String.
This is the same as NexRTStreamInformation.mStartSegUrl.
This interface defines a set of statistics to be received from NexPlayer about HLS, DASH, or SS playback.
Every set of statistics (general, initial, HTTP, and system statistics) implements this interface.
See Also
- GeneralStatistics
- InitialStatistics
- HTTPStatistics
- SystemStatistics
This method gets a statistics code.
Implemented in NexStatisticsMonitor.SystemStatisticsMetric, NexStatisticsMonitor.HttpStatisticsMetric, NexStatisticsMonitor.InitialStatisticsMetric, and NexStatisticsMonitor.GeneralStatisticsMetric.
This interface defines the listener that will be used to receive statistics related to playback.
Any listener created to receive statistics from NexPlayer must implement this interface.
Once an instance of NexStatisticsMonitor is created, a statistics listener implementing this interface can be set with setListener(IStatisticsListener listener).
This method is called whenever statistics are updated and sent by NexPlayer.
The time interval at which general and system statistics are updated in NexStatisticsMonitor can be changed by calling the setDuration() method.
| Name | Description |
|---|---|
| statistics Type | |
| STATISTICS_GENERAL= 0, for general playback statistics | |
| STATISTICS_INITIAL= 1, for initial statistics when playback starts | |
| STATISTICS_HTTP= 2, for HTTP statistics during playback | |
| STATISTICS_SYSTEM= 3, for system statistics during HLS, DASH, or SS playback |
| Name | Description |
|---|---|
| map | The updated statistics object as a HashMap. |
An enumeration defining the possible types of HLS, DASH, or SS media can be played by NexPlayer.
These media types include:
NONE= 0: No media file found.AUDIO = 1: Audio content.BASEVIDEO = 2: Base video content.TEXT = 4: Text content or subtitles.ENHANCEDVIDEO = 8: Enhanced video content.
See Also
- GeneralStatistics
- isMediaExist( MediaType mediaType, int mediaComposition )
Gets the integer code for the MediaType.
Returns
The integer code for the specified MediaType.
This method indicates whether or not the requested media exists in the current content.
This method can be used to check if the current content contains the specific media (AUDIO,BASEVIDEO,TEXT,ENHANCEDVIDEO) based on the mediaComposition value received.
Parameters
| Name | Description |
|---|---|
| mediaType | The type of media to check. This will be one of: •AUDIO (0x00000001): for audio media. •BASEVIDEO (0x00000002): for base video. •TEXT (0x00000004): for text or subtitles. •ENHANCEDVIDEO (0x00000008): for enhanced video. |
| mediaComposition | The composition of the specified media, as an integer. |
Returns
TRUE if the media indicated exists, or FALSE if it does not exist in the current content.