Functions
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';
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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | DRM solution name, for example, "com.clearplay.drm". |
Return value
| Type | Description |
|---|---|
| MediaKeySystem | MediaKeySystem instance. |
Error codes
For details about the error codes, see Universal Error Codes and DRM Error Codes.
| ID | Error Message |
|---|---|
| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 24700101 | All unknown errors |
| 24700103 | Meet max MediaKeySystem num limit |
| 24700201 | Fatal 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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | DRM solution name, for example, "com.clearplay.drm". |
Return value
| Type | Description |
|---|---|
| boolean | Check result for the support of the DRM solution. true if supported, false otherwise. |
Error codes
For details about the error codes, see Universal Error Codes and DRM Error Codes.
| ID | Error Message |
|---|---|
| 401 | The 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). |
| 24700101 | All unknown errors |
| 24700201 | Fatal 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.info("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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | DRM solution name. Before calling this API, ensure that the DRM solution name is supported by calling isMediaKeySystemSupported. |
| mimeType | string | Yes | MIME type. The supported MIME types depend on the DRM solution. For example, video/avc and video/hevc. |
Return value
| Type | Description |
|---|---|
| boolean | Check result for the support of the combination. true if supported, false otherwise. |
Error codes
For details about the error codes, see Universal Error Codes and DRM Error Codes.
| ID | Error Message |
|---|---|
| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
| 24700101 | All unknown errors |
| 24700201 | Fatal 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.info("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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | DRM solution name. Before calling this API, ensure that the DRM solution name is supported by calling isMediaKeySystemSupported. |
| mimeType | string | Yes | MIME type. The supported MIME types depend on the DRM solution. Before calling this API, ensure that the MIME type is supported by calling isMediaKeySystemSupported. |
| level | ContentProtectionLevel | Yes | Content protection level. |
Return value
| Type | Description |
|---|---|
| boolean | Check result for the support of the combination. true if supported, false otherwise. |
Error codes
For details about the error codes, see Universal Error Codes and DRM Error Codes.
| ID | Error Message |
|---|---|
| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
| 24700101 | All unknown errors |
| 24700201 | Fatal 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.info("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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | DRM solution name. You can check whether the solution name is supported by calling isMediaKeySystemSupported. |
Return value
| Type | Description |
|---|---|
| string | UUID of the DRM content protection system. |
Error codes
For details about the error codes, see Universal Error Codes and DRM Error Codes.
| ID | Error Message |
|---|---|
| 401 | The parameter check failed.Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 24700101 | All unknown errors |
| 24700201 | Fatal 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.info("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
| Type | Description |
|---|---|
| MediaKeySystemDescription[] | Array of supported plugins. |
Error codes
For details about the error codes, see DRM Error Codes.
| ID | Error Message |
|---|---|
| 24700101 | All unknown errors |
| 24700201 | Fatal 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}`);
}
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 capi-drm-drm-mediakeysystemdescription
openharmony 鸿蒙 capi-drm-drm-offlinemediakeyidarray
openharmony 鸿蒙 arkts-apis-drm-MediaKeySession
openharmony 鸿蒙 capi-drm-drm-keysinfo
openharmony 鸿蒙 capi-native-mediakeysystem-h
openharmony 鸿蒙 capi-drm-drm-mediakeyrequest
openharmony 鸿蒙 capi-native-mediakeysession-h