harmony 鸿蒙@ohos.multimedia.drm (Digital Rights Management)

2025-06-12 浏览 (1)

@ohos.multimedia.drm (Digital Rights Management)

The Digital Rights Management (DRM) framework provides APIs for you to develop digital rights management for your audio and video applications. You can call the DRM solutions (which exist as DRM plugins) provided by the system to implement the following features:

  • DRM certificate management: generates provision requests and processes responses to these requests. Such a request/response exchange occurs between an application and a provisioning server to retrieve a DRM certificate.
  • DRM media key management: generates media key requests, processes responses to these requests, and manages offline media keys. Such a request/response exchange occurs between an application and a license server to obtain or release a media key, which is used to decrypt DRM-protected content.
  • DRM authorization: authorizes access to DRM-protected content based on media keys.
  • DRM decryption: decrypts DRM-protected content.

NOTE The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { drm } from '@kit.DrmKit';

DrmErrorCode

Enumerates the DRM error codes.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameValueDescription
ERROR_UNKNOWN24700101Unknown error.
MAX_SYSTEM_NUM_REACHED24700103The number of MediaKeySystem instances reaches the upper limit (64).
MAX_SESSION_NUM_REACHED24700104The number of MediaKeySession instances reaches the upper limit (64).
SERVICE_FATAL_ERROR24700201DRM service error.

PreDefinedConfigName

Enumerates the names of predefined configuration items.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameValueDescription
CONFIG_DEVICE_VENDOR'vendor'Plugin vendor name, which corresponds to the value of vendor in the return value of getConfigurationString.
CONFIG_DEVICE_VERSION'version'Plugin version number, which corresponds to the value of version in the return value of getConfigurationString.
CONFIG_DEVICE_DESCRIPTION'description'Device descriptor, which corresponds to the value of description in the return value of getConfigurationString.
CONFIG_DEVICE_ALGORITHMS'algorithms'Supported algorithm names, which correspond to the value of algorithms in the return value of getConfigurationString.
CONFIG_DEVICE_UNIQUE_ID'deviceUniqueId'Unique device ID, which corresponds to the value of deviceUniqueId in the return value of getConfigurationByteArray.
CONFIG_SESSION_MAX'maxSessionNum'Maximum number of sessions supported by the device, which corresponds to the value of maxSessionNum in the return value of getConfigurationString.
CONFIG_SESSION_CURRENT'currentSessionNum'Number of existing sessions, which corresponds to the value of currentSessionNum in the return value of getConfigurationString.

MediaKeyType

Enumerates the types of media keys.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameValueDescription
MEDIA_KEY_TYPE_OFFLINE0Offline.
MEDIA_KEY_TYPE_ONLINE1Online.

OfflineMediaKeyStatus

Enumerates the statuses of offline media keys.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameValueDescription
OFFLINE_MEDIA_KEY_STATUS_UNKNOWN0Unknown status.
OFFLINE_MEDIA_KEY_STATUS_USABLE1The media key is available.
OFFLINE_MEDIA_KEY_STATUS_INACTIVE2The media key is inactive.

CertificateStatus

Enumerates the statuses of DRM certificates.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameValueDescription
CERT_STATUS_PROVISIONED0A DRM certificate has been installed on the device.
CERT_STATUS_NOT_PROVISIONED1No DRM certificate is installed on the device.
CERT_STATUS_EXPIRED2The DRM certificate has expired.
CERT_STATUS_INVALID3The DRM certificate is invalid.
CERT_STATUS_UNAVAILABLE4The DRM certificate is unavailable.

MediaKeyRequestType

Enumerates the types of media key requests.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameValueDescription
MEDIA_KEY_REQUEST_TYPE_UNKNOWN0Unknown type.
MEDIA_KEY_REQUEST_TYPE_INITIAL1Initial request.
MEDIA_KEY_REQUEST_TYPE_RENEWAL2Renewal request.
MEDIA_KEY_REQUEST_TYPE_RELEASE3Release request.
MEDIA_KEY_REQUEST_TYPE_NONE4None.
MEDIA_KEY_REQUEST_TYPE_UPDATE5Update request.

ContentProtectionLevel

