Create a media resource

Last update: 2023-10-02

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.

  1. Create a MediaResource by passing information about the media to the MediaResource constructor.

    Constructor Parameter Description


    A string that represents the URL of the manifest/playlist of the media.


    One of the following members of the MediaResource.Type enumeration that corresponds to the indicated file type:

    • HLS - M3U8


    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(
    } 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.

  2. Load the media resource by using the following:


    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.

On this page