Create a media resource

The MediaResource class represents the content that is about to be loaded by the MediaPlayer class.

  1. Create a MediaResource by passing information about the media to MediaResource.createFromUrl.
    Parameter Description
    URL Required. The location of the manifest/playlist for the content to be loaded.
    Metadata Required when using the MediaResource with the createFromUrl method. Otherwise, pass null. An instance of the Metadata class (a dictionary-like structure). This structure might contain additional information about the content that is about to be loaded, such as information about alternate or ad content to place inside the main content.
    try {
      // create a MediaResource instance pointing to some HLS content
      Metadata metadata = //TODO: create metadata 
      MediaResource mediaResource =
          MediaResource.createFromUrl("http://www.example.com/video/some-video.m3u8", metadata);
    } catch(IllegalArgumentException ex) {
      // this exception is thrown if the URL does not point to a valid url.
    }
    
  2. Check the media type and optionally retrieve other information about the media:
    Important: Currently, the Android PSDK supports only HLS content. If you attempt to load content of type other than HLS, such as HDS, the PSDK dispatches an error event.
    Method Returns
    getType The type of the content to be loaded. Usually you can detect the type of the resource from the URL, but sometimes when custom naming schemes are involved, this is not possible. This is a simple enumeration, MediaResource.Type, which defines the types of content that can be loaded by the MediaPlayer. This enumeration defines two values: HLS and HDS. Each value is associated with the string representing the file extensions commonly used: "m3u8" for HLS and "f4m" for HDS, respectively.
    getUrl The URL of the location of the manifest/playlist for the content to be loaded.
    getMetadata An instance of the Metadata class (a dictionary-like structure). This structure contains additional optional information about the content that is about to be loaded.
  3. Load the media resource in either way:
    • Load it directly inside the MediaPlayer

    • Load it using MediaPlayerItemLoader