CDN acceleration

更新时间:
复制 MD 格式

Use API operations to accelerate mini drama delivery through Alibaba Cloud CDN, including obtaining playback URLs and credentials.

Delivery and playback

Overview

ApsaraVideo VOD supports audio and video playback. You can preview files in the console and play them through ApsaraVideo Player SDK or third-party players.

Supported file types:

  • Transcoded stream files: Generated when you specify a transcoding template during upload.

  • Original files: Played in original quality when you use the No Transcoding template. Supported formats: MP4, FLV, M3U8, MP3, and WEBM.

Playback modes

  • Play videos based on their playback URLs

After obtaining a playback URL, play the file through ApsaraVideo Player or third-party players (system, open source, or custom).

  • Use playback credentials to play videos

For higher security requirements, use ApsaraVideo Player SDK with playback credentials. Each credential grants access to a specific video for a limited time — expired or invalid credentials are rejected.

Obtain a playback URL

Obtain playback URLs through event notifications or the API/SDK.

  • Event notifications

Obtain the playback URL from the StreamTranscodeComplete or TranscodeComplete callback, then save it on your server for playback.

Callback URLs are static. If URL signing is enabled, generate a signed URL — only the signed URL works for playback.

If a domain name is disabled or deleted, update the playback URL with the new domain name to avoid playback failure.

If video encryption is enabled, decrypt the playback URL before playback.

  • API/SDK

Call the GetPlayInfo operation directly or through the ApsaraVideo VOD SDK. Specify the video ID obtained during upload. Demo:

Important

Use STS for more secure access. For more information about authentication access methods, see Manage credentials.

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey pair to initialize the client.</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.vod20170321.Client createClient() throws Exception {
        // A leaked AccessKey pair can expose your account and all resources within the account to serious risks. The following sample code is provided for reference only.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        // For more information about endpoints, see https://api.aliyun.com/product/vod
        config.endpoint = "vod.cn-shanghai.aliyuncs.com";
        return new com.aliyun.vod20170321.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.vod20170321.Client client = Sample.createClient();
        com.aliyun.vod20170321.models.GetPlayInfoRequest getPlayInfoRequest = new com.aliyun.vod20170321.models.GetPlayInfoRequest();
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your code to print the response of the API operation if necessary.
            client.getPlayInfoWithOptions(getPlayInfoRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore exceptions in your project. In this example, error messages are displayed for your reference only.
            // Display error messages.
            System.out.println(error.getMessage());
            // The URL that is used for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore exceptions in your project. In this example, error messages are displayed for your reference only.
            // Display error messages.
            System.out.println(error.getMessage());
            // The URL that is used for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }        
    }
}

Obtain a playback credential

Call the GetVideoPlayAuth operation to obtain the playback credential. ApsaraVideo Player SDK then automatically retrieves the playback URL. Demo:

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey pair to initialize the client.</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.vod20170321.Client createClient() throws Exception {
        // A leaked AccessKey pair can expose your account and all resources within the account to serious risks. The following sample code is provided for reference only.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        // For more information about endpoints, see https://api.aliyun.com/product/vod
        config.endpoint = "vod.cn-shanghai.aliyuncs.com";
        return new com.aliyun.vod20170321.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.vod20170321.Client client = Sample.createClient();
        com.aliyun.vod20170321.models.GetVideoPlayAuthRequest getVideoPlayAuthRequest = new com.aliyun.vod20170321.models.GetVideoPlayAuthRequest();
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your code to print the response of the API operation if necessary.
            client.getVideoPlayAuthWithOptions(getVideoPlayAuthRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore exceptions in your project. In this example, error messages are displayed for your reference only.
            // Display error messages.
            System.out.println(error.getMessage());
            // The URL that is used for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore exceptions in your project. In this example, error messages are displayed for your reference only.
            // Display error messages.
            System.out.println(error.getMessage());
            // The URL that is used for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }        
    }
}

Troubleshoot playback errors

Troubleshoot video playback errors:

  1. Prerequisites

    You have obtained the playback URL from the ApsaraVideo VOD console, API, or SDK.

  2. Procedure

    1. Log on to the ApsaraVideo VOD console.

    2. In the left-side navigation pane, choose Tool > Troubleshooting.

    3. On the Troubleshooting page, enter the playback URL, select the domain type, and click Check.

    Follow the suggestions to resolve detected issues.

    1. Note

    If the URL remains unchanged after fixing issues, click Check Again on the Check Result page. If the URL changed, re-enter it on the Troubleshooting page.

    Check items for playback URLs with an Accelerated Domain Name:

    Check item

    Parameter

    Description

    Domain name

    Domain name status

    Checks the configuration status of the domain name.

    CNAME

    CNAME status

    Checks whether a CNAME record is configured for the domain name.

    SSL certificate

    Certificate status

    Checks the configuration status of the SSL certificate.

    Playback authentication

    URL signing

    Checks whether URL signing is enabled.

    Authentication status

    Checks whether URL signing is successful. If URL signing fails, the reason for the failure is provided.

    User-Agent blacklist or whitelist

    Type

    Checks the configuration status and type of the User-Agent blacklist or whitelist.

    Hotlink protection

    Status

    Checks whether hotlink protection is enabled.

    CORS

    Status

    Checks whether cross-origin resource sharing (CORS) is configured.

    Overdue payment

    ApsaraVideo VOD status

    Checks whether ApsaraVideo VOD is available.

    Payment status

    Checks whether overdue payments exist in your Alibaba Cloud account.

    Overdue payment status

    Checks whether the grace period for your overdue payments has elapsed.

    Check items for playback URLs with an OSS Domain Name:

    Check item

    Parameter

    Description

    OSS bucket

    ACL

    Checks the ACL of the Object Storage Service (OSS) bucket.

    Storage status

    Checks the storage configurations of the OSS bucket.

    Signature status

    Note: This parameter is displayed only when the ACL of the OSS bucket is private.

    Checks the signature status of the OSS bucket.