Enumerates the content protection levels.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameValueDescription
CONTENT_PROTECTION_LEVEL_UNKNOWN0Unknown content protection level.
CONTENT_PROTECTION_LEVEL_SW_CRYPTO1Software content protection level.
CONTENT_PROTECTION_LEVEL_HW_CRYPTO2Hardware content protection level.
CONTENT_PROTECTION_LEVEL_ENHANCED_HW3Enhanced hardware content protection level.
CONTENT_PROTECTION_LEVEL_MAX4Highest content protection level.

ProvisionRequest

Describes a provision request, which is used to request a DRM certificate from a provisioning server.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
dataUint8ArrayYesData carried in the provision request.
defaultURLstringYesURL of the provisioning server (which provisions DRM certificates).

OptionsData

Describes the optional data carried in a media key request.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
namestringYesName of the optional data.
valuestringYesValue of the optional data.

MediaKeyRequest

Describes a media key request.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
mediaKeyRequestTypeMediaKeyRequestTypeYesType of the media key request.
dataUint8ArrayYesData carried in the media key request.
defaultURLstringYesURL of the license server (which provisions media keys).

EventInfo

Describes the event information.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
infoUint8ArrayYesEvent information.
extraInfostringYesExtended event information.

StatisticKeyValue

Describes the statistical information.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
namestringYesName of the statistical item.
valuestringYesValue of the statistical item.

MediaKeyStatus

Describes the media key status.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
namestringYesName of the media key status (such as the media key expiration time and content protection level).
valuestringYesValue of the media key status.

KeysInfo

Describes the information about media keys.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
keyIdUint8ArrayYesMedia key ID.
valuestringYesMedia key status.

MediaKeySystemInfo

Describes the DRM information, which is used to encrypt content.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
uuidstringYesUUID of the DRM content protection system.
psshUint8ArrayYesProtection System Specific Header (PSSH) in the DRM information.

MediaKeySystemDescription12+

Describes the plugin information.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

NameTypeMandatoryDescription
namestringYesName of the plugin.
uuidstringYesUUID of the plugin.

drm.createMediaKeySystem

createMediaKeySystem(name: string): MediaKeySystem

Creates a MediaKeySystem instance.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
namestringYesDRM solution name.

Return value

TypeDescription
MediaKeySystemMediaKeySystem instance.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
24700101All unknown errors
24700103Meet max MediaKeySystem num limit
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
  let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
} catch (err) {
  let error = err as BusinessError;
  console.error(`createMediaKeySystem ERROR: ${error}`);  
}

drm.isMediaKeySystemSupported

isMediaKeySystemSupported(name: string): boolean

Checks whether the device supports the specified DRM solution.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
namestringYesDRM solution name.

Return value

TypeDescription
booleanReturns true if the device supports the DRM solution; returns false otherwise.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed, the param name's length is zero or too big(exceeds 4096 Bytes).
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm");
  console.log("isMediaKeySystemSupported: ", supported);
} catch (err) {
  let error = err as BusinessError;
  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
}

drm.isMediaKeySystemSupported

isMediaKeySystemSupported(name: string, mimeType: string): boolean

Checks whether the device supports the combination of the DRM solution and MIME type.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
namestringYesDRM solution name.
mimeTypestringYesMIME type, which is determined by the DRM solution.

Return value

TypeDescription
booleanReturns true if the device supports the combination; returns false otherwise.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm", "video/avc");
  console.log("isMediaKeySystemSupported: ", supported);
} catch (err) {
  let error = err as BusinessError;
  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
}

drm.isMediaKeySystemSupported

isMediaKeySystemSupported(name: string, mimeType: string, level: ContentProtectionLevel): boolean

Checks whether the device supports the combination of the DRM solution, MIME type, and content protection level.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
namestringYesDRM solution name.
mimeTypestringYesMIME type, which is determined by the DRM solution.
levelContentProtectionLevelYesContent protection level.

Return value

TypeDescription
booleanReturns true if the device supports the combination; returns false otherwise.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm", "video/avc", drm.ContentProtectionLevel.CONTENT_PROTECTION_LEVEL_SW_CRYPTO);
  console.log("isMediaKeySystemSupported: ", supported);
} catch (err) {
  let error = err as BusinessError;
  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
}

drm.getMediaKeySystemUuid12+

getMediaKeySystemUuid(name: string): string;

Obtains the UUID of the DRM content protection system supported by the specified DRM solution.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
namestringYesDRM solution name.

Return value

