Private Video Delivery With Mp4 Built In Players

api.video recommends that you read Private Videos to ensure that you understand the concept of private videos before proceeding.

There are cases where you would want to use built-in players that are not api.video. We support private video delivery via other players other than our in-house. In this article you can find how to deliver private videos with MP4 built-in player

MP4 private video url

Playing your private video on an MP4 player, like video.js or Android native player is as easy as just passing on the url we provide while you retrieve for example, if you would like to play the video on video.js, we provide a ready made url with mp4 extension :

https://vod.api.video/vod/ABC/token/XYZ/mp4/source.mp4

Serving private videos to HTML on Chrome, Mozilla or Safari:

You can use the video tag directly to play the video in a browser, for example:

<html>
  <head>
  </head>
  <body>
    <video height="30%" width="30%" controls>
        <source src='https://vod.api.video/vod/{video id}/token/{private token}/hls/manifest.m3u8'>
    </video>
  </body>
</html>

Serving private videos dynamically

In order to build a dynamically served private videos, you can leverage the /videos endpoint in order to get the url of the video and private token. For example the following steps are possible:

  • Make a request to /videos endpoint
curl --request GET \
     --url https://ws.api.video/videos/ABC \
     --header 'accept: application/json' \
     --header 'authorization: Basic ZYX='
  • You will get the following response, where the private token in the url and you can get the mp4 url from the mp4 field:
{
  "videoId": "ABC",
  "title": "test video",
  "description": "something that I wanted to share",
  "public": false,
  "panoramic": false,
  "mp4Support": true,
  "publishedAt": "2023-01-19T10:19:19+00:00",
  "createdAt": "2023-01-19T10:19:19+00:00",
  "updatedAt": "2023-01-26T16:55:41+00:00",
  "tags": [],
  "metadata": [],
  "source": {
    "type": "upload",
    "uri": "/videos/ABC/source"
  },
  "assets": {
    "iframe": "<iframe src=\"https://embed.api.video/vod/ABC?token=XYZ\" width=\"100%\" height=\"100%\" frameborder=\"0\" scrolling=\"no\" allowfullscreen=\"true\"></iframe>",
    "player": "https://embed.api.video/vod/ABC?token=XYZ",
    "hls": "https://vod.api.video/vod/ABC/token/XYZ/hls/manifest.m3u8",
    "thumbnail": "https://vod.api.video/vod/ABC/token/XYZ/thumbnail.jpg",
    "mp4": "https://vod.api.video/vod/ABC/token/XYZ/mp4/source.mp4"
  }
}
  • All you have to do now is to get the mp4 url and pass it as a value to the HTML that will be generated by the server. We will handle the rest.

Private video delivery on Android native player

You can follow the same steps as you've seen above to retrieve the video url and pass it to the native Android media player, like the example below.

Reference can be found here: https://developer.android.com/guide/topics/media/mediaplayer

String url = "https://vod.api.video/vod/ABC/token/XYZ/mp4/source.mp4";
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioAttributes(
    new AudioAttributes.Builder()
        .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
        .setUsage(AudioAttributes.USAGE_MEDIA)
        .build()
);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();

Was this page helpful?