Using MediaPlayerItemLoader helps you obtain information about a media stream without instantiating a MediaPlayer instance. This is especially useful in pre-buffering streams so that playback can begin without delay.
The MediaPlayerItemLoader
class helps you exchange a media resource for the current MediaPlayerItem
without attaching a view to a MediaPlayer
instance, which would allocate video decoding hardware resources. Additional steps are necessary for DRM-protected content, but this manual does not describe them.
TVSDK does not support a single QoSProvider
to work with both itemLoader
and MediaPlayer
. If your application uses Instant On, the application needs to maintain two QoS
instances and manage both instances for the information. See instant-on for more information.
Create an instance of MediaPlayerItemLoader
.
private MediaPlayerItemLoader createLoader() {
MediaPlayerItemLoader itemLoader =
new MediaPlayerItemLoader(this, new MediaPlayerItemLoader.LoaderListener() {
public void onError(PSDKErrorCode mediaErrorCode, String description) {
//Do something
}
public void onLoadComplete(MediaPlayerItem playerItem) {
loader.prepareBuffer();
}
public void onBufferingBegin() {
//Do something
}
public void onBufferPrepared() {
mPlayer.reset();
}
});
itemLoader.setKeepRebufferingForLive(true);
return itemLoader;
}
Create a separate instance of MediaPlayerItemLoader
for each resource. Do not use one MediaPlayerItemLoader
instance to load multiple resources.
Implement the ItemLoaderListener
class to receive notifications from the MediaPlayerItemLoader
instance.
private MediaPlayerItemLoader createLoader() {
MediaPlayerItemLoader itemLoader =
new MediaPlayerItemLoader(this, new MediaPlayerItemLoader.LoaderListener() {
public void onError(PSDKErrorCode mediaErrorCode, String description) {
//Do something
}
public void onLoadComplete(MediaPlayerItem playerItem) {
loader.prepareBuffer();
}
public void onBufferingBegin() {
//Do something
}
public void onBufferPrepared() {
mPlayer.reset();
}
} );
itemLoader.setKeepRebufferingForLive(true);
return itemLoader;
}
In the onLoadComplete()
callback, do one of the following:
prepareBuffer()
to take advantage of instant on.MediaPlayer
instance by using replaceCurrentItem()
.If you call prepareBuffer()
, you receive the BUFFER_PREPARED event in your onBufferPrepared
handler when the preparation is finished.
Call load
on the MediaPlayerItemLoader
instance and pass the resource to be loaded, and optionally the content ID, and a MediaPlayerItemConfig
instance.
loader = createLoader();
MediaResource res = new MediaResource(mVideoUrl, MediaResource.Type.HLS, metadata);
loader.load(res, 233, getConfig());
To buffer from a point other than the beginning of the stream, call prepareBuffer()
with the position (in milliseconds) at which to start buffering.
Use the replaceCurrentItem()
and play()
methods of MediaPlayer
to start playing from that point.
Wait for idle status and call replaceCurrentItem
.
Play the item.
If the item is loaded but not buffered:
prepareToPlay()
.play()
.If the item is buffered:
play()
.