Video and Playlist Objects from JSON

Product(s)
Video Cloud
Brightcove Player
Role(s)
Device SDK Developer
Task(s)
Add Videos/Assets
Topic(s)
Playback
SDK
Android
In this topic, you will learn how to create playable video and playlist objects by calling helper methods in the Brightcove Native SDK for Android with the required JSON-formatted data.

Overview

As of version 6.2.0+, the Brightcove Native SDK for Android supports methods for creating video and playlist objects from a JSON object.

This is useful if you want to use a server-side proxy to retrieve video and playlist data from your Brightcove account. With this approach, you won't expose your Policy Keys on the client side of your apps.

To create a playable video and playlist object, do the following:

  1. Optional: Make a server-side call to the Playback API to return your video or playlist data.
  2. Create a JSON-formatted object based on the required fields below.
  3. Pass in the JSON-formatted object and call the appropriate method to create the following:
  4. Load the returned video or playlist into your player.

Video objects

To create a video object, pass the following information to the buildVideoFromJSON() method:

Field Description
account_id The account id associated with the video
id The video id
sources A JSON array of video sources. Each source in the array must have:
  • A src field with a valid URL to content
  • For HLS or DASH content, a type field with the mime type of the content
  • For MP4 content, a container field with the value MP4
duration The video duration in milliseconds

When your server-side proxy returns video data, build a JSON object string with the values specified in the table above.

{
  "account_id": "3636334163001",
  "sources": [
  {
    "src": "http://f1.media.brightcove.com/4/36356334163001/3636334163001_3637454559001_Cascada-Teaser.mp4",
    "container": "MP4"
  }, {
    "type": "application/x-mpegURL",
    "src": "http://c.brightcove.com/services/mobile/streaming/index/master.m3u8"
  }],
  "id": "3637780364001",
  "duration": 74700
}

Convert the JSON string to a JSON object and pass it to the to the buildVideoFromJSON() method:

try {
   JSONObject jsonObject = new JSONObject(response);
   Video video = VideoParser.buildVideoFromJSON(jsonObject, eventEmitter);
  } catch (JSONException e) {
    e.printStackTrace();
  } catch (VideoParseException e) {
    e.printStackTrace();
  }

Playlist objects

To create a playlist object, pass the following information to the buildPlaylistFromJSON() method:

Field Description
account_id The account id associated with the video
id The video id
videos A JSON array of video objects. This includes the required fields as described in the Video objects section.
duration The video duration in milliseconds

When your server-side proxy returns playlist data, build a JSON object string with the values specified in the table above.

{
  "id": "4970066630001",
  "account_id": "3636335163001",
  "name": "token auth playlist",
  "videos": [{
    "account_id": "3636335763001",
    "id": "4973773347001",
    "sources": [{
      "type": "application/dash+xml",
      "src": "https://brightcove.hs.llnwd.net/v2/unsecured/media/3636334163001/201606/1923/3636334163001_4973820156001_4973773237001.mpd"
    }],
    "duration": 29000
    },
    {
    "account_id": "3636334463001",
    "id": "4973766826001",
    "sources": [{
      "type": "application/dash+xml",
      "src": "http://brightcove.vo.llnwd.net/v1/unsecured/media/3636334163001/201606/2933/3636334163001_4973816542001_4973737826001.mpd"
    }],
    "duration": 29000
    }
  ]
}

Convert the JSON string to a JSON object and pass it to the buildPlaylistFromJSON() method:

try {
   JSONObject jsonObject = new JSONObject(response);
   Playlist playlist = VideoParser.buildPlaylistFromJSON(jsonObject, eventEmitter);
  } catch (JSONException e) {
    e.printStackTrace();
  } catch (VideoParseException e) {
    e.printStackTrace();
  }

Notes

If your content is governed by TTL (Time to live) and you want to create a long-lived video object, you will need to ensure it continues to be playable. This is configured on the CDN that you are using.