Play a video¶
This guide shows how to get the stream of a video and start the playback in your player. Use the same steps for a film, an episode and a trailer.
Before you start¶
Make sure that:
- Your code can sign requests. See Sign a request.
- For paid videos: the user has an access token. See Authorize a user.
- Your player supports the protocols and the DRM systems that MEGOGO set for your key. See Credentials.
WARNING
The Content API gives the stream of an fvod or advod video without
a user. These videos are part of your subscription. Before you request
the stream, make sure that the user has your subscription.
The flow¶
sequenceDiagram
participant App as Partner application
participant Server as Partner server
participant API as MEGOGO Content API
participant CDN as MEGOGO CDN
App->>Server: The user selects "Watch"
Server->>Server: Check the access of the user
Server-->>App: Signed URL of /stream
App->>API: GET /stream
API-->>App: src, drm_type, audio_tracks, subtitles
App->>CDN: GET src (manifest)
CDN-->>App: Video
Step 1. Get the signed URL¶
Your server makes the signed URL of /stream. Then the private key stays
on your server.
| Parameter | Required | Description |
|---|---|---|
video_id |
Yes | The ID of the film, the episode or the trailer |
lang |
No | The language of the text in the response, for example en |
access_token |
For paid videos | The access token of the user |
sign |
Yes | The signature of all other parameters, in the URL order |
https://api.megogo.net/v1/stream?video_id={video_id}&lang=en&access_token={access_token}&sign={sign}
For a series, send the ID of an episode. Get the episode IDs from the XML
feed (seria@id) or from the Content API. /video/info gives the seasons
(season_list) and the episodes of the first season. For the other
seasons, send /video/episodes?id={season_id}. If you send the ID of the
series to /stream, the response gives the first episode.
For a trailer, send the trailer ID (trailer_id in /video/info, or
trailer@id in the feed). Do not send access_token.
Step 2. Send the request from the device of the user¶
Send the request from the application on the device, not from your server. MEGOGO finds the country of the user from the IP address of the request.
If your server must send the request, tell your MEGOGO manager. MEGOGO then sets a fixed region for your key. You are responsible for the location of your users.
WARNING
Send /stream only when the user starts the playback. For a rented
(TVOD) video, the first response with src starts the rent period. Do
not send the request to prepare or to check the stream.
Step 3. Check the response¶
Expected response for a video that the user can watch (shortened):
{
"result": "ok",
"code": 200,
"data": {
"video_id": 12345,
"title": "Example film",
"src": "https://…/playlist.m3u8?…",
"stream_type": "hls",
"content_type": "vod",
"drm_type": "",
"license_server": "",
"play_start_time": 0,
"credits_start": 5400,
"bitrates": [ … ],
"audio_tracks": [ … ],
"subtitles": [ … ]
}
}
- If
resultiserror, see Errors. - If
srcis empty, the user cannot watch the video. Readrestrictions[].codeand do the action in the table below. - If
srcis not empty, go to step 4.
restrictions[].code |
Cause | Action |
|---|---|---|
NOT_PURCHASABLE |
The user has no subscription or purchase for this video, or access_token is not in the request |
Offer a subscription or a purchase. If the user has a service, get a new access token |
CONTRACT, NO_CONTRACT |
The video is not in your contract | Do not show the video |
NO_VOD_COUNTRY, NOT_ENABLED_IN_COUNTRY |
The video is not available in the country of the user | Tell the user that the video is not available in this country |
NO_BITRATE |
No video quality is available for your key. For example, the video is a 4K version, and 4K is not set for your key | Do not show the video with this key. To show 4K videos, ask your MEGOGO manager |
NO_DRM_SUPPORT, DRM |
The video has DRM, but your key does not support it | Do not show the video with this key. Ask your MEGOGO manager about DRM for your platform |
PARTNER_IS_DISABLED |
Your key is disabled | Tell your MEGOGO manager |
Do not show restrictions[].message to the user as the reason. The text
is generic.
Step 4. Start the playback¶
- Give
srcto your player.stream_typetells the protocol:hls,dashormss. -
If
drm_typeis not empty, set the DRM license URL in your player:drm_typeDRM system Stream format Data for the player modularWidevine DASH license_serverplayreadyPlayReady DASH license_serverfairplayFairPlay HLS license_serverandlicense_certificateMEGOGO sets the DRM system for each key. Only videos with DRM in the feed (
protectionother than0) come with DRM. Videos without DRM come in the protocol that MEGOGO set for your key (for example HLS). Use the key of the platform where the user watches the video. See Credentials. -
If you show a quality menu, use
bitrates. Each item has its ownsrcandlicense_server. A 4K version (is_uhd: true) has only the 2160 bitrate.is_hdr: truemeans that the video is HDR. - To continue from the last position, start the playback at
play_start_time(seconds). - Select the audio track and the subtitles. See Change playback settings.
For an episode, the response also has root_video_id (the series),
prev and next (the previous and the next episode IDs). Use next to
play the next episode. The first episode has no prev. The last episode
has no next.
credits_start is the start of the end credits, in seconds. You can use
it to offer the next episode.
WARNING
src contains data of the user. Do not keep src in a cache, do not
write it to logs and do not share it. Send a new /stream request each
time the user starts the playback.
Ignore the field advert_url.
Errors¶
| Response | Cause | Action |
|---|---|---|
HTTP 400, "message": "You entered wrong sign key" |
The signature is not correct | Make sure that the signature has all parameters in the URL order, also access_token. See Sign a request |
HTTP 200, "result": "error", "code": 400 |
video_id is not in the request or is not a number |
Send a correct video_id |
HTTP 200, "result": "error", "code": 403 |
The access token is not correct or expired | Get a new access token. See Authorize a user |
HTTP 200, "result": "error", "code": 404 |
The video is not found | Do not show the video. Remove it from your catalog |
HTTP 200, "result": "ok", empty src |
The user cannot watch the video | Read restrictions (step 3) |
| HTTP 429 | Too many requests | Send fewer requests |