For each new video content, initialize a MediaResource instance with information about the video content and load the media resource. The MediaResource class represents the content to be loaded by the MediaPlayer instance.
Create a MediaResource
by passing information about the media to the MediaResource
constructor.
Constructor Parameter | Description |
---|---|
url |
A string that represents the URL of the manifest/playlist of the media. |
type |
One of the following members of the MediaResource.Type enumeration that corresponds to the indicated file type:
|
metadata |
An instance of the Metadata class, which might contain custom information about the content to be loaded. Examples of content are alternate or ad content to place inside the main content. If using advertising, set up AuditudeSettings . For more information, see Ad Insertion Metadata . |
TVSDK supports playback for only specific types of content. If you attempt to load any other type of content, TVSDK dispatches an error event.
For MP4 video-on-demand (VOD) content, TVSDK does not support trick play, adaptive bit rate (ABR) streaming, ad insertion, closed captions, or DRM.
The following code creates a MediaResource
instance:
try {
// create a MediaResource instance pointing to some HLS content
Metadata metadata = //TODO: create metadata
MediaResource mediaResource = MediaResource.createFromUrl(
"https://www.example.com/video/some-video.m3u8",
MediaResource.Type.HLS,
metadata);
} catch(IllegalArgumentException ex) {
// this exception is thrown if the URL does not point
// to a valid url.
}
At this point, you can use MediaResource
accessors (getters) to examine the resource’s type, URL, and metadata.
Load the media resource by using the following:
Your MediaPlayer instance.
For more information, see Load a media resource in the MediaPlayer.
A MediaPlayerItemLoader
For more information, see Load a media resource using MediaPlayerItemLoader.
Do not load the media resource on a background thread. Most TVSDK operations need to be run on the main thread, and running them on a background thread can cause the operation to throw an error and exit.