Another way to resolve a media resource is with MediaPlayerItemLoader. This is useful when you want to obtain information about a particular media stream without the full instantiation of a MediaPlayer instance.
Through the MediaPlayerItemLoader class, you can exchange a media resource for the corresponding MediaPlayerItem without attaching a view to a MediaPlayer instance, which would lead to the allocation of the video decoding hardware resources. The process of obtaining the MediaPlayerItem instance is asynchronous.
// instantiate the listener interface
MediaPlayerItemLoader.LoaderListener _itemLoaderListener =
new MediaPlayerItemLoader.LoaderListener() {
@Override
public void onError(MediaErrorCode mediaErrorCode, String description) {
// something went wrong - look at the error code and description
}
@Override
public void onLoadComplete(MediaPlayerItem playerItem) {
// information is available - look at the data in the "playerItem" object
}
}
// instantiate the MediaPlayerItemLoader object (pass the listener as parameter)
MediaPlayerItemLoader itemLoader = new MediaPlayerItemLoader(_itemLoaderListener);
// create the MediaResource instance and set the URL to point to the actual media stream
MediaResource mediaResource = MediaResource.createFromUrl("http://example.com/media/test_media.m3u8", null);
// load the media resource
itemLoader.load(mediaResource);