MediaPlayerNotification objects provide information about changes in player state, warnings, and errors. Errors that stop the playback of the video also cause a change in the state of the player.
Your application can retrieve the notification and state information. You can also create a logging system for diagnostics and validation by using the notification information.
You implement event listeners to capture and respond to events. Many events provide MediaPlayerNotification status notifications.
MediaPlayerNotification provides information that is related to the player's status.
TVSDK provides a chronological list of MediaPlayerNotification notifications. Each notification contains the following information:
- Time stamp
- Diagnostic metadata that consists of the following elements:
- type : INFO, WARN, or ERROR.
- code : A numerical representation of the notification.
- name : A human-readable description of the notification, such as SEEK_ERROR
- metadata : Key/value pairs that contain relevant information about the notification. For example, a key named URL provides a value that is a URL related to the notification.
- innerNotification : A reference to another MediaPlayerNotification object that directly impacts this notification.
You can store this information locally for later analysis or send it to a remote server for logging and graphical representation.
Set up your notification system
You can listen for notifications and you can add your own notifications to the notification history.
The core of the Primetime Player notification system is the Notification class, which represents a standalone notification.
The NotificationHistory class provides a mechanism for accumulating notifications. It stores a log of notification (NotificationHistoryItem) objects that represents a collection of Notifications.
To receive notifications:
- Listen for notifications
- Add notifications to the notification history
- Listen for state changes.
- Implement the MediaPlayer.PlaybackEventListener.onStateChanged callback.
- TVSDK passes two parameters to the callback:
- The new state ( MediaPlayer.PlayerState )
- A MediaPlayerNotification object
Add real-time logging and debugging
You can use notifications to implement real-time logging in your video application.
The notification system allows you to gather logging and debugging information for diagnostics and validation without overly stressing the system.
The logging back end is not part of a production setup and is not expected to handle high-load traffic. If your implementation does not need to be absolutely complete, consider the efficiency of data transmission to avoid overloading your system.
Here is an example of how to retrieve notifications.
- Create a timer-based execution thread for your video application that periodically queries the data gathered by the TVSDK notification system.
- If the timer's interval is too large and the size of the event list is too small, the notification event list will overflow. To avoid this overflow, do one of the following:
- Decrease the time interval that drives the thread that polls for new events.
- Increase the size of the notification list.
- Serialize the latest notification event entries in JSON format and send the entries to a remote server for postprocessing.The remote server could then graphically display the provided data in real-time.
- To detect the loss of notification events, look for gaps in the sequence of event index values.Each notification event has an index value that is automatically incremented by the session.NotificationHistory class.