Integrate a license

更新时间:
复制 MD 格式

An ApsaraVideo Media SDK license binds to an application identifier to authorize SDK calls. After obtaining a license, integrate it with the Push SDK, short video SDK, ApsaraVideo Player SDK, or Queen SDK to complete authorization on web, Android, iOS, and HarmonyOS clients.

Prerequisites

A license file and License Key obtained from Manage a license.

Authentication flow

image

License authentication relies on a License Key and a license file.

Item

Required

Description

License Key

Yes

Used to request updates for the license file.

The SDK checks for updates during initialization and every 15 minutes at runtime.

License file

No. Recommended Configuration

Fallback for authentication when the server-side certificate request fails, such as during network outages.

The certificate file stores enabled permissions and validity period. Update it when permissions change to maintain reliability in weak network environments.

Note
  1. Permission changes usually include activating new services, enabling value-added services, or renewing services.

  2. Native ApsaraVideo Player SDK V7.6.0 and later require a license file.

  3. The web client does not require a license file.

  4. For renewals, the certificate updates online automatically, but update the local file to ensure validity period checks succeed.

To skip the built-in license file, omit the LicenseFile configuration in the platform-specific steps below.

Note

Without a built-in certificate file, authentication relies entirely on the server. Network fluctuations may cause instability, and first-time users must wait for the certificate download to complete before authentication succeeds.

ApsaraVideo Player SDK service environments

ApsaraVideo Player SDK V6.14.0 and later provide multiple service environments for global compliance. The selected environment determines which service center handles license authentication and playback quality data.

Alibaba Cloud China Website (www.aliyun.com) users can use either the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) environment or the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment (Singapore node). V6.14.0 and later default to the China site environment.

Environment

Description

The Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)

The Alibaba Cloud China Website (www.aliyun.com) environment (default). Uses the Shanghai, China node to serve users in the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China).

Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China))

The Alibaba Cloud International Website environment. Uses the Singapore node for compliance and performance in regions outside the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China).

Video tutorials

This example demonstrates license integration with ApsaraVideo Player SDK.

Android

iOS

Flutter

HarmonyOS

Integrate a license on the web client

  1. Obtain the License Key from the console.image

  2. When initializing the player, pass the license field, which includes the registered domain name and the License Key:

    var player = new Aliplayer({
      license: {
        domain: "example.com", // The domain name you entered when you applied for the license
        key: "example-key" // The License Key you can view in the console after a successful application
      }
    });
  3. If no error messages appear after initialization, the license is configured successfully.

    Note

    The page domain must match or be a subdomain of the domain registered in your license application. Otherwise, verification fails.

Integrate a license on Android

  1. Configure the license.

    1. (Recommended) Copy the certificate file to the assets directory in your Android Studio project.

      Note

      You can also copy the certificate file to another location on the device. However, ensure the value of com.aliyun.alivc_license.licensefile (for the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) or com.aliyun.alivc_license.licensefile_SEA (for Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China))) matches the path of the license file.

    2. In the AndroidManifest.xml file, add a <meta-data> node.

      Important
      • If 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, see FAQ about licenses for troubleshooting.

      • For Alibaba Cloud International Website (www.alibabacloud.com) users, if you use ApsaraVideo Player SDK V6.14.0 or later, configure a license for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment. If you do not use the ApsaraVideo Player SDK, configure a license only for the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) environment.

      • You can integrate two sets of licenses: one for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment and one for the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) environment. After integrating the licenses, specify the operating environment for the player by configuring its service environment each time the app starts. You cannot switch the environment while the player is running.

      License配置-android-EN3.png

      // Configure the license for the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) (default China site configuration)
      <meta-data
          android:name="com.aliyun.alivc_license.licensekey"
          android:value="foIVziMaUHaRqgDyhf6b6eb8fcf014af39535d0720a32****"/>  <!-- TODO: Set your LicenseKey value. -->
      <meta-data
          android:name="com.aliyun.alivc_license.licensefile"
          android:value="assets/cert/release.crt"/>  <!-- TODO: Set the path of your license file. -->
      
      
      // Configure the license for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment. Manually add _SEA to the end of the name.
      <meta-data
          android:name="com.aliyun.alivc_license.licensekey_SEA"
          android:value="f6b6foIVziMaUHaRqgDyheb8fcf014af39535d0a32720****"/>  <!-- TODO: Set your LicenseKey value. -->
      <meta-data
          android:name="com.aliyun.alivc_license.licensefile_SEA"
          android:value="assets/cert/release.crt"/>  <!-- TODO: Set the path of your license file. -->
  2. Configure the service environment for ApsaraVideo Player SDK (required for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment).

    ApsaraVideo Player SDK V6.14.0 and later default to the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) environment. Alibaba Cloud International Website users must switch to the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment using one of the following methods. Otherwise, license authentication fails. For other versions and SDK usage scenarios, ignore this step.

    1. Method 1: Call the following API to update the default configuration to the international site environment.

      // If you use the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment, ensure you call the following interface to update the default configuration to the international site environment before calling any player API. This ensures all subsequent services run in the international site environment.
      // Use the unified AlivcBase interface to set the international site environment. You cannot modify the environment at runtime.
      AlivcBase.getEnvironmentManager().setGlobalEnvironment(AlivcEnv.GlobalEnv.ENV_SEA);
    2. Method 2 (Recommended): For ApsaraVideo Player SDK V7.6.0 and later, configure the international site environment using the XML method.

      In the AndroidManifest.xml file, add a <meta-data> node.

      <meta-data
        android:name="com.aliyun.alivc_env"
        android:value="SEA"/>  

      The following figure shows a configuration example:1754556751170-7001527b-36a7-4ebd-8887-e0972a3d64e3

