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 C/C++. 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:

#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"

/* Query a playback URL. */

VodApiResponse getPlayInfo(VodCredential authInfo) {
    string apiName = "GetPlayInfo";
    map<string, string> args;
    args["VideoId"] = "<VideoId>"; // The ID of the video for which you want to query a playback URL.
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = getPlayInfo(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

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:

#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"

/* Query a playback credential. */

VodApiResponse getVideoPlayAuth(VodCredential authInfo) {
    string apiName = "GetVideoPlayAuth";
    map<string, string> args;
    args["VideoId"] = "<VideoId>";
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = getVideoPlayAuth(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}