TypeDescription
stringUUID of the DRM content protection system.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed.Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
  let uuid: String = drm.getMediaKeySystemUuid("com.clearplay.drm");
  console.log("getMediaKeySystemUuid: ", uuid);
} catch (err) {
  let error = err as BusinessError;
  console.error(`getMediaKeySystemUuid ERROR: ${error}`);  
}

drm.getMediaKeySystems12+

getMediaKeySystems(): MediaKeySystemDescription[]

Obtains the list of plugins supported by the device.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
MediaKeySystemDescription[]Array of the supported plugins.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
  let description: drm.MediaKeySystemDescription[] = drm.getMediaKeySystems();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getMediaKeySystems ERROR: ${error}`);  
}

MediaKeySystem

Implements MediaKeySystem instance management. Specifically, it provides APIs to request and process DRM certificates, creates session, manages offline media key, obtain DRM statistical information, and obtain device configuration information. Before calling any API in MediaKeySystem, you must use createMediaKeySystem to create a MediaKeySystem instance.

setConfigurationString

setConfigurationString(configName: string, value: string): void

Sets a configuration item in the form of a string.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
configNamestringYesName of the configuration item, which is determined by the DRM solution on the device and cannot be empty. For details about available options, see PreDefinedConfigName.
valuestringYesValue of the configuration item.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  mediaKeySystem.setConfigurationString("stringConfigName", "stringConfigValue"); // Ensure that stringConfigName is configurable.
} catch (err) {
  let error = err as BusinessError;
  console.error(`setConfigurationString ERROR: ${error}`);
}

getConfigurationString

getConfigurationString(configName: string): string

Obtains the value of a configuration item in the form of a string.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
configNamestringYesName of the configuration item, which is determined by the DRM solution on the device and cannot be empty. For details about available options, see PreDefinedConfigName.

Return value

TypeDescription
stringValue of the configuration item in the form of a string.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed, the param's length is zero or too big(exceeds 4096 Bytes).
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let configValue: string = mediaKeySystem.getConfigurationString("vendor");
} catch (err) {
  let error = err as BusinessError;
  console.error(`getConfigurationString ERROR: ${error}`);  
}

setConfigurationByteArray

setConfigurationByteArray(configName: string, value: Uint8Array): void

Sets a configuration item in the form of a byte array.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
configNamestringYesName of the configuration item, which is determined by the DRM solution on the device and cannot be empty. For details about available options, see PreDefinedConfigName.
valueUint8ArrayYesValue of the configuration item in the form of an array. The specific value is determined by the DRM solution on the device.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors.
24700201Fatal service error, for example, service died.

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
// Set configValue based on project requirements.
let configValue: Uint8Array = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
try {
  // Ensure that byteArrayConfigName of the current DRM solution is configurable.
  mediaKeySystem.setConfigurationByteArray("byteArrayConfigName", configValue);
} catch (err) {
  let error = err as BusinessError;
  console.error(`setConfigurationByteArray ERROR: ${error}`);  
}

getConfigurationByteArray

getConfigurationByteArray(configName: string): Uint8Array

Obtains the value of a configuration item in the form of a byte array.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
configNamestringYesName of the configuration item, which is determined by the DRM solution on the device and cannot be empty. For details about available options, see PreDefinedConfigName.

Return value

TypeDescription
Uint8ArrayValue of the configuration item in the form of an array.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let configValue: Uint8Array = mediaKeySystem.getConfigurationByteArray("deviceUniqueId"); // Ensure that deviceUniqueId exists.
} catch (err) {
  let error = err as BusinessError;
  console.error(`getConfigurationByteArray ERROR: ${error}`);  
}

getStatistics

getStatistics(): StatisticKeyValue[]

Obtains the statistical information, including the number of current sessions, plugin version, maximum decryption duration for each session, number of decryption times, and number of decryption failures.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
StatisticKeyValue[]Statistical information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let statisticKeyValue: drm.StatisticKeyValue[] = mediaKeySystem.getStatistics();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getConfigurationByteArray ERROR: ${error}`);
}

getMaxContentProtectionLevel

getMaxContentProtectionLevel(): ContentProtectionLevel

