1# @ohos.multimedia.drm (数字版权保护)
2
3DRM(Digital Rights Management)框架组件支持音视频媒体业务数字版权管理功能的开发。开发者可以调用系统提供的DRM插件,完成以下功能:
4
5* DRM证书管理:生成证书请求、设置证书响应,实现对证书Provision(下载)功能。
6* DRM媒体密钥管理:生成媒体密钥请求、设置媒体密钥响应、管理离线媒体密钥功能。
7* DRM节目授权:支持DRM插件根据媒体密钥权限对DRM节目授权。
8* DRM节目解密:支持媒体播放功能的解密调用,实现对DRM节目的解密。
9
10> **说明:**
11> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
12
13## 导入模块
14
15```ts
16import { drm } from '@kit.DrmKit';
17```
18
19## DrmErrorCode
20
21枚举,错误码。
22
23**系统能力:** SystemCapability.Multimedia.Drm.Core
24
25| 名称                       | 值   | 说明            |
26| ------------------------- | ---- | ------------    |
27| ERROR_UNKNOWN       | 24700101    | 未知错误   |
28| MAX_SYSTEM_NUM_REACHED   | 24700103    | MediaKeySystem实例数量超过上限(64个)    |
29| MAX_SESSION_NUM_REACHED    | 24700104    | MediaKeySession实例数量超过上限(64个)     |
30| SERVICE_FATAL_ERROR  | 24700201    | DRM服务异常     |
31
32## PreDefinedConfigName
33
34枚举,预定义的配置属性。
35
36**系统能力:** SystemCapability.Multimedia.Drm.Core
37
38| 名称                       | 值   | 说明            |
39| ------------------------- | ---- | ------------    |
40| CONFIG_DEVICE_VENDOR        | 'vendor'    | 插件厂商名,通过[getConfigurationString](#getconfigurationstring)接口获取vendor对应配置值。   |
41| CONFIG_DEVICE_VERSION    | 'version'    | 插件版本号,通过[getConfigurationString](#getconfigurationstring)接口获取version对应配置值。     |
42| CONFIG_DEVICE_DESCRIPTION     | 'description'    | 设备描述符,通过[getConfigurationString](#getconfigurationstring)接口获取description对应配置值。      |
43| CONFIG_DEVICE_ALGORITHMS   | 'algorithms'    | 支持的算法,通过[getConfigurationString](#getconfigurationstring)接口获取algorithms对应配置值。     |
44| CONFIG_DEVICE_UNIQUE_ID    | 'deviceUniqueId'    | 设备唯一标识,通过[getConfigurationByteArray](#getconfigurationbytearray)接口获取deviceUniqueId对应配置值。     |
45| CONFIG_SESSION_MAX         | 'maxSessionNum'    | 设备支持的最大会话数,通过[getConfigurationString](#getconfigurationstring)接口获取maxSessionNum对应配置值。     |
46| CONFIG_SESSION_CURRENT   | 'currentSessionNum'    | 当前会话数量,通过[getConfigurationString](#getconfigurationstring)接口获取currentSessionNum对应配置值。     |
47
48## MediaKeyType
49
50枚举,媒体密钥类型。
51
52**系统能力:** SystemCapability.Multimedia.Drm.Core
53
54| 名称                       | 值   | 说明            |
55| ------------------------- | ---- | ------------    |
56| MEDIA_KEY_TYPE_OFFLINE        | 0    | 离线   |
57| MEDIA_KEY_TYPE_ONLINE   | 1    | 在线     |
58
59## OfflineMediaKeyStatus
60
61枚举,离线媒体密钥状态。
62
63**系统能力:** SystemCapability.Multimedia.Drm.Core
64
65| 名称                       | 值   | 说明            |
66| ------------------------- | ---- | ------------    |
67| OFFLINE_MEDIA_KEY_STATUS_UNKNOWN        | 0    | 未知状态   |
68| OFFLINE_MEDIA_KEY_STATUS_USABLE   | 1    | 可用状态     |
69| OFFLINE_MEDIA_KEY_STATUS_INACTIVE     | 2    | 失活状态       |
70
71## CertificateStatus
72
73枚举,设备证书状态。
74
75**系统能力:** SystemCapability.Multimedia.Drm.Core
76
77| 名称                       | 值   | 说明            |
78| ------------------------- | ---- | ------------    |
79| CERT_STATUS_PROVISIONED        | 0    | 设备已安装设备证书   |
80| CERT_STATUS_NOT_PROVISIONED   | 1    | 设备未安装设备证书     |
81| CERT_STATUS_EXPIRED    | 2    | 设备证书过期       |
82| CERT_STATUS_INVALID  | 3    | 设备证书无效     |
83| CERT_STATUS_UNAVAILABLE  | 4    | 设备证书不可用     |
84
85## MediaKeyRequestType
86
87枚举,媒体密钥请求类型。
88
89**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
90
91**系统能力:** SystemCapability.Multimedia.Drm.Core
92
93| 名称                       | 值   | 说明            |
94| ------------------------- | ---- | ------------    |
95| MEDIA_KEY_REQUEST_TYPE_UNKNOWN        | 0    | 未知请求类型   |
96| MEDIA_KEY_REQUEST_TYPE_INITIAL    | 1    | 初始化请求     |
97| MEDIA_KEY_REQUEST_TYPE_RENEWAL     | 2    | 续订请求       |
98| MEDIA_KEY_REQUEST_TYPE_RELEASE   | 3    | 释放请求     |
99| MEDIA_KEY_REQUEST_TYPE_NONE    | 4    | 无请求     |
100| MEDIA_KEY_REQUEST_TYPE_UPDATE    | 5    | 更新请求     |
101
102## ContentProtectionLevel
103
104枚举,内容保护级别。
105
106**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
107
108**系统能力:** SystemCapability.Multimedia.Drm.Core
109
110| 名称                       | 值   | 说明            |
111| ------------------------- | ---- | ------------    |
112| CONTENT_PROTECTION_LEVEL_UNKNOWN        | 0    | 未知内容保护级别   |
113| CONTENT_PROTECTION_LEVEL_SW_CRYPTO   | 1    | 软件内容保护级别     |
114| CONTENT_PROTECTION_LEVEL_HW_CRYPTO    | 2    | 硬件内容保护级别       |
115| CONTENT_PROTECTION_LEVEL_ENHANCED_HW  | 3    | 硬件增强内容保护级别     |
116| CONTENT_PROTECTION_LEVEL_MAX  | 4    | 最高内容保护级别     |
117
118## ProvisionRequest
119
120设备证书请求。
121
122**系统能力:** SystemCapability.Multimedia.Drm.Core
123
124| 名称      | 类型                           | 必填 | 说明         |
125| -------- | ----------------------------- |---- | ------------- |
126| data   | Uint8Array | 是  | 设备证书请求数据      |
127| defaultURL     | string                 | 是  | Provision服务(设备证书请求服务)URL       |
128
129## OptionsData
130
131设备证书请求的可选数据。
132
133**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
134
135**系统能力:** SystemCapability.Multimedia.Drm.Core
136
137| 名称      | 类型                           | 必填 | 说明         |
138| -------- | ----------------------------- |---- | ------------- |
139| name   | string | 是  | 可选数据名      |
140| value     | string                 | 是  | 可选数据值       |
141
142## MediaKeyRequest
143
144媒体密钥请求参数。
145
146**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
147
148**系统能力:** SystemCapability.Multimedia.Drm.Core
149
150| 名称      | 类型                           | 必填 | 说明         |
151| -------- | ----------------------------- |---- | ------------- |
152| mediaKeyRequestType   | [MediaKeyRequestType](#mediakeyrequesttype) | 是  | 媒体密钥请求类型      |
153| data     | Uint8Array                 | 是  | 媒体密钥请求数据       |
154| defaultURL     | string                 | 是  | 媒体密钥服务URL       |
155
156## EventInfo
157
158事件信息。
159
160**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
161
162**系统能力:** SystemCapability.Multimedia.Drm.Core
163
164| 名称      | 类型                           | 必填 | 说明         |
165| -------- | ----------------------------- |---- | ------------- |
166| info   | Uint8Array | 是  | 事件信息数据      |
167| extraInfo     | string                 | 是  | 事件扩展信息       |
168
169## StatisticKeyValue
170
171度量记录。
172
173**系统能力:** SystemCapability.Multimedia.Drm.Core
174
175| 名称      | 类型                           | 必填 | 说明         |
176| -------- | ----------------------------- |---- | ------------- |
177| name   | string | 是  | 度量记录名      |
178| value     | string                 | 是  | 度量记录值       |
179
180## MediaKeyStatus
181
182媒体密钥状态
183
184**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
185
186**系统能力:** SystemCapability.Multimedia.Drm.Core
187
188| 名称      | 类型                           | 必填 | 说明         |
189| -------- | ----------------------------- |---- | ------------- |
190| name   | string | 是  | 媒体密钥状态名称(如媒体密钥过期时间、内容保护安全级别等)      |
191| value     | string                 | 是  | 媒体密钥状态值       |
192
193## KeysInfo
194
195媒体密钥中密钥信息。
196
197**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
198
199**系统能力:** SystemCapability.Multimedia.Drm.Core
200
201| 名称      | 类型                           | 必填 | 说明         |
202| -------- | ----------------------------- |---- | ------------- |
203| keyId   | Uint8Array | 是  | 媒体密钥标识      |
204| value     | string                 | 是  | 媒体密钥状态值       |
205
206## MediaKeySystemInfo
207
208加密媒体内容的DRM信息。
209
210**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
211
212**系统能力:** SystemCapability.Multimedia.Drm.Core
213
214| 名称      | 类型                           | 必填 | 说明         |
215| -------- | ----------------------------- |---- | ------------- |
216| uuid   | string | 是  | DRM内容保护系统的唯一标识      |
217| pssh     | Uint8Array                 | 是  | DRM内容保护系统专用头(Protection System Specific Header)       |
218
219## MediaKeySystemDescription<sup>12+</sup>
220
221插件信息。
222
223**系统能力:** SystemCapability.Multimedia.Drm.Core
224
225| 名称      | 类型                           | 必填 | 说明         |
226| -------- | ----------------------------- |---- | ------------- |
227| name   | string | 是  | 插件名称      |
228| uuid   | string | 是  | 插件唯一标识码      |
229
230## drm.createMediaKeySystem
231
232createMediaKeySystem(name: string): MediaKeySystem
233
234创建MediaKeySystem实例。
235
236**系统能力:** SystemCapability.Multimedia.Drm.Core
237
238**参数:**
239
240| 参数名     | 类型                                             | 必填 | 说明                           |
241| -------- | ----------------------------------------------- | ---- | ---------------------------- |
242| name  | string     | 是   | DRM解决方案名称。                   |
243
244**返回值:**
245
246| 类型                                             | 说明                           |
247| ----------------------------------------------- | ---------------------------- |
248| [MediaKeySystem](#mediakeysystem)           | MediaKeySystem实例。                   |
249
250**错误码:**
251
252以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
253
254| 错误码ID         | 错误信息        |
255| --------------- | --------------- |
256| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.               |
257| 24700101                |  All unknown errors                  |
258| 24700103                |  Meet max MediaKeySystem num limit                  |
259| 24700201                |  Fatal service error, for example, service died                  |
260
261**示例:**
262
263```ts
264import { drm } from '@kit.DrmKit';
265import { BusinessError } from '@kit.BasicServicesKit';
266try {
267  let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
268} catch (err) {
269  let error = err as BusinessError;
270  console.error(`createMediaKeySystem ERROR: ${error}`);  
271}
272```
273
274## drm.isMediaKeySystemSupported
275
276isMediaKeySystemSupported(name: string): boolean
277
278判断设备是否支持指定的DRM解决方案。
279
280**系统能力:** SystemCapability.Multimedia.Drm.Core
281
282**参数:**
283
284| 参数名     | 类型                                             | 必填 | 说明                           |
285| -------- | ----------------------------------------------- | ---- | ---------------------------- |
286| name  | string     | 是   | DRM解决方案名称。                   |
287
288**返回值:**
289
290| 类型                                             | 说明                           |
291| ----------------------------------------------- | ---------------------------- |
292| boolean          | 返回是否支持。                   |
293
294**错误码:**
295
296以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
297
298| 错误码ID         | 错误信息        |
299| --------------- | --------------- |
300| 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).               |
301| 24700101                |  All unknown errors                  |
302| 24700201                |  Fatal service error, for example, service died                  |
303
304**示例:**
305
306```ts
307import { drm } from '@kit.DrmKit';
308import { BusinessError } from '@kit.BasicServicesKit';
309
310try {
311  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm");
312  console.log("isMediaKeySystemSupported: ", supported);
313} catch (err) {
314  let error = err as BusinessError;
315  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
316}
317```
318
319## drm.isMediaKeySystemSupported
320
321isMediaKeySystemSupported(name: string, mimeType: string): boolean
322
323判断设备是否支持指定DRM解决方案及媒体类型。
324
325**系统能力:** SystemCapability.Multimedia.Drm.Core
326
327**参数:**
328
329| 参数名     | 类型                                             | 必填 | 说明                           |
330| -------- | ----------------------------------------------- | ---- | ---------------------------- |
331| name  | string     | 是   | DRM解决方案名称。                   |
332| mimeType  | string     | 是   | 媒体类型,由DRM解决方案决定具体的支持类型。                   |
333
334**返回值:**
335
336| 类型                                             | 说明                           |
337| ----------------------------------------------- | ---------------------------- |
338| boolean          | 返回是否支持。                   |
339
340**错误码:**
341
342以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
343
344| 错误码ID         | 错误信息        |
345| --------------- | --------------- |
346| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.                |
347| 24700101                |  All unknown errors                  |
348| 24700201                |  Fatal service error, for example, service died                  |
349
350**示例:**
351
352```ts
353import { drm } from '@kit.DrmKit';
354import { BusinessError } from '@kit.BasicServicesKit';
355
356try {
357  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm", "video/avc");
358  console.log("isMediaKeySystemSupported: ", supported);
359} catch (err) {
360  let error = err as BusinessError;
361  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
362}
363```
364
365## drm.isMediaKeySystemSupported
366
367isMediaKeySystemSupported(name: string, mimeType: string, level: ContentProtectionLevel): boolean
368
369判断设备是否支持指定DRM解决方案、媒体类型以及内容保护级别。
370
371**系统能力:** SystemCapability.Multimedia.Drm.Core
372
373**参数:**
374
375| 参数名     | 类型                                             | 必填 | 说明                           |
376| -------- | ----------------------------------------------- | ---- | ---------------------------- |
377| name  | string     | 是   | DRM解决方案名称。                   |
378| mimeType  | string     | 是   | 媒体类型,由DRM解决方案决定具体的支持类型。                   |
379| level  | [ContentProtectionLevel](#contentprotectionlevel)     | 是   | 内容保护级别。                   |
380
381**返回值:**
382
383| 类型                                             | 说明                           |
384| ----------------------------------------------- | ---------------------------- |
385| boolean          | 返回是否支持。                   |
386
387**错误码:**
388
389以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
390
391| 错误码ID         | 错误信息        |
392| --------------- | --------------- |
393| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.               |
394| 24700101                |  All unknown errors                  |
395| 24700201                |  Fatal service error, for example, service died                  |
396
397**示例:**
398
399```ts
400import { drm } from '@kit.DrmKit';
401import { BusinessError } from '@kit.BasicServicesKit';
402
403try {
404  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm", "video/avc", drm.ContentProtectionLevel.CONTENT_PROTECTION_LEVEL_SW_CRYPTO);
405  console.log("isMediaKeySystemSupported: ", supported);
406} catch (err) {
407  let error = err as BusinessError;
408  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
409}
410```
411
412## drm.getMediaKeySystemUuid<sup>12+</sup>
413
414getMediaKeySystemUuid(name: string): string;
415
416获取DRM解决方案支持的DRM内容保护系统唯一标识。
417
418**系统能力:** SystemCapability.Multimedia.Drm.Core
419
420**参数:**
421
422| 参数名     | 类型                                             | 必填 | 说明                           |
423| -------- | ----------------------------------------------- | ---- | ---------------------------- |
424| name  | string     | 是   | DRM解决方案名称。                   |
425
426**返回值:**
427
428| 类型                                             | 说明                           |
429| ----------------------------------------------- | ---------------------------- |
430| uuid  | string     | 是   | DRM内容保护系统的唯一标识。                   |
431
432**错误码:**
433
434以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
435
436| 错误码ID         | 错误信息        |
437| --------------- | --------------- |
438| 401                |  The parameter check failed.Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.                |
439| 24700101                |  All unknown errors                  |
440| 24700201                |  Fatal service error, for example, service died                  |
441
442**示例:**
443
444```ts
445import { drm } from '@kit.DrmKit';
446import { BusinessError } from '@kit.BasicServicesKit';
447try {
448  let uuid: String = drm.getMediaKeySystemUuid("com.clearplay.drm");
449  console.log("getMediaKeySystemUuid: ", uuid);
450} catch (err) {
451  let error = err as BusinessError;
452  console.error(`getMediaKeySystemUuid ERROR: ${error}`);  
453}
454```
455
456## drm.getMediaKeySystems<sup>12+</sup>
457
458getMediaKeySystems(): MediaKeySystemDescription[]
459
460获取设备支持的插件信息列表。
461
462**系统能力:** SystemCapability.Multimedia.Drm.Core
463
464**返回值:**
465
466| 类型                                             | 说明                           |
467| ----------------------------------------------- | ---------------------------- |
468| [MediaKeySystemDescription[]](#mediakeysystemdescription12)           | 设备支持的插件信息列表。                   |
469
470**错误码:**
471
472以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
473
474| 错误码ID         | 错误信息        |
475| --------------- | --------------- |
476| 24700101                |  All unknown errors                  |
477| 24700201                |  Fatal service error, for example, service died                  |
478
479**示例:**
480
481```ts
482import { drm } from '@kit.DrmKit';
483import { BusinessError } from '@kit.BasicServicesKit';
484try {
485  let description: drm.MediaKeySystemDescription[] = drm.getMediaKeySystems();
486} catch (err) {
487  let error = err as BusinessError;
488  console.error(`getMediaKeySystems ERROR: ${error}`);  
489}
490```
491
492## MediaKeySystem
493支持MediaKeySystem实例管理、设备证书申请与处理、会话创建、离线媒体密钥管理、获取DRM度量记录、设备属性等。在调用MediaKeySystem方法之前,必须使用[createMediaKeySystem](#drmcreatemediakeysystem)创建一个MediaKeySystem实例。
494
495### setConfigurationString
496
497setConfigurationString(configName: string, value: string): void
498
499设置字符串类型的配置信息。
500
501**系统能力:** SystemCapability.Multimedia.Drm.Core
502
503**参数:**
504
505| 参数名     | 类型                                             | 必填 | 说明                           |
506| -------- | ----------------------------------------------- | ---- | ---------------------------- |
507| configName  | string     | 是   | 配置属性名,不能为空,属性名参考[PreDefinedConfigName](#predefinedconfigname),具体支持的属性名由设备上DRM解决方案决定。                   |
508| value  | string     | 是   | 配置属性值。                   |
509
510**错误码:**
511
512以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
513
514| 错误码ID         | 错误信息        |
515| --------------- | --------------- |
516| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.|
517| 24700101                |  All unknown errors                  |
518| 24700201                |  Fatal service error, for example, service died                  |
519
520**示例:**
521
522```ts
523import { drm } from '@kit.DrmKit';
524import { BusinessError } from '@kit.BasicServicesKit';
525
526let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
527try {
528  mediaKeySystem.setConfigurationString("stringConfigName", "stringConfigValue"); // 确保stringConfigName是可配置的
529} catch (err) {
530  let error = err as BusinessError;
531  console.error(`setConfigurationString ERROR: ${error}`);
532}
533```
534
535### getConfigurationString
536
537getConfigurationString(configName: string): string
538
539获取字符串类型的配置属性值。
540
541**系统能力:** SystemCapability.Multimedia.Drm.Core
542
543**参数:**
544
545| 参数名     | 类型                                             | 必填 | 说明                           |
546| -------- | ----------------------------------------------- | ---- | ---------------------------- |
547| configName  | string     | 是   | 配置属性名,不能为空,属性名参考[PreDefinedConfigName](#predefinedconfigname),具体支持的属性名由设备上DRM解决方案决定。                   |
548
549**返回值:**
550
551| 类型                                             | 说明                           |
552| ----------------------------------------------- | ---------------------------- |
553| string          | 返回字符串类型的配置属性值。                   |
554
555**错误码:**
556
557以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
558
559| 错误码ID         | 错误信息        |
560| --------------- | --------------- |
561| 401                |  The 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).                              |
562| 24700101                |  All unknown errors                  |
563| 24700201                |  Fatal service error, for example, service died                  |
564
565**示例:**
566
567```ts
568import { drm } from '@kit.DrmKit';
569import { BusinessError } from '@kit.BasicServicesKit';
570
571let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
572try {
573  let configValue: string = mediaKeySystem.getConfigurationString("vendor");
574} catch (err) {
575  let error = err as BusinessError;
576  console.error(`getConfigurationString ERROR: ${error}`);  
577}
578```
579
580### setConfigurationByteArray
581
582setConfigurationByteArray(configName: string, value: Uint8Array): void
583
584设置数组类型的配置信息。
585
586**系统能力:** SystemCapability.Multimedia.Drm.Core
587
588**参数:**
589
590| 参数名     | 类型                                             | 必填 | 说明                           |
591| -------- | ----------------------------------------------- | ---- | ---------------------------- |
592| configName  | string     | 是   | 配置属性名,不能为空,属性名参考[PreDefinedConfigName](#predefinedconfigname),具体支持的属性名由设备上DRM解决方案决定。                   |
593| value  | Uint8Array     | 是   | 数组类型的配置属性值,具体属性值由设备上DRM解决方案决定。                   |
594
595**错误码:**
596
597以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
598
599| 错误码ID         | 错误信息        |
600| --------------- | --------------- |
601| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.               |
602| 24700101                |  All unknown errors.                  |
603| 24700201                |  Fatal service error, for example, service died.                  |
604
605**示例:**
606
607```ts
608import { drm } from '@kit.DrmKit';
609import { BusinessError } from '@kit.BasicServicesKit';
610
611let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
612// 按实际需求填写configValue属性值,请按实际值传入
613let configValue: Uint8Array = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
614try {
615  // 需确认当前DRM解决方案的byteArrayConfigName属性是可配置的
616  mediaKeySystem.setConfigurationByteArray("byteArrayConfigName", configValue);
617} catch (err) {
618  let error = err as BusinessError;
619  console.error(`setConfigurationByteArray ERROR: ${error}`);  
620}
621```
622
623### getConfigurationByteArray
624
625getConfigurationByteArray(configName: string): Uint8Array
626
627获取数组类型的配置信息。
628
629**系统能力:** SystemCapability.Multimedia.Drm.Core
630
631**参数:**
632
633| 参数名     | 类型                                             | 必填 | 说明                           |
634| -------- | ----------------------------------------------- | ---- | ---------------------------- |
635| configName  | string     | 是   | 配置属性名,不能为空,属性名参考[PreDefinedConfigName](#predefinedconfigname),具体支持的属性名由设备上DRM解决方案决定。                   |
636
637**返回值:**
638
639| 类型                                             | 说明                           |
640| ----------------------------------------------- | ---------------------------- |
641| Uint8Array          | 数组类型的配置属性值。                   |
642
643**错误码:**
644
645以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
646
647| 错误码ID         | 错误信息        |
648| --------------- | --------------- |
649| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.        |
650| 24700101                |  All unknown errors                  |
651| 24700201                |  Fatal service error, for example, service died                  |
652
653**示例:**
654
655```ts
656import { drm } from '@kit.DrmKit';
657import { BusinessError } from '@kit.BasicServicesKit';
658
659let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
660try {
661  let configValue: Uint8Array = mediaKeySystem.getConfigurationByteArray("deviceUniqueId"); // 确保deviceUniqueId属性是存在的
662} catch (err) {
663  let error = err as BusinessError;
664  console.error(`getConfigurationByteArray ERROR: ${error}`);  
665}
666```
667
668### getStatistics
669
670getStatistics(): StatisticKeyValue[]
671
672获取性能度量记录。其中包括当前会话数、插件版本信息、每个会话最大三次解密耗时、解密次数和解密失败次数。
673
674**系统能力:** SystemCapability.Multimedia.Drm.Core
675
676**返回值:**
677
678| 类型                                             | 说明                           |
679| ----------------------------------------------- | ---------------------------- |
680| [StatisticKeyValue[]](#statistickeyvalue)          | 度量记录。                   |
681
682**错误码:**
683
684以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
685
686| 错误码ID         | 错误信息        |
687| --------------- | --------------- |
688| 24700101                |  All unknown errors                  |
689| 24700201                |  Fatal service error, for example, service died                  |
690
691**示例:**
692
693```ts
694import { drm } from '@kit.DrmKit';
695import { BusinessError } from '@kit.BasicServicesKit';
696
697let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
698try {
699  let statisticKeyValue: drm.StatisticKeyValue[] = mediaKeySystem.getStatistics();
700} catch (err) {
701  let error = err as BusinessError;
702  console.error(`getConfigurationByteArray ERROR: ${error}`);
703}
704```
705
706### getMaxContentProtectionLevel
707
708getMaxContentProtectionLevel(): ContentProtectionLevel
709
710获取当前DRM解决方案支持的最大内容保护级别。
711
712**系统能力:** SystemCapability.Multimedia.Drm.Core
713
714**返回值:**
715
716| 类型                                             | 说明                           |
717| ----------------------------------------------- | ---------------------------- |
718| [ContentProtectionLevel](#contentprotectionlevel)          | 返回设备支持的最大内容保护级别。                   |
719
720**错误码:**
721
722以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
723
724| 错误码ID         | 错误信息        |
725| --------------- | --------------- |
726| 24700101                |  All unknown errors                  |
727| 24700201                |  Fatal service error, for example, service died                  |
728
729**示例:**
730
731```ts
732import { drm } from '@kit.DrmKit';
733import { BusinessError } from '@kit.BasicServicesKit';
734
735let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
736try {
737  let maxLevel: drm.ContentProtectionLevel = mediaKeySystem.getMaxContentProtectionLevel();
738} catch (err) {
739  let error = err as BusinessError;
740  console.error(`getConfigurationByteArray ERROR: ${error}`);
741}
742```
743
744### generateKeySystemRequest
745
746generateKeySystemRequest(): Promise<ProvisionRequest\>
747
748生成获取mediaKeySystem设备证书的请求。
749
750**系统能力:** SystemCapability.Multimedia.Drm.Core
751
752**返回值:**
753
754| 类型                                             | 说明                           |
755| ----------------------------------------------- | ---------------------------- |
756| Promise<[ProvisionRequest](#provisionrequest)\>          | Promise对象,mediaKeySystem设备证书的请求。设备上如果已存在设备证书,会返回失败。   |
757
758**错误码:**
759
760以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
761
762| 错误码ID         | 错误信息        |
763| --------------- | --------------- |
764| 24700101                |  All unknown errors                  |
765| 24700201                |  Fatal service error, for example, service died                  |
766
767**示例:**
768
769```ts
770import { drm } from '@kit.DrmKit';
771import { BusinessError } from '@kit.BasicServicesKit';
772
773let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
774// 设备上已有设备证书的情况下不需要调用
775mediaKeySystem.generateKeySystemRequest().then((ProvisionRequest: drm.ProvisionRequest) => {
776  console.log("generateKeySystemRequest");
777}).catch((err: BusinessError) => {
778  console.error(`generateKeySystemRequest: ERROR: ${err}`);
779});
780```
781
782### processKeySystemResponse
783
784processKeySystemResponse(response: Uint8Array): Promise<void\>
785
786处理获得的设备证书请求的响应。
787
788**系统能力:** SystemCapability.Multimedia.Drm.Core
789
790**参数:**
791
792| 参数名     | 类型                                             | 必填 | 说明                           |
793| -------- | ----------------------------------------------- | ---- | ---------------------------- |
794| response  | Uint8Array     | 是   | 设备证书响应。                   |
795
796**返回值:**
797
798| 类型                                             | 说明                           |
799| ----------------------------------------------- | ---------------------------- |
800| Promise<void\>          | Promise对象。                   |
801
802**错误码:**
803
804以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
805
806| 错误码ID         | 错误信息        |
807| --------------- | --------------- |
808| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.         |
809| 24700101                |  All unknown errors                  |
810| 24700201                |  Fatal service error, for example, service died                  |
811
812**示例:**
813
814```ts
815import { drm } from '@kit.DrmKit';
816import { BusinessError } from '@kit.BasicServicesKit';
817
818let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
819// keySystemResponse是从DRM服务获取的设备证书响应,请按实际值传入;
820let keySystemResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
821mediaKeySystem.processKeySystemResponse(keySystemResponse).then(() => {
822  console.log("processKeySystemResponse");
823}).catch((err: BusinessError) => {
824  console.error(`processKeySystemResponse: ERROR: ${err}`);
825});
826```
827
828### getCertificateStatus
829
830getCertificateStatus():CertificateStatus
831
832获取设备证书状态值。
833
834**系统能力:** SystemCapability.Multimedia.Drm.Core
835
836**返回值:**
837
838| 类型                                             | 说明                           |
839| ----------------------------------------------- | ---------------------------- |
840| [CertificateStatus](#certificatestatus)          | 设备证书状态值。                   |
841
842**错误码:**
843
844以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
845
846| 错误码ID         | 错误信息        |
847| --------------- | --------------- |
848| 24700101                |  All unknown errors                  |
849| 24700201                |  Fatal service error, for example, service died                  |
850
851**示例:**
852
853```ts
854import { drm } from '@kit.DrmKit';
855import { BusinessError } from '@kit.BasicServicesKit';
856
857let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
858try {
859  let certificateStatus: drm.CertificateStatus = mediaKeySystem.getCertificateStatus();
860} catch (err) {
861  let error = err as BusinessError;
862  console.error(`getCertificateStatus ERROR: ${error}`);
863}
864```
865
866### on('keySystemRequired')
867
868on(type: 'keySystemRequired', callback: (eventInfo: EventInfo) => void): void
869
870监听设备证书请求事件,获取事件信息。
871
872**系统能力:** SystemCapability.Multimedia.Drm.Core
873
874**参数:**
875
876| 参数名      | 类型                  | 必填 | 说明                                  |
877| -------- | -------------------- | ---- | ------------------------------------- |
878| type     | string               | 是   | 事件类型,MediaKeySystem实例创建成功后可监听,需要设备证书时触发该事件。 |
879| callback | Callback\<[EventInfo](#eventinfo)\> | 是   | 回调函数,返回事件信息。只要有该事件返回就证明需请求设备证书。                 |
880
881**错误码:**
882
883以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
884
885| 错误码ID         | 错误信息        |
886| --------------- | --------------- |
887| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.               |
888| 24700101                |  All unknown errors                  |
889
890**示例:**
891
892```ts
893import { drm } from '@kit.DrmKit';
894
895let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
896mediaKeySystem.on('keySystemRequired', (eventInfo: drm.EventInfo) => {
897  console.log('keySystemRequired ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
898});
899```
900
901### off('keySystemRequired')
902
903off(type: 'keySystemRequired', callback?: (eventInfo: EventInfo) => void): void
904
905注销设备证书请求事件的监听。
906
907**系统能力:** SystemCapability.Multimedia.Drm.Core
908
909**参数:**
910
911| 参数名      | 类型                  | 必填 | 说明                                  |
912| -------- | -------------------- | ---- | ------------------------------------- |
913| type     | string               | 是   | 监听事件类型,MediaKeySystem实例创建成功后可监听。 |
914| callback | Callback\<[EventInfo](#eventinfo)\> | 否   | 回调函数,返回事件信息。可选。                |
915
916**错误码:**
917
918以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
919
920| 错误码ID         | 错误信息        |
921| --------------- | --------------- |
922| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.               |
923| 24700101                |  All unknown errors                  |
924
925**示例:**
926
927```ts
928let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
929mediaKeySystem.off('keySystemRequired');
930```
931
932### createMediaKeySession
933
934createMediaKeySession(level: ContentProtectionLevel): MediaKeySession
935
936创建指定内容保护级别的MediaKeySession实例。
937
938**系统能力:** SystemCapability.Multimedia.Drm.Core
939
940**参数:**
941
942| 参数名     | 类型                                             | 必填 | 说明                           |
943| -------- | ----------------------------------------------- | ---- | ---------------------------- |
944| level  | [ContentProtectionLevel](#contentprotectionlevel)     | 是   | 内容保护级别。                   |
945
946**返回值:**
947
948| 类型                                             | 说明                           |
949| ----------------------------------------------- | ---------------------------- |
950| [MediaKeySession](#mediakeysession)          | MediaKeySession实例。                   |
951
952**错误码:**
953
954以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
955
956| 错误码ID         | 错误信息        |
957| --------------- | --------------- |
958| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.The param level exceeds reasonable range, please use value in ContentProtectionLevel.          |
959| 24700101                 |  All unknown errors                  |
960| 24700104                 |  Meet max MediaKeySession num limit                  |
961| 24700201                |  Fatal service error, for example, service died                  |
962
963**示例:**
964
965```ts
966import { drm } from '@kit.DrmKit';
967import { BusinessError } from '@kit.BasicServicesKit';
968
969let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
970try {
971  let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession(drm.ContentProtectionLevel.CONTENT_PROTECTION_LEVEL_SW_CRYPTO);
972} catch (err) {
973  let error = err as BusinessError;
974  console.error(`createMediaKeySession ERROR: ${error}`);
975}
976```
977
978### createMediaKeySession
979
980createMediaKeySession(): MediaKeySession
981
982创建DRM解决方案默认内容保护级别的MediaKeySession实例。
983
984**系统能力:** SystemCapability.Multimedia.Drm.Core
985
986**返回值:**
987
988| 类型                                             | 说明                           |
989| ----------------------------------------------- | ---------------------------- |
990| [MediaKeySession](#mediakeysession)          | MediaKeySession实例。                   |
991
992**错误码:**
993
994以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
995
996| 错误码ID         | 错误信息        |
997| --------------- | --------------- |
998| 24700101                |  All unknown errors                  |
999| 24700104                 |  Meet max MediaKeySession num limit                  |
1000| 24700201                |  Fatal service error, for example, service died                  |
1001
1002**示例:**
1003
1004```ts
1005import { drm } from '@kit.DrmKit';
1006import { BusinessError } from '@kit.BasicServicesKit';
1007
1008let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1009try {
1010  let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1011} catch (err) {
1012  let error = err as BusinessError;
1013  console.error(`createMediaKeySession ERROR: ${error}`);
1014}
1015```
1016
1017### getOfflineMediaKeyIds
1018
1019getOfflineMediaKeyIds(): Uint8Array[]
1020
1021获取离线媒体密钥标识列表。
1022
1023**系统能力:** SystemCapability.Multimedia.Drm.Core
1024
1025
1026**返回值:**
1027
1028| 类型                                             | 说明                           |
1029| ----------------------------------------------- | ---------------------------- |
1030| Uint8Array[]          | 离线媒体密钥标识列表。                   |
1031
1032**错误码:**
1033
1034以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1035
1036| 错误码ID         | 错误信息        |
1037| --------------- | --------------- |
1038| 24700101                |  All unknown errors                  |
1039| 24700201                |  Fatal service error, for example, service died                  |
1040
1041**示例:**
1042
1043```ts
1044import { drm } from '@kit.DrmKit';
1045import { BusinessError } from '@kit.BasicServicesKit';
1046
1047let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1048try {
1049  let offlineMediaKeyIds: Uint8Array[] = mediaKeySystem.getOfflineMediaKeyIds();
1050} catch (err) {
1051  let error = err as BusinessError;
1052  console.error(`getOfflineMediaKeyIds ERROR: ${error}`);
1053}
1054```
1055
1056### getOfflineMediaKeyStatus
1057
1058getOfflineMediaKeyStatus(mediaKeyId: Uint8Array): OfflineMediaKeyStatus
1059
1060获取指定离线媒体密钥标识的媒体密钥的状态值。
1061
1062**系统能力:** SystemCapability.Multimedia.Drm.Core
1063
1064**参数:**
1065
1066| 参数名     | 类型                                             | 必填 | 说明                           |
1067| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1068| mediaKeyId | Uint8Array     | 是   | 离线媒体密钥标识。                   |
1069
1070**返回值:**
1071
1072| 类型                                             | 说明                           |
1073| ----------------------------------------------- | ---------------------------- |
1074| [OfflineMediaKeyStatus](#offlinemediakeystatus)          | 离线媒体密钥状态值。                   |
1075
1076**错误码:**
1077
1078以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1079
1080| 错误码ID         | 错误信息        |
1081| --------------- | --------------- |
1082| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.            |
1083| 24700101                |  All unknown errors                  |
1084| 24700201                |  Fatal service error, for example, service died                  |
1085
1086**示例:**
1087
1088```ts
1089import { drm } from '@kit.DrmKit';
1090import { BusinessError } from '@kit.BasicServicesKit';
1091
1092let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1093// mediaKeyId是processMediaKeyResponse或getOfflineMediaKeyIds接口返回的媒体密钥标识,请按实际值传入
1094let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1095try {
1096  let configValue: drm.OfflineMediaKeyStatus = mediaKeySystem.getOfflineMediaKeyStatus(mediaKeyId);
1097} catch (err) {
1098  let error = err as BusinessError;
1099  console.error(`getOfflineMediaKeyStatus ERROR: ${error}`);
1100}
1101```
1102
1103### clearOfflineMediaKeys
1104
1105clearOfflineMediaKeys(mediaKeyId: Uint8Array): void
1106
1107删除指定媒体密钥标识的离线媒体密钥。
1108
1109**系统能力:** SystemCapability.Multimedia.Drm.Core
1110
1111**参数:**
1112
1113| 参数名     | 类型                                             | 必填 | 说明                           |
1114| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1115| mediaKeyId  | Uint8Array     | 是   | 离线媒体密钥标识。            |
1116
1117**错误码:**
1118
1119以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1120
1121| 错误码ID         | 错误信息        |
1122| --------------- | --------------- |
1123| 401                |  The parameter check failed.Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.           |
1124| 24700101                |  All unknown errors                  |
1125| 24700201                |  Fatal service error, for example, service died                  |
1126
1127**示例:**
1128
1129```ts
1130import { drm } from '@kit.DrmKit';
1131import { BusinessError } from '@kit.BasicServicesKit';
1132
1133let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1134// mediaKeyId是processMediaKeyResponse或getOfflineMediaKeyIds接口返回的媒体密钥标识,请按实际值传入
1135let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1136try {
1137  mediaKeySystem.clearOfflineMediaKeys(mediaKeyId);
1138} catch (err) {
1139  let error = err as BusinessError;
1140  console.error(`clearOfflineMediaKeys ERROR: ${error}`);
1141}
1142```
1143
1144### destroy
1145
1146destroy(): void
1147
1148销毁MediaKeySystem实例。
1149
1150**系统能力:** SystemCapability.Multimedia.Drm.Core
1151
1152**错误码:**
1153
1154以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1155
1156| 错误码ID         | 错误信息        |
1157| --------------- | --------------- |
1158| 24700101                |  All unknown errors                  |
1159| 24700201                |  Fatal service error, for example, service died                  |
1160
1161**示例:**
1162
1163```ts
1164import { drm } from '@kit.DrmKit';
1165import { BusinessError } from '@kit.BasicServicesKit';
1166
1167let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1168try {
1169  mediaKeySystem.destroy();
1170} catch (err) {
1171  let error = err as BusinessError;
1172  console.error(`mediaKeySystem destroy ERROR: ${error}`);
1173}
1174```
1175
1176## MediaKeySession
1177支持媒体密钥管理。在调用MediaKeySession方法之前,必须使用[createMediaKeySession](#createmediakeysession)获取一个MediaKeySession实例。
1178
1179### generateMediaKeyRequest
1180
1181generateMediaKeyRequest(mimeType: string, initData: Uint8Array, mediaKeyType: number, options?: OptionsData[]): Promise<MediaKeyRequest\>
1182
1183生成媒体密钥请求。
1184
1185**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1186
1187**系统能力:** SystemCapability.Multimedia.Drm.Core
1188
1189**参数:**
1190
1191| 参数名     | 类型                                             | 必填 | 说明                           |
1192| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1193| mimeType  | string     | 是   | 媒体类型,由DRM解决方案决定具体的支持类型。                   |
1194| initData  | Uint8Array     | 是   | 初始数据。                   |
1195| mediaKeyType| number     | 是   | 媒体密钥类型。                   | 0表示在线,1表示离线 |
1196| options  | [OptionsData[]](#optionsdata)     | 否   | 可选数据。                   |
1197
1198**返回值:**
1199
1200| 类型                                             | 说明                           |
1201| ----------------------------------------------- | ---------------------------- |
1202| Promise<[MediaKeyRequest](#mediakeyrequest)\>          | Promise对象,媒体密钥请求。                   |
1203
1204**错误码:**
1205
1206以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1207
1208| 错误码ID         | 错误信息        |
1209| --------------- | --------------- |
1210| 401                | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.              |
1211| 24700101                |  All unknown errors                  |
1212| 24700201                |  Fatal service error, for example, service died                  |
1213
1214**示例:**
1215
1216```ts
1217import { drm } from '@kit.DrmKit';
1218import { BusinessError } from '@kit.BasicServicesKit';
1219
1220let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1221let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1222// pssh数据为版权保护系统描述头,封装在加密码流中,mp4文件中位于pssh box、dash码流中位于mpd及mp4的pssh box、hls+ts的码流位于m3u8及每个ts片段中,请按实际值传入
1223let uint8pssh = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1224mediaKeySession.generateMediaKeyRequest("video/avc", uint8pssh, drm.MediaKeyType.MEDIA_KEY_TYPE_ONLINE).then((mediaKeyRequest: drm.MediaKeyRequest) =>{
1225  console.log('generateMediaKeyRequest' + mediaKeyRequest);
1226}).catch((err: BusinessError) => {
1227  console.error(`generateMediaKeyRequest: ERROR: ${err}`);
1228});
1229```
1230
1231### processMediaKeyResponse
1232
1233processMediaKeyResponse(response: Uint8Array): Promise<Uint8Array\>
1234
1235处理媒体密钥响应。
1236
1237**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1238
1239**系统能力:** SystemCapability.Multimedia.Drm.Core
1240
1241**参数:**
1242
1243| 参数名     | 类型                                             | 必填 | 说明                           |
1244| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1245| response  | Uint8Array     | 是   | 媒体密钥响应。                   |
1246
1247**返回值:**
1248
1249| 类型                                             | 说明                           |
1250| ----------------------------------------------- | ---------------------------- |
1251| Promise<Uint8Array\>          | Promise对象,媒体密钥标识。                   |
1252
1253**错误码:**
1254
1255以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1256
1257| 错误码ID         | 错误信息        |
1258| --------------- | --------------- |
1259| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.            |
1260| 24700101                |  All unknown errors                  |
1261| 24700201                |  Fatal service error, for example, service died                  |
1262
1263**示例:**
1264
1265```ts
1266import { drm } from '@kit.DrmKit';
1267import { BusinessError } from '@kit.BasicServicesKit';
1268
1269let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1270let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1271// mediaKeyResponse是从DRM服务获取的媒体密钥响应,按实际值填入
1272let mediaKeyResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1273mediaKeySession.processMediaKeyResponse(mediaKeyResponse).then((mediaKeyId: Uint8Array) => {
1274  console.log('processMediaKeyResponse:' + mediaKeyId);
1275}).catch((err: BusinessError) => {
1276  console.error(`processMediaKeyResponse: ERROR: ${err}`);
1277});
1278```
1279
1280### checkMediaKeyStatus
1281
1282 checkMediaKeyStatus(): MediaKeyStatus[]
1283
1284检查当前媒体密钥状态。
1285
1286**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1287
1288**系统能力:** SystemCapability.Multimedia.Drm.Core
1289
1290**返回值:**
1291
1292| 类型                                             | 说明                           |
1293| ----------------------------------------------- | ---------------------------- |
1294| [MediaKeyStatus[]](#mediakeystatus)          | 当前媒体密钥状态值。                   |
1295
1296**错误码:**
1297
1298以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1299
1300| 错误码ID         | 错误信息        |
1301| --------------- | --------------- |
1302| 24700101                |  All unknown errors                  |
1303| 24700201                |  Fatal service error, for example, service died                  |
1304
1305**示例:**
1306
1307```ts
1308import { drm } from '@kit.DrmKit';
1309import { BusinessError } from '@kit.BasicServicesKit';
1310
1311let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1312let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1313try {
1314  let keyStatus: drm.MediaKeyStatus[] =  mediaKeySession.checkMediaKeyStatus();
1315} catch (err) {
1316  let error = err as BusinessError;
1317  console.error(`checkMediaKeyStatus ERROR: ${error}`);
1318}
1319```
1320
1321### clearMediaKeys
1322
1323clearMediaKeys(): void
1324
1325清除当前媒体密钥。
1326
1327**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1328
1329**系统能力:** SystemCapability.Multimedia.Drm.Core
1330
1331**错误码:**
1332
1333以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1334
1335| 错误码ID         | 错误信息        |
1336| --------------- | --------------- |
1337| 24700101                |  All unknown errors                  |
1338| 24700201                |  Fatal service error, for example, service died                  |
1339
1340**示例:**
1341
1342```ts
1343import { drm } from '@kit.DrmKit';
1344import { BusinessError } from '@kit.BasicServicesKit';
1345
1346let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1347let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1348// mediaKeyResponse是从DRM服务获取的媒体密钥响应,按实际值填入
1349let mediaKeyResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1350mediaKeySession.processMediaKeyResponse(mediaKeyResponse).then((mediaKeyId: Uint8Array) => {
1351  console.log('processMediaKeyResponse:' + mediaKeyId);
1352}).catch((err: BusinessError) => {
1353  console.error(`processMediaKeyResponse: ERROR: ${err}`);
1354});
1355try {
1356  mediaKeySession.clearMediaKeys();
1357} catch (err) {
1358  let error = err as BusinessError;
1359  console.error(`clearMediaKeys ERROR: ${error}`);
1360}
1361```
1362
1363### generateOfflineReleaseRequest
1364
1365generateOfflineReleaseRequest(mediaKeyId: Uint8Array): Promise<Uint8Array\>
1366
1367生成离线媒体密钥释放请求。
1368
1369**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1370
1371**系统能力:** SystemCapability.Multimedia.Drm.Core
1372
1373**参数:**
1374
1375| 参数名     | 类型                                             | 必填 | 说明                           |
1376| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1377| mediaKeyId  | Uint8Array    | 是   | 离线媒体密钥标识                   |
1378
1379**返回值:**
1380
1381| 类型                                             | 说明                           |
1382| ----------------------------------------------- | ---------------------------- |
1383| Promise<Uint8Array\>          | Promise对象,设备上的DRM解决方案支持离线媒体密钥释放处理,则返回离线媒体密钥释放请求。                   |
1384
1385**错误码:**
1386
1387以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1388
1389| 错误码ID         | 错误信息        |
1390| --------------- | --------------- |
1391| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.         |
1392| 24700101                |  All unknown errors                  |
1393| 24700201                |  Fatal service error, for example, service died                  |
1394
1395**示例:**
1396
1397```ts
1398import { drm } from '@kit.DrmKit';
1399import { BusinessError } from '@kit.BasicServicesKit';
1400
1401let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1402let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1403// mediaKeyId是processMediaKeyResponse或getOfflineMediaKeyIds接口返回的媒体密钥标识,请按实际值传入
1404let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1405mediaKeySession.generateOfflineReleaseRequest(mediaKeyId).then((offlineReleaseRequest: Uint8Array) => {
1406  console.log('generateOfflineReleaseRequest:' + offlineReleaseRequest);
1407}).catch((err: BusinessError) => {
1408  console.error(`generateOfflineReleaseRequest: ERROR: ${err}`);
1409});
1410```
1411
1412### processOfflineReleaseResponse
1413
1414processOfflineReleaseResponse(mediaKeyId: Uint8Array, response: Uint8Array): Promise<void\>
1415
1416处理离线媒体密钥释放响应。
1417
1418**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1419
1420**系统能力:** SystemCapability.Multimedia.Drm.Core
1421
1422**参数:**
1423
1424| 参数名     | 类型                                             | 必填 | 说明                           |
1425| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1426| mediaKeyId  | Uint8Array     | 是   | 离线媒体密钥标识。                   |
1427| response  | Uint8Array     | 是   | 离线媒体密钥释放响应。                   |
1428
1429**返回值:**
1430
1431| 类型                                             | 说明                           |
1432| ----------------------------------------------- | ---------------------------- |
1433| Promise<void\>          | Promise对象,设备上的DRM解决方案支持离线媒体密钥释放处理,则返回。                   |
1434
1435**错误码:**
1436
1437以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1438
1439| 错误码ID         | 错误信息        |
1440| --------------- | --------------- |
1441| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.            |
1442| 24700101                |  All unknown errors                  |
1443| 24700201                |  Fatal service error, for example, service died                  |
1444
1445**示例:**
1446
1447```ts
1448import { drm } from '@kit.DrmKit';
1449import { BusinessError } from '@kit.BasicServicesKit';
1450
1451let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1452let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1453// mediaKeyId是processMediaKeyResponse或getOfflineMediaKeyIds接口返回的媒体密钥标识,请按实际长度申请内存
1454let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1455mediaKeySession.generateOfflineReleaseRequest(mediaKeyId).then((offlineReleaseRequest: Uint8Array) => {
1456  console.log('generateOfflineReleaseRequest:' + offlineReleaseRequest);
1457}).catch((err: BusinessError) => {
1458  console.error(`generateOfflineReleaseRequest: ERROR: ${err}`);
1459});
1460// offlineReleaseResponse是从DRM服务获取的离线媒体密钥释放响应,请按实际长度申请内存
1461let offlineReleaseResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1462mediaKeySession.processOfflineReleaseResponse(mediaKeyId, offlineReleaseResponse).then(() => {
1463  console.log('processOfflineReleaseResponse');
1464}).catch((err: BusinessError) => {
1465  console.error(`processOfflineReleaseResponse: ERROR: ${err}`);
1466});
1467```
1468
1469### restoreOfflineMediaKeys
1470
1471restoreOfflineMediaKeys(mediaKeyId: Uint8Array): Promise<void\>
1472
1473恢复离线媒体密钥。
1474
1475**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1476
1477**系统能力:** SystemCapability.Multimedia.Drm.Core
1478
1479**参数:**
1480
1481| 参数名     | 类型                                             | 必填 | 说明                           |
1482| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1483| mediaKeyId  | Uint8Array     | 是   | 离线媒体密钥标识。                   |
1484
1485**返回值:**
1486
1487| 类型                                             | 说明                           |
1488| ----------------------------------------------- | ---------------------------- |
1489| Promise<void\>          | Promise对象。                   |
1490
1491**错误码:**
1492
1493以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1494
1495| 错误码ID         | 错误信息        |
1496| --------------- | --------------- |
1497| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.              |
1498| 24700101                |  All unknown errors                  |
1499| 24700201                |  Fatal service error, for example, service died                  |
1500
1501**示例:**
1502
1503```ts
1504import { drm } from '@kit.DrmKit';
1505import { BusinessError } from '@kit.BasicServicesKit';
1506
1507let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1508let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1509// mediaKeyId是processMediaKeyResponse或getOfflineMediaKeyIds接口返回的媒体密钥标识,请按实际数据传入
1510let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
1511mediaKeySession.restoreOfflineMediaKeys(mediaKeyId).then(() => {
1512  console.log("restoreOfflineMediaKeys");
1513}).catch((err: BusinessError) => {
1514  console.error(`restoreOfflineMediaKeys: ERROR: ${err}`);
1515});
1516```
1517
1518### getContentProtectionLevel
1519
1520getContentProtectionLevel(): ContentProtectionLevel
1521
1522获取当前会话的内容保护级别。
1523
1524**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1525
1526**系统能力:** SystemCapability.Multimedia.Drm.Core
1527
1528**返回值:**
1529
1530| 类型                                             | 说明                           |
1531| ----------------------------------------------- | ---------------------------- |
1532| [ContentProtectionLevel](#contentprotectionlevel)          | 返回当前会话内容保护级别。                   |
1533
1534**错误码:**
1535
1536以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1537
1538| 错误码ID         | 错误信息        |
1539| --------------- | --------------- |
1540| 24700101                |  All unknown errors                  |
1541| 24700201                |  Fatal service error, for example, service died                  |
1542
1543**示例:**
1544
1545```ts
1546import { drm } from '@kit.DrmKit';
1547import { BusinessError } from '@kit.BasicServicesKit';
1548
1549let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1550let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1551try {
1552  let contentProtectionLevel: drm.ContentProtectionLevel = mediaKeySession.getContentProtectionLevel();
1553} catch (err) {
1554  let error = err as BusinessError;
1555  console.error(`getContentProtectionLevel ERROR: ${error}`);
1556}
1557```
1558
1559### requireSecureDecoderModule
1560
1561requireSecureDecoderModule(mimeType: string): boolean
1562
1563是否需要安全解码。
1564
1565**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1566
1567**系统能力:** SystemCapability.Multimedia.Drm.Core
1568
1569**参数:**
1570
1571| 参数名     | 类型                                             | 必填 | 说明                           |
1572| -------- | ----------------------------------------------- | ---- | ---------------------------- |
1573| mimeType  | string     | 是   | 媒体类型,由DRM解决方案决定具体的支持类型。                   |
1574
1575**返回值:**
1576
1577| 类型                                             | 说明                           |
1578| ----------------------------------------------- | ---------------------------- |
1579| boolean          | 是否需要安全解码,true表示需要安全解码,false表示不需要安全解码。                   |
1580
1581**错误码:**
1582
1583以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1584
1585| 错误码ID         | 错误信息        |
1586| --------------- | --------------- |
1587| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.      |
1588| 24700101                |  All unknown errors                  |
1589| 24700201                |  Fatal service error, for example, service died                  |
1590
1591**示例:**
1592
1593```ts
1594import { drm } from '@kit.DrmKit';
1595import { BusinessError } from '@kit.BasicServicesKit';
1596
1597let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1598let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1599try {
1600  let status: boolean = mediaKeySession.requireSecureDecoderModule("video/avc");
1601} catch (err) {
1602  let error = err as BusinessError;
1603  console.error(`requireSecureDecoderModule ERROR: ${error}`);
1604} 
1605```
1606
1607### on('keyRequired')
1608
1609on(type: 'keyRequired', callback: (eventInfo: EventInfo) => void): void
1610
1611监听密钥请求事件。
1612
1613**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1614
1615**系统能力:** SystemCapability.Multimedia.Drm.Core
1616
1617**参数:**
1618
1619| 参数名      | 类型                  | 必填 | 说明                                  |
1620| -------- | -------------------- | ---- | ------------------------------------- |
1621| type     | string               | 是   | 事件类型,固定为'keyRequired',当播放DRM节目需要获取媒体密钥时触发。 |
1622| callback | Callback\<[EventInfo](#eventinfo)\> | 是   | 回调函数,返回事件信息。                 |
1623
1624**错误码:**
1625
1626以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1627
1628| 错误码ID         | 错误信息        |
1629| --------------- | --------------- |
1630| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.         |
1631| 24700101                |  All unknown errors                  |
1632
1633**示例:**
1634
1635```ts
1636import { drm } from '@kit.DrmKit';
1637
1638let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1639let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1640mediaKeySession.on('keyRequired', (eventInfo: drm.EventInfo) => {
1641  console.log('keyRequired ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
1642});
1643```
1644
1645### off('keyRequired')
1646
1647off(type: 'keyRequired', callback?: (eventInfo: EventInfo) => void): void
1648
1649注销密钥请求事件监听。
1650
1651**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1652
1653**系统能力:** SystemCapability.Multimedia.Drm.Core
1654
1655**参数:**
1656
1657| 参数名      | 类型                  | 必填 | 说明                                  |
1658| -------- | -------------------- | ---- | ------------------------------------- |
1659| type     | string               | 是   | 监听事件类型,固定为'keyRequired'。 |
1660| callback | Callback\<[EventInfo](#eventinfo)\> | 否   | 回调函数,返回事件信息。可选。                |
1661
1662**错误码:**
1663
1664以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1665
1666| 错误码ID         | 错误信息        |
1667| --------------- | --------------- |
1668| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.             |
1669| 24700101                |  All unknown errors                  |
1670
1671**示例:**
1672
1673```ts
1674import { drm } from '@kit.DrmKit';
1675
1676let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1677let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1678mediaKeySession.off('keyRequired');
1679```
1680
1681### on('keyExpired')
1682
1683on(type: 'keyExpired', callback: (eventInfo: EventInfo) => void): void
1684
1685监听密钥过期事件。
1686
1687**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1688
1689**系统能力:** SystemCapability.Multimedia.Drm.Core
1690
1691**参数:**
1692
1693| 参数名      | 类型                  | 必填 | 说明                                  |
1694| -------- | -------------------- | ---- | ------------------------------------- |
1695| type     | string               | 是   | 监听事件类型,固定为'keyExpired'。密钥过期时触发。 |
1696| callback | Callback\<[EventInfo](#eventinfo)\> | 是   | 回调函数,返回事件信息。                 |
1697
1698**错误码:**
1699
1700以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1701
1702| 错误码ID         | 错误信息        |
1703| --------------- | --------------- |
1704| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.          |
1705| 24700101                |  All unknown errors                  |
1706
1707**示例:**
1708
1709```ts
1710import { drm } from '@kit.DrmKit';
1711
1712let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1713let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1714mediaKeySession.on('keyExpired', (eventInfo: drm.EventInfo) => {
1715  console.log('keyExpired ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
1716});
1717```
1718
1719### off('keyExpired')
1720
1721off(type: 'keyExpired', callback?: (eventInfo: EventInfo) => void): void
1722
1723注销密钥过期事件监听。
1724
1725**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1726
1727**系统能力:** SystemCapability.Multimedia.Drm.Core
1728
1729**参数:**
1730
1731| 参数名      | 类型                  | 必填 | 说明                                  |
1732| -------- | -------------------- | ---- | ------------------------------------- |
1733| type     | string               | 是   | 监听事件类型,固定为'keyExpired'。 |
1734| callback | Callback\<[EventInfo](#eventinfo)\> | 否   | 回调函数,返回事件信息。可选。                |
1735
1736**错误码:**
1737
1738以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1739
1740| 错误码ID         | 错误信息        |
1741| --------------- | --------------- |
1742| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.            |
1743| 24700101                |  All unknown errors                  |
1744
1745**示例:**
1746
1747```ts
1748import { drm } from '@kit.DrmKit';
1749
1750let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1751let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1752mediaKeySession.off('keyExpired');
1753```
1754
1755### on('vendorDefined')
1756
1757on(type: 'vendorDefined', callback: (eventInfo: EventInfo) => void): void
1758
1759监听DRM解决方案自定义事件。
1760
1761**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1762
1763**系统能力:** SystemCapability.Multimedia.Drm.Core
1764
1765**参数:**
1766
1767| 参数名      | 类型                  | 必填 | 说明                                  |
1768| -------- | -------------------- | ---- | ------------------------------------- |
1769| type     | string               | 是   | 监听事件,固定为'vendorDefined'。自定义事件发生时触发。 |
1770| callback | Callback\<[EventInfo](#eventinfo)\> | 是   | 回调函数,返回事件信息。                 |
1771
1772**错误码:**
1773
1774以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1775
1776| 错误码ID         | 错误信息        |
1777| --------------- | --------------- |
1778| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.              |
1779| 24700101                |  All unknown errors                  |
1780
1781**示例:**
1782
1783```ts
1784import { drm } from '@kit.DrmKit';
1785
1786let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1787let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1788mediaKeySession.on('vendorDefined', (eventInfo: drm.EventInfo) => {
1789  console.log('vendorDefined ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
1790});
1791```
1792
1793### off('vendorDefined')
1794
1795off(type: 'vendorDefined', callback?: (eventInfo: EventInfo) => void): void
1796
1797注销DRM解决方案自定义事件监听。
1798
1799**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1800
1801**系统能力:** SystemCapability.Multimedia.Drm.Core
1802
1803**参数:**
1804
1805| 参数名      | 类型                  | 必填 | 说明                                  |
1806| -------- | -------------------- | ---- | ------------------------------------- |
1807| type     | string               | 是   | 监听事件,固定为'vendorDefined'。 |
1808| callback | Callback\<[EventInfo](#eventinfo)\> | 否   | 回调函数,返回事件信息。可选。                |
1809
1810**错误码:**
1811
1812以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1813
1814| 错误码ID         | 错误信息        |
1815| --------------- | --------------- |
1816| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.      |
1817| 24700101                |  All unknown errors                  |
1818
1819**示例:**
1820
1821```ts
1822import { drm } from '@kit.DrmKit';
1823
1824let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1825let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1826mediaKeySession.off('vendorDefined');
1827```
1828
1829### on('expirationUpdate')
1830
1831on(type: 'expirationUpdate', callback: (eventInfo: EventInfo) => void): void
1832
1833监听密钥过期更新事件。
1834
1835**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1836
1837**系统能力:** SystemCapability.Multimedia.Drm.Core
1838
1839**参数:**
1840
1841| 参数名      | 类型                  | 必填 | 说明                                  |
1842| -------- | -------------------- | ---- | ------------------------------------- |
1843| type     | string               | 是   | 监听事件类型,固定为'expirationUpdate'。密钥过期更新时触发。 |
1844| callback | Callback\<[EventInfo](#eventinfo)\> | 是   | 回调函数,返回事件信息。                 |
1845
1846**错误码:**
1847
1848以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1849
1850| 错误码ID         | 错误信息        |
1851| --------------- | --------------- |
1852| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.        |
1853| 24700101                |  All unknown errors                  |
1854
1855**示例:**
1856
1857```ts
1858import { drm } from '@kit.DrmKit';
1859
1860let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1861let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1862mediaKeySession.on('expirationUpdate', (eventInfo: drm.EventInfo) => {
1863  console.log('expirationUpdate ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info);
1864});
1865```
1866
1867### off('expirationUpdate')
1868
1869off(type: 'expirationUpdate', callback?: (eventInfo: EventInfo) => void): void
1870
1871注销过期更新事件监听。
1872
1873**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1874
1875**系统能力:** SystemCapability.Multimedia.Drm.Core
1876
1877**参数:**
1878
1879| 参数名      | 类型                  | 必填 | 说明                                  |
1880| -------- | -------------------- | ---- | ------------------------------------- |
1881| type     | string               | 是   | 监听事件类型,固定为'expirationUpdate'。 |
1882| callback | Callback\<[EventInfo](#eventinfo)\> | 否   | 回调函数,返回事件信息。可选。                |
1883
1884**错误码:**
1885
1886以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1887
1888| 错误码ID         | 错误信息        |
1889| --------------- | --------------- |
1890| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.       |
1891| 24700101                |  All unknown errors                  |
1892
1893**示例:**
1894
1895```ts
1896import { drm } from '@kit.DrmKit';
1897
1898let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1899let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1900mediaKeySession.off('expirationUpdate');
1901```
1902
1903### on('keysChange')
1904
1905on(type: 'keysChange', callback: (keyInfo: KeysInfo[], newKeyAvailable: boolean) => void): void
1906
1907监听密钥变化事件。
1908
1909**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1910
1911**系统能力:** SystemCapability.Multimedia.Drm.Core
1912
1913**参数:**
1914
1915| 参数名      | 类型                  | 必填 | 说明                                  |
1916| -------- | -------------------- | ---- | ------------------------------------- |
1917| type     | string               | 是   | 监听事件类型,固定为'keysChange'。密钥变化时触发。 |
1918| callback | Callback\<[KeysInfo[]](#keysinfo), boolean\> | 是   | 回调函数,返回事件信息,包含密钥标识和密钥状态描述的列表及密钥是否可用。                 |
1919
1920**错误码:**
1921
1922以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1923
1924| 错误码ID         | 错误信息        |
1925| --------------- | --------------- |
1926| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.             |
1927| 24700101                |  All unknown errors                  |
1928
1929**示例:**
1930
1931```ts
1932import { drm } from '@kit.DrmKit';
1933
1934let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1935let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1936mediaKeySession.on('keysChange', (keyInfo: drm.KeysInfo[], newKeyAvailable: boolean) => {
1937  for (let i = 0; i < keyInfo.length; i++) {
1938    console.log('keysChange' + 'keyId:' + keyInfo[i].keyId + ' data:' + keyInfo[i].value);
1939  }
1940});
1941```
1942
1943### off('keysChange')
1944
1945off(type: 'keysChange', callback?: (keyInfo: KeysInfo[], newKeyAvailable: boolean) => void): void
1946
1947注销密钥变化事件监听。
1948
1949**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1950
1951**系统能力:** SystemCapability.Multimedia.Drm.Core
1952
1953**参数:**
1954
1955| 参数名      | 类型                  | 必填 | 说明                                  |
1956| -------- | -------------------- | ---- | ------------------------------------- |
1957| type     | string               | 是   | 监听事件类型,固定为'keysChange'。 |
1958| callback | Callback\<[KeysInfo[]](#keysinfo), boolean\> | 否   | 回调函数,返回事件信息,包含密钥标识和密钥状态描述的列表及密钥是否可用。                |
1959
1960**错误码:**
1961
1962以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1963
1964| 错误码ID         | 错误信息        |
1965| --------------- | --------------- |
1966| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified or too many parameters. 2.Incorrect parameter types. 3.Parameter verification failed.            |
1967| 24700101                |  All unknown errors                  |
1968
1969**示例:**
1970
1971```ts
1972import { drm } from '@kit.DrmKit';
1973
1974let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
1975let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
1976mediaKeySession.off('keysChange');
1977```
1978
1979### destroy
1980
1981destroy(): void
1982
1983销毁MediaKeySession实例。
1984
1985**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1986
1987**系统能力:** SystemCapability.Multimedia.Drm.Core
1988
1989**错误码:**
1990
1991以下错误码的详细介绍请参见[DRM错误码](errorcode-drm.md)。
1992
1993| 错误码ID         | 错误信息        |
1994| --------------- | --------------- |
1995| 24700101                |  All unknown errors                  |
1996| 24700201                |  Fatal service error, for example, service died                  |
1997
1998**示例:**
1999
2000```ts
2001import { drm } from '@kit.DrmKit';
2002import { BusinessError } from '@kit.BasicServicesKit';
2003
2004let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
2005let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession();
2006try {
2007  mediaKeySession.destroy();
2008} catch (err) {
2009  let error = err as BusinessError;
2010  console.error(`mediaKeySession destroy ERROR: ${error}`);
2011}
2012
2013```