All Products
Search
Document Center

Video playback

Last Updated: Jan 04, 2021

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 PHP. 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:

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

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:

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";
}