Obtains the maximum content protection level supported by the current DRM solution.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
ContentProtectionLevelMaximum content protection level.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let maxLevel: drm.ContentProtectionLevel = mediaKeySystem.getMaxContentProtectionLevel();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getConfigurationByteArray ERROR: ${error}`);
}

generateKeySystemRequest

generateKeySystemRequest(): Promise<ProvisionRequest>

Generates a provision request.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
Promise<ProvisionRequest>Promise used to return the provision request obtained. If a DRM certificate already exists on the device, a failure message is returned.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
// Do not call this API if a DRM certificate already exists on the device.
mediaKeySystem.generateKeySystemRequest().then((ProvisionRequest: drm.ProvisionRequest) => {
  console.log("generateKeySystemRequest");
}).catch((err: BusinessError) => {
  console.error(`generateKeySystemRequest: ERROR: ${err}`);
});

processKeySystemResponse

processKeySystemResponse(response: Uint8Array): Promise<void>

Processes a provision response.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
responseUint8ArrayYesProvision response.

Return value

TypeDescription
Promise<void>Promise

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
// keySystemResponse is the response obtained from the DRM service. Pass in the actual data obtained.
let keySystemResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySystem.processKeySystemResponse(keySystemResponse).then(() => {
  console.log("processKeySystemResponse");
}).catch((err: BusinessError) => {
  console.error(`processKeySystemResponse: ERROR: ${err}`);
});

getCertificateStatus

getCertificateStatus():CertificateStatus

Obtains the status of the DRM certificate.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
CertificateStatusCertificate status.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let certificateStatus: drm.CertificateStatus = mediaKeySystem.getCertificateStatus();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getCertificateStatus ERROR: ${error}`);
}

on('keySystemRequired')

on(type: 'keySystemRequired', callback: (eventInfo: EventInfo) => void): void

Subscribes to events indicating that the application requires a DRM certificate.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event can be listened for when a MediaKeySystem instance is created. This event is triggered when the application requests a DRM certificate.
callbackCallback<EventInfo>YesCallback used to return the event information. If this event callback is returned, a DRM certificate must be requested.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
mediaKeySystem.on('keySystemRequired', (eventInfo: drm.EventInfo) => {
  console.log('keySystemRequired ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
});

off('keySystemRequired')

off(type: 'keySystemRequired', callback?: (eventInfo: EventInfo) => void): void

Unsubscribes from events indicating that the application requests a DRM certificate.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event can be listened for when a MediaKeySystem instance is created.
callbackCallback<EventInfo>NoCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
24700101All unknown errors

Example

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
mediaKeySystem.off('keySystemRequired');

createMediaKeySession

createMediaKeySession(level: ContentProtectionLevel): MediaKeySession

Creates a MediaKeySession instance with the specified content protection level.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
levelContentProtectionLevelYesContent protection level.

Return value

TypeDescription
MediaKeySessionMediaKeySession instance.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.The param level exceeds reasonable range, please use value in ContentProtectionLevel.
24700101All unknown errors
24700104Meet max MediaKeySession num limit
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession(drm.ContentProtectionLevel.CONTENT_PROTECTION_LEVEL_SW_CRYPTO);
} catch (err) {
  let error = err as BusinessError;
  console.error(`createMediaKeySession ERROR: ${error}`);
}

createMediaKeySession

createMediaKeySession(): MediaKeySession

Creates a MediaKeySession instance with the default content protection level of the DRM solution.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
MediaKeySessionMediaKeySession instance.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700104Meet max MediaKeySession num limit
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
} catch (err) {
  let error = err as BusinessError;
  console.error(`createMediaKeySession ERROR: ${error}`);
}

getOfflineMediaKeyIds

getOfflineMediaKeyIds(): Uint8Array[]

