阿里云首页 视频点播

音视频播放

本篇文档提供了Node.js SDK音视频播放模块相关功能的API调用示例。包含获取播放地址、获取视频播放凭证。

初始化客户端

使用前请先初始化客户端,请参见初始化

获取播放地址

调用GetPlayInfo接口,完成获取播放地址功能。

接口参数和返回字段请参见GetPlayInfo。调用示例如下:

// 调用样例
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);
});

获取视频播放凭证

调用GetVideoPlayAuth接口,完成获取视频播放凭证功能。

接口参数和返回字段请参见GetVideoPlayAuth。调用示例如下:

// 调用样例
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);
});