This topic describes the main media playback use cases for the NaCl Player API.
The NaCl (Native Client) Player API allows you to play content from URL or elementary stream sources, with or without DRM protection and subtitles.
For more information on code implementation, see API Usage and Developing Playback Applications.
You can use the URLDataSource class to play content from a specified URL, with or without platform-supported DRM protection. You can also implement subtitles.
To implement playback from a URL data source:
You can use the ESDataSource class to play content containing elementary streams demuxed by the application, with or without platform-supported or custom DRM protection. You can also implement external subtitles.
Application logic may be using player in push or pull mode. In push mode the application controls when data should be sent. In pull mode player sends events to application indicating when data should be sent.
To implement playback from elementary stream sources:
Create a MediaPlayer object.
Create objects derived from the MediaEventsListener and BufferingListener classes, and register them in the MediaPlayer object.
Register optional listeners:
To implement subtitles, create an object derived from the SubtitleListener class and register it in the MediaPlayer object, and call the MediaPlayer::AddExternalSubtitles() function to specify the external subtitle URL.
To implement platform-supported DRM decryption, create an object derived from the DRMListener class and register it in the MediaPlayer object.
Create an ESDataSource object.
If in pull mode, implement class derived from the ElementaryStreamListener, and create one instance of it for each elementary stream (of course you can implement more than one class, e.g. one for audio stream and other for video stream).
Add video and audio streams to the ESDataSource object:
Attach the ESDataSource object to the media player by calling the MediaPlayer::AttachDataSource() function.
To implement platform-supported DRM, handle the DRMListener::OnLicenseRequest() event:
To buffer packets from the VideoElementaryStream and AudioElementaryStream objects:
The packets are decoded and the resulting video and audio are presented.
When the BufferingListener::OnBufferingComplete() event notifies that enough data has been buffered and playback can be started, call the MediaPlayer::Play() function to start playback.
To implement subtitles, handle the SubtitleListener::OnShowSubtitle() event to display the received subtitle for a specified duration.
To continue playback, continue buffering video and audio packets if in push mode, or handle ElementaryStreamListener events appropriately if in pull mode.
To change the stream representation during playback:
When the streams end, call the ESDataSource::SetEndOfStream() function.