To use ApsaraVideo MediaBox SDK in your application, you must apply for a license. After you obtain a license, you must bind the license to your application to authorize the application to use Push SDK, short video SDK, ApsaraVideo Player SDK, or Queen SDK. This topic describes how to bind a license to a Web, iOS, or Android application.
Prerequisites
A license is applied for, and the license key and license file are obtained. For more information, see Apply for a license.
Authentication flowchart
As shown in the preceding figure, ApsaraVideo MediaBox SDK authenticates an application by using a license key and license file. The following table describes the configuration requirements for these.
Item | Required | Description | |||||
LicenseKey | Yes | The license key is used to request the latest license file. ApsaraVideo MediaBox SDK checks for an updated license file during initialization, followed by every 15 minutes once the application starts to run. | |||||
License file | No. We recommend that you configure a license file. | The built-in license file is used for authentication if a license file fails to be obtained from the server. For example, the built-in license file is used if the license file is not downloaded due to network issues. The license file includes the granted permissions and their validity period. To ensure a high authentication success rate in environments with weak network connectivity, we recommend that you proactively update the built-in license file whenever the granted permissions are changed. Note
|
If you do not want to configure a built-in license file, skip the related configurations when you bind a license to an application.
If no built-in license file is configured, authentication is complete based on the license file obtained from the server. This may cause authentication failures due to network issues. In addition, if you are using the application for the first time, you may need to wait until the license file is downloaded. The wait time depends on the actual network conditions.
Service environments for Player SDK
ApsaraVideo Player SDK V6.14.0 and later provides multiple service environments to ensure business compliance. After you select a service environment for ApsaraVideo Player SDK, the service center in the selected service environment provides the data required for license-based authentication and data related to playback quality. You can select a service environment based on your business requirements. The following table describes the available service environments.
Users of the Alibaba Cloud international site (alibabacloud.com) can only use the international environment. However, the global environment is configured for ApsaraVideo Player SDK V6.14.0 or later by default. To ensure smooth license-based authentication, update the service environment to the international environment for ApsaraVideo Player SDK.
Environment | Description | Suggestion |
Global environment (default) | Services are provided by the nodes in the China (Shanghai) region of Alibaba Cloud to ensure that the access and authorization requirements of global users are met. | This environment is suitable for business in the Chinese mainland. Note If you are a user of the Alibaba Cloud international site (alibabacloud.com), you can only use the international environment. If you want to use the global environment, contact Alibaba Cloud for technical support. |
International environment | This environment is designed for users of the Alibaba Cloud international site (alibabacloud.com). In this environment, services are provided by the nodes in the Singapore region to meet the compliance and performance requirements in specific regions. | This environment is suitable for business outside the Chinese mainland, including Hong Kong (China), Macao (China), and Taiwan (China). |
Bind a license to a Web application
Obtain the license key in the ApsaraVideo VOD console.
Configure the license information when you initialize the player, such as your domain name and the license key.
var player = new Aliplayer({ license: { domain: "example.com", // The domain name that you specify when you apply for a license. key: "example-key" // The license key displayed in the ApsaraVideo VOD console after you have applied for a license. } });
Wait until the initialization is complete. If no error message is returned after you initialize the player, the license is configured correctly..
NoteThe domain of the page where the player is embedded must be a subdomain of or have the same name as the domain you specified when applying for the license. Otherwise, the license verification fails. The localhost does not verify the domain name.
Bind a license to an Android application
Configure a license.
Recommended. Copy the license file to the assets directory of your Android Studio project.
NoteYou can also copy the license file to another directory on your device. If you do so, make sure that the value that corresponds to
com.aliyun.alivc_license.licensefile
for the global environment orcom.aliyun.alivc_license.licensefile_SEA
for the international environment is the same as the path of the license file.Add <meta-data> elements to the AndroidManifest.xml file.
ImportantIf the authentication fails after you configure the license, check whether the <meta-data> elements are added under the <application> element, and whether the names in the <meta-data> elements are correct. If the issue persists, troubleshoot the issue by referring to FAQ about licenses.
If you want to use ApsaraVideo Player SDK V6.14.0 or later on the Alibaba Cloud international site (alibabacloud.com), you must configure a license for the international environment. If you do not use ApsaraVideo Player SDK, you can configure a license for the global environment.
You can bind two licenses to your application at the same time: one for the global environment and one for the international environment. Then, you can specify the environment to use the player by configuring the service environment for ApsaraVideo Player SDK each time you start your application. You cannot switch the environment when the player is running.
// Configure a license for the global environment. This is the default configuration. <meta-data android:name="com.aliyun.alivc_license.licensekey" android:value="foIVziMaUHaRqgDyhf6b6eb8fcf014af39535d0720a32****"/> <!-- TODO: Specify the license key.--> <meta-data android:name="com.aliyun.alivc_license.licensefile" android:value="assets/cert/release.crt"/> <!-- TODO: Specify the path of your license file.--> // Configure a license for the international environment and add _SEA to the end of the license name. <meta-data android:name="com.aliyun.alivc_license.licensekey_SEA" android:value="f6b6foIVziMaUHaRqgDyheb8fcf014af39535d0a32720****"/> <!-- TODO: Specify the license key.--> <meta-data android:name="com.aliyun.alivc_license.licensefile_SEA" android:value="assets/cert/release.crt"/> <!-- TODO: Specify the path of your license file.-->
Configure a service environment for ApsaraVideo Player SDK. This step is required if you use the Alibaba Cloud international site (alibabacloud.com).
ApsaraVideo Player SDK V6.14.0 and later allows you to select a service environment. By default, the global environment is configured for ApsaraVideo Player SDK V6.14.0 and later. Users of the Alibaba Cloud international site (alibabacloud.com) cannot use the global environment. If you want to use the Alibaba Cloud international site (alibabacloud.com), you must update the service environment to the international environment for ApsaraVideo Player SDK by using the following method each time you start your application. Otherwise, authentication will fail for the license that authorizes your application to use ApsaraVideo Player SDK. You can ignore this step in scenarios such as using ApsaraVideo Player SDK of a version that is earlier than V6.14.0 or using other SDKs.
// When you use the Alibaba Cloud international site (alibabacloud.com), make sure that you have updated the service environment before calling an API operation of the player. This ensures that all subsequent services will run on the Alibaba Cloud international site (alibabacloud.com). // Update the service environment to the international environment by calling the following operation. You cannot alter the environment when the player is running. AlivcBase.getEnvironmentManager().setGlobalEnvironment(AlivcEnv.GlobalEnv.ENV_SEA);
Bind a license to an iOS application
Configure a license.
Recommended. Copy the license file
AliVideoCert-********.crt
to the AppSupportFiles directory of your Xcode project. You can also copy it to the sandbox directory or other directories that you prefer. Select the current project in Target Membership.Open the Info.plist file. Set the AlivcLicenseKey and AlivcLicenseFile parameters for the global environment, or the AlivcLicenseKey_SEA and AlivcLicenseFile_SEA parameters for the international environment to the license key and license file path you obtained when applying for the license.
ImportantIf you want to use ApsaraVideo Player SDK V6.14.0 or later on the Alibaba Cloud international site (alibabacloud.com), you must configure a license for the international environment. If you do not use ApsaraVideo Player SDK, you can configure a license for the global environment.
You can bind two licenses to your application at the same time: one for the global environment and one for the international environment. Then, you can specify the environment to use the player by configuring the service environment for ApsaraVideo Player SDK each time you start your application. You cannot switch the environment when the player is running.
// Configure a license for the global environment. This is the default configuration. <key>AlivcLicenseFile</key> <string>XXX</string> <key>AlivcLicenseKey</key> <string>foIVziMaUHaRqgDyhf6b6eb8fcf014af39535d0720a32****</string> // Configure a license for the international environment and add _SEA to the end of the license name. <key>AlivcLicenseFile_SEA</key> <string>XXX</string> <key>AlivcLicenseKey_SEA</key> <string>f6b6efoIVziMaUHaRqgDyhb8fcf014af39535d0a32072****</string>
Configure a service environment for ApsaraVideo Player SDK. This step is required if you use the Alibaba Cloud international site (alibabacloud.com).
ApsaraVideo Player SDK V6.14.0 and later allows you to select a service environment. By default, the global environment is configured for ApsaraVideo Player SDK V6.14.0 and later. Users of the Alibaba Cloud international site (alibabacloud.com) cannot use the global environment. If you want to use the Alibaba Cloud international site (alibabacloud.com), you must update the service environment to the international environment for ApsaraVideo Player SDK by using the following method each time you start your application. Otherwise, authentication will fail for the license that authorizes your application to use ApsaraVideo Player SDK. You can ignore this step in scenarios such as using ApsaraVideo Player SDK of a version that is earlier than V6.14.0 or using other SDKs.
// When you use the Alibaba Cloud international site (alibabacloud.com), make sure that you have updated the service environment before calling an API operation of the player. This ensures that all subsequent services will run on the Alibaba Cloud international site (alibabacloud.com). // Update the service environment to the international environment by calling the following operation. You cannot alter the environment when the player is running. AlivcBase.EnvironmentManager.globalEnvironment = ENV_SEA;