Obtains the IDs of offline media keys.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
Uint8Array[]Array holding the IDs of offline media keys.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  let offlineMediaKeyIds: Uint8Array[] = mediaKeySystem.getOfflineMediaKeyIds();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getOfflineMediaKeyIds ERROR: ${error}`);
}

getOfflineMediaKeyStatus

getOfflineMediaKeyStatus(mediaKeyId: Uint8Array): OfflineMediaKeyStatus

Obtains the status of offline media keys with the specified IDs.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
mediaKeyIdUint8ArrayYesArray holding the IDs of offline media keys.

Return value

TypeDescription
OfflineMediaKeyStatusStatus of the offline media keys.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
// mediaKeyId is the return value of processMediaKeyResponse or getOfflineMediaKeyIds. Pass in the actual data returned.
let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
try {
  let configValue: drm.OfflineMediaKeyStatus = mediaKeySystem.getOfflineMediaKeyStatus(mediaKeyId);
} catch (err) {
  let error = err as BusinessError;
  console.error(`getOfflineMediaKeyStatus ERROR: ${error}`);
}

clearOfflineMediaKeys

clearOfflineMediaKeys(mediaKeyId: Uint8Array): void

Clears offline media keys by ID.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
mediaKeyIdUint8ArrayYesArray holding the IDs of offline media keys.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed.Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
// mediaKeyId is the return value of processMediaKeyResponse or getOfflineMediaKeyIds. Pass in the actual data returned.
let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
try {
  mediaKeySystem.clearOfflineMediaKeys(mediaKeyId);
} catch (err) {
  let error = err as BusinessError;
  console.error(`clearOfflineMediaKeys ERROR: ${error}`);
}

destroy

destroy(): void

Destroys this MediaKeySystem instance.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.Multimedia.Drm.Core

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
try {
  mediaKeySystem.destroy();
} catch (err) {
  let error = err as BusinessError;
  console.error(`mediaKeySystem destroy ERROR: ${error}`);
}

MediaKeySession

Implements media key management. Before calling any API in MediaKeySession, you must use createMediaKeySession to create a MediaKeySession instance.

generateMediaKeyRequest

generateMediaKeyRequest(mimeType: string, initData: Uint8Array, mediaKeyType: number, options?: OptionsData[]): Promise<MediaKeyRequest>

Generates a media key request.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
mimeTypestringYesMIME type, which is determined by the DRM solution.
initDataUint8ArrayYesInitial data.
mediaKeyTypenumberYesType of the media key. The value 0 means an online media key, and 1 means an offline media key.
optionsOptionsData[]NoOptional data.

Return value

TypeDescription
Promise<MediaKeyRequest>Promise used to return the media key request generated.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
// PSSH data is the descriptive header of the copyright protection system and is encapsulated in encrypted streams. Specifically, in MP4 file, the PSSH data is found within the PSSH box; for DASH streams, the PSSH data is located in the MPD and MP4 PSSH box; for HLS+TS streams, the PSSH data is located in the M3U8 file and each TS segment. Pass in the actual value.
let uint8pssh = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySession.generateMediaKeyRequest("video/avc", uint8pssh, drm.MediaKeyType.MEDIA_KEY_TYPE_ONLINE).then((mediaKeyRequest: drm.MediaKeyRequest) =>{
  console.log('generateMediaKeyRequest' + mediaKeyRequest);
}).catch((err: BusinessError) => {
  console.error(`generateMediaKeyRequest: ERROR: ${err}`);
});

processMediaKeyResponse

processMediaKeyResponse(response: Uint8Array): Promise<Uint8Array>

Processes a media key response.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
responseUint8ArrayYesMedia key response.

Return value

TypeDescription
Promise<Uint8Array>Promise used to return the media key IDs.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
// mediaKeyResponse is obtained from the DRM service. Pass in the actual value obtained.
let mediaKeyResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySession.processMediaKeyResponse(mediaKeyResponse).then((mediaKeyId: Uint8Array) => {
  console.log('processMediaKeyResponse:' + mediaKeyId);
}).catch((err: BusinessError) => {
  console.error(`processMediaKeyResponse: ERROR: ${err}`);
});

checkMediaKeyStatus

checkMediaKeyStatus(): MediaKeyStatus[]

Checks the status of the media keys in use.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
MediaKeyStatus[]Media key status.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
try {
  let keyStatus: drm.MediaKeyStatus[] =  mediaKeySession.checkMediaKeyStatus();
} catch (err) {
  let error = err as BusinessError;
  console.error(`checkMediaKeyStatus ERROR: ${error}`);
}

clearMediaKeys

clearMediaKeys(): void

Clears the media keys in use.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
// mediaKeyResponse is obtained from the DRM service. Pass in the actual value obtained.
let mediaKeyResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySession.processMediaKeyResponse(mediaKeyResponse).then((mediaKeyId: Uint8Array) => {
  console.log('processMediaKeyResponse:' + mediaKeyId);
}).catch((err: BusinessError) => {
  console.error(`processMediaKeyResponse: ERROR: ${err}`);
});
try {
  mediaKeySession.clearMediaKeys();
} catch (err) {
  let error = err as BusinessError;
  console.error(`clearMediaKeys ERROR: ${error}`);
}

generateOfflineReleaseRequest

generateOfflineReleaseRequest(mediaKeyId: Uint8Array): Promise<Uint8Array>

Generates a request to release offline media keys.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
mediaKeyIdUint8ArrayYesArray holding the IDs of offline media keys.

Return value

TypeDescription
Promise<Uint8Array>Promise used to return the request generated if the DRM solution on the device supports offline media key release.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
// mediaKeyId is the return value of processMediaKeyResponse or getOfflineMediaKeyIds. Pass in the actual data returned.
let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySession.generateOfflineReleaseRequest(mediaKeyId).then((offlineReleaseRequest: Uint8Array) => {
  console.log('generateOfflineReleaseRequest:' + offlineReleaseRequest);
}).catch((err: BusinessError) => {
  console.error(`generateOfflineReleaseRequest: ERROR: ${err}`);
});

processOfflineReleaseResponse

processOfflineReleaseResponse(mediaKeyId: Uint8Array, response: Uint8Array): Promise<void>

Processes a response to a request for releasing offline media keys.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
mediaKeyIdUint8ArrayYesArray holding the IDs of offline media keys.
responseUint8ArrayYesResponse to the request for releasing offline media keys.

Return value

TypeDescription
Promise<void>Promise used to return the result if the DRM solution on the device supports offline media key release.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
// mediaKeyId is the return value of processMediaKeyResponse or getOfflineMediaKeyIds. Apply for memory based on the actual length.
let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySession.generateOfflineReleaseRequest(mediaKeyId).then((offlineReleaseRequest: Uint8Array) => {
  console.log('generateOfflineReleaseRequest:' + offlineReleaseRequest);
}).catch((err: BusinessError) => {
  console.error(`generateOfflineReleaseRequest: ERROR: ${err}`);
});
// offlineReleaseResponse is obtained from the DRM service. Apply for memory based on the actual length.
let offlineReleaseResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySession.processOfflineReleaseResponse(mediaKeyId, offlineReleaseResponse).then(() => {
  console.log('processOfflineReleaseResponse');
}).catch((err: BusinessError) => {
  console.error(`processOfflineReleaseResponse: ERROR: ${err}`);
});

restoreOfflineMediaKeys

restoreOfflineMediaKeys(mediaKeyId: Uint8Array): Promise<void>

Restores offline media keys.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
mediaKeyIdUint8ArrayYesArray holding the IDs of offline media keys.

Return value

TypeDescription
Promise<void>Promise

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
// mediaKeyId is the return value of processMediaKeyResponse or getOfflineMediaKeyIds. Pass in the actual data returned.
let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
mediaKeySession.restoreOfflineMediaKeys(mediaKeyId).then(() => {
  console.log("restoreOfflineMediaKeys");
}).catch((err: BusinessError) => {
  console.error(`restoreOfflineMediaKeys: ERROR: ${err}`);
});

getContentProtectionLevel

getContentProtectionLevel(): ContentProtectionLevel

Obtains the content protection level of this media key session.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Return value

TypeDescription
ContentProtectionLevelContent protection level.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
try {
  let contentProtectionLevel: drm.ContentProtectionLevel = mediaKeySession.getContentProtectionLevel();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getContentProtectionLevel ERROR: ${error}`);
}

