All Products
Search
Document Center

Audio and video playback

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Obtain the audio or video playback URL

For more information about the request and response parameters, see GetPlayInfo.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("GetPlayInfo", {
    VideoId: 'VideoId'
}, {}).then(function (response) {
    // The audio or video playback URL.
    if (response.PlayInfoList && response.PlayInfoList.PlayInfo && response.PlayInfoList.PlayInfo.length > 0){ 
        for (var i=0; i<response.PlayInfoList.PlayInfo.length; i++){ 
            console.log("PlayInfo.PlayURL = " + response.PlayInfoList.PlayInfo[i].PlayURL);
        }
    }
    // The basic information about the audio or video.
    if (response.VideoBase){
        console.log('VideoBase.Title = ' + response.VideoBase.Title);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Obtain the video playback credential

For more information about the request and response parameters, see GetVideoPlayAuth.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("GetVideoPlayAuth", {
    VideoId: 'VideoId'
}, {}).then(function (response) {
    // The video playback credential.
    console.log('PlayAuth = ' + response.PlayAuth);

    // The video metadata.
    if (response.VideoMeta){
        console.log('VideoMeta.Title = ' + response.VideoMeta.Title);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});