Integrate a license on iOS

  1. Configure the license.

    1. In your Xcode project, copy the certificate file AliVideoCert-********.crt into the project. We recommend placing it in the AppSupportFiles directory. You can also place it in the sandbox or another path. In Target Membership, select the current project.

      p687320

    2. Open the Info.plist file. Set AlivcLicenseKey and AlivcLicenseFile (for the China environment) or AlivcLicenseKey_SEA and AlivcLicenseFile_SEA (for the International environment) to the License Key and license file path obtained from Manage a license.

      Important
      • For Alibaba Cloud International Website (www.alibabacloud.com) users, if you use ApsaraVideo Player SDK V6.14.0 or later, configure a license for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment. If you do not use the ApsaraVideo Player SDK, configure a license only for the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) environment.

      • You can integrate two sets of licenses: one for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment and one for the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) environment. After integrating the licenses, specify the operating environment for the player by configuring its service environment each time the app starts. You cannot switch the environment while the player is running.

      // Configure the license for the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) (default configuration)
      <key>AlivcLicenseFile</key>
      <string>XXX</string>
      <key>AlivcLicenseKey</key>
      <string>foIVziMaUHaRqgDyhf6b6eb8fcf014af39535d0720a32****</string>
      
      
      // Configure the license for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment. Manually add _SEA to the end of the key name.
      <key>AlivcLicenseFile_SEA</key>
      <string>XXX</string>
      <key>AlivcLicenseKey_SEA</key>
      <string>f6b6efoIVziMaUHaRqgDyhb8fcf014af39535d0a32072****</string>
  2. Configure the service environment for ApsaraVideo Player SDK (required for the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment).

    ApsaraVideo Player SDK V6.14.0 and later default to the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China) environment. Alibaba Cloud International Website users must switch to the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment using one of the following methods. Otherwise, license authentication fails. For other versions and SDK usage scenarios, ignore this step.

    1. Method 1: Call the following API to update the default configuration to the international site environment.

      // If you use the Global (excluding the Chinese mainland, Hong Kong (China), Macao (China), and Taiwan (China)) environment, ensure you call the following interface to update the default configuration to the international site environment before calling any player API. This ensures all subsequent services run in the international site environment.
      // Use the unified AlivcBase interface to set the international site environment. You cannot modify the environment at runtime.
      AlivcBase.EnvironmentManager.globalEnvironment = ENV_SEA;
    2. Method 2 (Recommended): For ApsaraVideo Player SDK V7.6.0 and later, configure the international site environment using the Info.Plist method.

      Open the Info.plist file and set AlivcEnv to SEA.

      // Configure the current environment as the international site environment.
      <key>AlivcEnv</key>
      <string>SEA</string>

      The following figure shows a configuration example:1754557498401-1d235342-3c0b-4c83-bcee-ae7656e8ff23

Integrate a license on Flutter

For Flutter applications, integrate the license on each supported platform: Integrate a license on Android or Integrate a license on iOS.

Integrate a license on HarmonyOS

  1. Copy the obtained license certificate file into your DevEco Studio project. We recommend placing it in the rawfile directory.

  2. In the module.json5 file, add the following fields.c80dab1c5a78e060e10a0f19ef73dc9d

    • The key is com.aliyun.alivc_license.licensekey (all lowercase), and the value is your License Key.

    • The key is com.aliyun.alivc_license.licensefile (all lowercase), and the value is the path to the certificate file from the previous step. Specify the path as needed.

      "metadata": [
        {
          "name": "com.aliyun.alivc_license.licensekey",
          "value": "********"
        },
        {
          "name": "com.aliyun.alivc_license.licensefile",
          "value": "license.crt"
        },
      ]