This topic provides examples on how to use the API operations of the video playback module. The API operations are encapsulated in ApsaraVideo VOD SDK for Node.js. You can call the API operations to query playback URLs and playback credentials.
Initialize a client
Before you can use the SDK, initialize a client. For more information, see Initialization.
Query a playback URL
You can call the GetPlayInfo operation to query a playback URL.
For more information about the request and response parameters of this operation, see GetPlayInfo. Example:
// Call example
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
client.request("GetPlayInfo", {
VideoId: 'VideoId'
}, {}).then(function (response) {
// play 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);
}
}
// base metadata
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);
});
Query a playback credential
You can call the GetVideoPlayAuth operation to query a playback credential.
For more information about the request and response parameters of this operation, see GetVideoPlayAuth. Example:
// Call example
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
client.request("GetVideoPlayAuth", {
VideoId: 'VideoId'
}, {}).then(function (response) {
// play auth
console.log('PlayAuth = ' + response.PlayAuth);
// base 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);
});