requireSecureDecoderModule

requireSecureDecoderModule(mimeType: string): boolean

Checks whether secure decoding is required.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
mimeTypestringYesMIME type, which is determined by the DRM solution.

Return value

TypeDescription
booleanWhether secure decoding is required. The value true means that secure decoding is required, and false means the opposite.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
try {
  let status: boolean = mediaKeySession.requireSecureDecoderModule("video/avc");
} catch (err) {
  let error = err as BusinessError;
  console.error(`requireSecureDecoderModule ERROR: ${error}`);
} 

on('keyRequired')

on(type: 'keyRequired', callback: (eventInfo: EventInfo) => void): void

Subscribes to events indicating that the application requests a media key.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'keyRequired'. This event is triggered when the application requires a media key.
callbackCallback<EventInfo>YesCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.on('keyRequired', (eventInfo: drm.EventInfo) => {
  console.log('keyRequired ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
});

off('keyRequired')

off(type: 'keyRequired', callback?: (eventInfo: EventInfo) => void): void

Unsubscribes from events indicating that the application requests a media key.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'keyRequired'.
callbackCallback<EventInfo>NoCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.off('keyRequired');

on('keyExpired')

on(type: 'keyExpired', callback: (eventInfo: EventInfo) => void): void

Subscribes to events indicating that a media key expires.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'keyExpired'. This event is triggered when a media key expires.
callbackCallback<EventInfo>YesCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.on('keyExpired', (eventInfo: drm.EventInfo) => {
  console.log('keyExpired ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
});

off('keyExpired')

off(type: 'keyExpired', callback?: (eventInfo: EventInfo) => void): void

Unsubscribes from events indicating that a media key expires.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'keyExpired'.
callbackCallback<EventInfo>NoCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.off('keyExpired');

on('vendorDefined')

on(type: 'vendorDefined', callback: (eventInfo: EventInfo) => void): void

Subscribes to vendor-defined events.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'vendorDefined'. This event is triggered when a vendor-defined event occurs.
callbackCallback<EventInfo>YesCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.on('vendorDefined', (eventInfo: drm.EventInfo) => {
  console.log('vendorDefined ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
});

off('vendorDefined')

off(type: 'vendorDefined', callback?: (eventInfo: EventInfo) => void): void

Unsubscribes from vendor-defined events.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'vendorDefined'.
callbackCallback<EventInfo>NoCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.off('vendorDefined');

on('expirationUpdate')

on(type: 'expirationUpdate', callback: (eventInfo: EventInfo) => void): void

Subscribes to events indicating that a media key updates on expiry.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'expirationUpdate'. This event is triggered when a media key updates on expiry.
callbackCallback<EventInfo>YesCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.on('expirationUpdate', (eventInfo: drm.EventInfo) => {
  console.log('expirationUpdate ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
});

off('expirationUpdate')

off(type: 'expirationUpdate', callback?: (eventInfo: EventInfo) => void): void

Unsubscribes from events indicating that a media key updates on expiry.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'expirationUpdate'.
callbackCallback<EventInfo>NoCallback used to return the event information.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.off('expirationUpdate');

on('keysChange')

on(type: 'keysChange', callback: (keyInfo: KeysInfo[], newKeyAvailable: boolean) => void): void

Subscribes to events indicating that a media key changes.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'keysChange'. This event is triggered when a media key changes.
callbackCallback<KeysInfo[], boolean>YesCallback used to return the event information, including the lists of key IDs, statuses, and availability.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.on('keysChange', (keyInfo: drm.KeysInfo[], newKeyAvailable: boolean) => {
  for (let i = 0; i < keyInfo.length; i++) {
    console.log('keysChange' + 'keyId:' + keyInfo[i].keyId + ' data:' + keyInfo[i].value);
  }
});

off('keysChange')

off(type: 'keysChange', callback?: (keyInfo: KeysInfo[], newKeyAvailable: boolean) => void): void

Unsubscribes from events indicating that a media key changes.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value is fixed at 'keysChange'.
callbackCallback<KeysInfo[], boolean>NoCallback used to return the event information, including the lists of key IDs, statuses, and availability.

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
401The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.
24700101All unknown errors

Example

import { drm } from '@kit.DrmKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
mediaKeySession.off('keysChange');

destroy

destroy(): void

Destroys this MediaKeySession instance.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Multimedia.Drm.Core

Error codes

For details about the error codes, see DRM Error Codes.

IDError Message
24700101All unknown errors
24700201Fatal service error, for example, service died

Example

import { drm } from '@kit.DrmKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
try {
  mediaKeySession.destroy();
} catch (err) {
  let error = err as BusinessError;
  console.error(`mediaKeySession destroy ERROR: ${error}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙DRM Kit

harmony 鸿蒙DRM_KeysInfo

harmony 鸿蒙DRM_MediaKeyRequest

harmony 鸿蒙DRM_MediaKeyRequestInfo

harmony 鸿蒙DRM_MediaKeyStatus

harmony 鸿蒙DRM_MediaKeySystemDescription

harmony 鸿蒙DRM_MediaKeySystemInfo

harmony 鸿蒙DRM_OfflineMediakeyIdArray

harmony 鸿蒙DRM_PsshInfo

harmony 鸿蒙DRM_Statistics

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/M6GUdO