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, 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 Manage 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 contains 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 relies 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
Player SDK V6.14.0 or later provides multiple service environments to ensure business compliance. After you select a service environment, 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 China environment is configured for SDK V6.14.0 or later by default. To ensure smooth license-based authentication, update the service environment to international.
Environment | Description |
China | For users on the China site (default). Services are provided by the nodes in the China (Shanghai) region of Alibaba Cloud to ensure that the access and authorization requirements of users in China are met. |
International | For users on the 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. |
Bind a license to a web application
Obtain the license key in the ApsaraVideo VOD console.
Configure the license information such as your domain name and license key when you initialize the player.
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.
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, license verification will fail.
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 China 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 License FAQ.
To use Player SDK V6.14.0 or later on the Alibaba Cloud international site (alibabacloud.com), you must configure a license specifically for the international environment. If Player SDK is not used, you can configure a license for the China environment.
You can bind two licenses to your application at the same time: one for the China environment and the other for the international environment. When starting your application, you can specify which environment the player should use by configuring the service environment for Player SDK. The environment cannot be changed while the player is running.
// Configure a license for the China 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 manually add _SEA to the end. <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 Player SDK if you want to use the international environment.
Beginning with Player SDK V6.14.0, you can select a service environment, with the default configuration set to the China environment. To switch to the international environment, you must update the service environment to international using the provided method each time you start your application. Failure to do so will result in authentication failures for the license that authorizes your application to use Player SDK. This step is unnecessary if you are using Player SDK versions earlier than V6.14.0 or other SDKs.
// Before using the international environment, make sure that you have updated the service environment to international prior to calling any player API operations. This ensures that all subsequent services will run on the Alibaba Cloud international site (alibabacloud.com). // Update the service environment to international by calling the following operation. The environment cannot be changed while 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 China 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.
ImportantTo use Player SDK V6.14.0 or later on the Alibaba Cloud international site (alibabacloud.com), you must configure a license specifically for the international environment. If Player SDK is not used, you can configure a license for the China environment.
You can bind two licenses to your application at the same time: one for the China environment and the other for the international environment. When starting your application, you can specify which environment the player should use by configuring the service environment for Player SDK. The environment cannot be changed while the player is running.
// Configure a license for the China 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 manually add _SEA to the end. <key>AlivcLicenseFile_SEA</key> <string>XXX</string> <key>AlivcLicenseKey_SEA</key> <string>f6b6efoIVziMaUHaRqgDyhb8fcf014af39535d0a32072****</string>
Configure a service environment for Player SDK if you want to use the international environment.
Beginning with Player SDK V6.14.0, you can select a service environment, with the default configuration set to the China environment. To switch to the international environment, you must update the service environment to international by using the following method each time you start your application. Failure to do so will result in authentication failures for the license that authorizes your application to use Player SDK. This step is unnecessary if you are using Player SDK versions earlier than V6.14.0 or other SDKs.
// Before using the international environment, make sure that you have updated the service environment to international prior to calling any player API operations. This ensures that all subsequent services will run on the Alibaba Cloud international site (alibabacloud.com). // Update the service environment to international by calling the following operation. The environment cannot be changed while the player is running. AlivcBase.EnvironmentManager.globalEnvironment = ENV_SEA;
Bind a license to a Flutter application
Flutter is an open source framework for building multi-platform applications. Therefore, you may need to use licenses for multiple platforms. For more information, see Bind a license to an Android application and Bind a license to an iOS application.