Integrating a Custom Video Player via API Integrating a Custom Video Player via API

Integrating a Custom Video Player via API

The Zype platform provides an out of the box solution for transcoding and delivering content to a customer’s end users without requiring any development effort. The out of the box solution uses THEOplayer as Zype’s player of choice for video content playback.

The Zype platform also provides APIs that provide access to the streaming materials used by the out of the box player solution so that a customer can play content using their own choice of player.

There are two different flows to provide video playback, depending on whether a video is monetized or not:

 

Unmonetized (Free) Playback

Unmonetized playback can be set up using either an API or app key. Zype provides two ways to request the playback URL for a video.

  • An optional parameter on the “List Videos” or “View Video” APIs.

  • A dedicated API endpoint or requesting the playback URL

Prerequisites

  • API Key or App Key is required for authentication

Instructions

To request the playback URL using the optional parameter on the “List Videos” or “View Video” APIs make a request to either of the following endpoints using your API key or app key.

To authenticate your request using your API key please see the following examples:

curl 'https://api.zype.com/videos?api_key=[API_KEY]'
curl 'https://api.zype.com/videos[VIDEO_ID]?api_key=[API_KEY]'

To include the playback URL on the video objects returned add manifest=true to the API calls. Please see the following examples:

curl 'https://api.zype.com/videos?api_key=[API_KEY]&manifest=true'
curl 'https://api.zype.com/videos[VIDEO_ID]?api_key=[API_KEY]&manifest=true'

This will include an additional element on the JSON video object named manifest which includes the playback URL.

{
  "_id": "5fda1c398f41010001117d3f",
  "active": true,
  "country": null,
  "created_at": "2020-12-16T09:39:53.445-05:00",
  "cue_in_offset": null,
  ...
  "transcoded": true,
  "vimeo_id": null,
  "youtube_id": null,
  "iconik_id": null,
  "subscription_required": false,
  "manifest": "https://player.zype.com/manifest/5fda1c398f41010001117d3f.m3u8?api_key=cmDk7ci6T3xXotHW5d3IVIHsP4FiUIgqUbAIj5MzkgCbnvef2VAQA-oWTfSYh8bQ"
}

To request the playback URL using the dedicated API endpoint option please see the following example:

curl 'https://api.zype.com/videos[VIDEO_ID]/manifest?api_key=[API_KEY]'

This API will return a code snippet similar to the following:

{
  "url": "https://player.zype.com/manifest/5fda1c398f41010001117d3f.m3u8?api_key=[API_KEY]"
}

NOTE: The playback URL will be scoped for playback to the IP address initially making the API request. If the request is being made from a server, and not the client machine where the video will be played this can cause an issue for playback. You can optionally supply the remote_ip of the request in order to scope the playback URL to the client where the video will be played. Please see the following example:

curl 'https://api.zype.com/videos[VIDEO_ID]/manifest?api_key=[API_KEY]&remote_ip=[REMOTE_IP]'

The playback URL can then be used to embed into a video player to provide video playback.

Monetized Playback

Monetized playback can be set up using an Oauth access token. Zype provides two ways to request the playback URL for a video.

  • An optional parameter on the “List Videos” or “View Video” APIs.

  • A dedicated API endpoint or requesting the playback URL

Prerequisites

  • OAuth access token is required for authentication.

Instructions

First use the OAuth API to authenticate a consumer and create an access token that can be used to authenticate the Zype API.

https://docs.zype.com/reference/retrieveaccesstoken-1

The OAuth API requires you to have the following information:

  • An application created, and the corresponding client_id and client_secret for the application.

  • A consumer created and the corresponding username and password for the consumer.

Once you have a consumer authenticated you can use the access token returned to authenticate API requests as a consumer.

To request the playback URL using the optional parameter on the “List Videos” or “View Video” APIs make a request to either of the following endpoints using your API key or app key.

To authenticate your request using your access token please see the following examples:

curl 'https://api.zype.com/videos?access_token=[ACCESS_TOKEN]'
curl 'https://api.zype.com/videos[VIDEO_ID]?access_token=[ACCESS_TOKEN]'

To include the playback URL on the video objects returned add manifest=true to the API calls. Please see the following examples:

curl 'https://api.zype.com/videos?access_token=[ACCESS_TOKEN]&manifest=true'
curl 'https://api.zype.com/videos[VIDEO_ID]?access_token=[ACCESS_TOKEN]&manifest=true'

This will include an additional element on the JSON video object named manifest which includes the playback URL.

{
  "_id": "5fda1c398f41010001117d3f",
  "active": true,
  "country": null,
  "created_at": "2020-12-16T09:39:53.445-05:00",
  "cue_in_offset": null,
  ...
  "transcoded": true,
  "vimeo_id": null,
  "youtube_id": null,
  "iconik_id": null,
  "subscription_required": false,
  "manifest": "https://player.zype.com/manifest/5fda1c398f41010001117d3f.m3u8?access_token=[ACCESS_TOKEN]"
}

To request the playback URL using the dedicated API endpoint option please see the following example:

curl 'https://api.zype.com/videos[VIDEO_ID]/manifest?api_key=[API_KEY]'

This API will return a code snippet similar to the following:

{
  "url": "https://player.zype.com/manifest/5fda1c398f41010001117d3f.m3u8?api_key=[API_KEY]"
}

NOTE: The playback URL will be scoped for playback to the IP address initially making the API request. If the request is being made from a server, and not the client machine where the video will be played this can cause an issue for playback. You can optionally supply the remote_ip of the request in order to scope the playback URL to the client where the video will be played. Please see the following example:

curl 'https://api.zype.com/videos[VIDEO_ID]/manifest?api_key=[API_KEY]&remote_ip=[REMOTE_IP]'

The playback URL can then be used to embed into a video player to provide video playback.

The playback URL requires the authenticated consumer to pass entitlement checks to see if the user has subscribed, purchased or returned the video (depending on video monetization settings). The playback URL will return a 403 error response unless the consumer successfully passes the entitlement check.

You can perform an entitlement check using the following API before attempting to play back the content to provide a user friendly error if the consumer is not entitled.

To authenticate your request using your access token please see the following example:

curl 'https://api.zype.com/videos[VIDEO_ID]/entitled?access_token=[ACCESS_TOKEN]'

If the user is entitled to play the video you will receive the following response with status code 200:

{
  "message": "entitled"
}

If the user is not entitled to play the video you will receive the following response with status code 422:

{
  "message": "You do not have permission to play this video"
}