音视频播放

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

初始化客户端

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

获取播放地址

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

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

function getPlayInfo($client, $videoId) {
    $request = new vod\GetPlayInfoRequest();
    $request->setVideoId($videoId);
    $request->setAuthTimeout(3600*24);
    $request->setAcceptFormat('JSON');
    return $client->getAcsResponse($request);
}
// 注意捕获异常
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $playInfo = getPlayInfo($client, 'videoId');
    print_r($playInfo->PlayInfoList->PlayInfo);
    var_dump($playInfo);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

获取视频播放凭证

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

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

function getPlayAuth($client, $videoId) {
    $request = new vod\GetVideoPlayAuthRequest();
    $request->setVideoId($videoId);
    $request->setAuthInfoTimeout(3000);
    $request->setAcceptFormat('JSON');
    $response = $client->getAcsResponse($request);
    return $response;
}
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $playAuth = getPlayAuth($client, 'videoId');
    print($playAuth->PlayAuth."\n");
    print_r($playAuth->VideoMeta);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}