The mini drama solution allows you to call API operations to use Alibaba Cloud CDN for playback acceleration. This topic describes how to call API operations to accelerate the delivery of mini dramas.
Delivery and playback
Overview
ApsaraVideo VOD supports audio and video playback. You can preview audio and video files in the ApsaraVideo VOD console and play the files by using ApsaraVideo Player SDK or third-party players.
ApsaraVideo VOD allows you to play the following types of audio and video files:
Transcoded stream files: If you specify a transcoding template when you upload audio and video files, transcoded stream files are generated.
Original files: If you use the No Transcoding template when you upload audio and video files, the files are played in the original quality. You can play only audio and video files in the MP4, FLV, M3U8, MP3, and WEBM formats in the original quality without transcoding.
Playback modes
Play videos based on their playback URLs
After you obtain the playback URL of an audio or video file stored in ApsaraVideo VOD, you can use the playback URL to play the file by using ApsaraVideo Player or third-party players including the system player, open source player, and self-developed player. This topic describes how to obtain playback URLs and play audio and video files stored in ApsaraVideo VOD.
Use playback credentials to play videos
If you have higher security requirements for the playback of audio and video files stored in ApsaraVideo VOD, you can obtain playback URLs by using ApsaraVideo Player SDK and playback credentials. Each playback credential can be used to obtain the playback URL only for a specific video in a specific period of time. You cannot obtain the playback URL if the credential expires or is incorrect. This topic describes how to call an operation to obtain a playback credential for an audio or video file and use ApsaraVideo Player SDK to play the audio or video file.
Obtain a playback URL
You can obtain playback URLs from event notifications or by using the API or SDK.
Event notifications
You can obtain the playback URL from the StreamTranscodeComplete or TranscodeComplete callback. Save the playback URL on your server and access your server to play the file.
The playback URLs obtained from callbacks are fixed URLs. If URL signing is enabled, you must generate a signed URL for playback. In this case, you can play the file only by using the signed URL.
If the old domain name is disabled or deleted, replace the domain name in the playback URL with the new domain name. Otherwise, video playback fails.
If video encryption is configured, the returned playback URL must be decrypted before the video can be played.
API/SDK
You can call the GetPlayInfo operation or call the operation by using the ApsaraVideo VOD SDK. When you call this operation, specify the video ID that you obtained during the upload to obtain the playback URL. Demo:
We recommend that you use the more secure STS access method. For more information about authentication access methods, see Manage access 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
You can call the GetVideoPlayAuth operation to query the credential required for media playback. ApsaraVideo Player SDK automatically obtains the playback URL based on the playback credential. 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);
}
}
}Common issues and solutions to the issues
Troubleshoot video playback errors:
Prerequisites
The playback URL is obtained by using the ApsaraVideo console, API, or SDK.
Procedure
Log on to the ApsaraVideo VOD console.
In the left-side navigation pane, choose Check Tool > Troubleshooting.
On the Troubleshooting page, enter the playback URL of the video that you want to check, select the domain type from the drop-down list, and then click Check.
Handle the detected exceptions by referring to the provided suggestions.
Note
If the playback URL of the video is not changed after you handle the exceptions, click Check Again on the Check Result page. If the playback URL is changed, return to the Troubleshooting page and enter the new playback URL to recheck the URL.
The following table describes the check items for a playback URL that includes 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.
The following table describes the check items for a playback URL that includes 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.