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 request and response parameters, see GetPlayInfo.

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

Obtain the video playback credential

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

function getPlayAuth($client, $videoId) {
    $request = new vod\GetVideoPlayAuthRequest();
    $request->setVideoId($videoId); 
    $request->setAuthInfoTimeout(3600); 
    $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"; 
}