1# Interface (MediaKeySystem) 2 3> **NOTE** 4> 5> 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. 6 7MediaKeySystem 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](arkts-apis-drm-f.md#drmcreatemediakeysystem) to create a MediaKeySystem instance. 8 9## Modules to Import 10 11```ts 12import { drm } from '@kit.DrmKit'; 13``` 14 15## setConfigurationString 16 17setConfigurationString(configName: string, value: string): void 18 19Sets a configuration item in the form of a string. 20 21**Atomic service API**: This API can be used in atomic services since API version 14. 22 23**System capability**: SystemCapability.Multimedia.Drm.Core 24 25**Parameters** 26 27| Name | Type | Mandatory| Description | 28| -------- | ----------------------------------------------- | ---- | ---------------------------- | 29| configName | string | Yes | Name 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](arkts-apis-drm-e.md#predefinedconfigname). | 30| value | string | Yes | Value of the configuration item. | 31 32**Error codes** 33 34For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 35 36| ID | Error Message | 37| --------------- | --------------- | 38| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 39| 24700101 | All unknown errors | 40| 24700201 | Fatal service error, for example, service died | 41 42**Example** 43 44```ts 45import { drm } from '@kit.DrmKit'; 46import { BusinessError } from '@kit.BasicServicesKit'; 47 48let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 49try { 50 mediaKeySystem.setConfigurationString("stringConfigName", "stringConfigValue"); // Ensure that stringConfigName is configurable. 51} catch (err) { 52 let error = err as BusinessError; 53 console.error(`setConfigurationString ERROR: ${error}`); 54} 55``` 56 57## getConfigurationString 58 59getConfigurationString(configName: string): string 60 61Obtains the value of a configuration item in the form of a string. 62 63**Atomic service API**: This API can be used in atomic services since API version 14. 64 65**System capability**: SystemCapability.Multimedia.Drm.Core 66 67**Parameters** 68 69| Name | Type | Mandatory| Description | 70| -------- | ----------------------------------------------- | ---- | ---------------------------- | 71| configName | string | Yes | Name 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](arkts-apis-drm-e.md#predefinedconfigname). | 72 73**Return value** 74 75| Type | Description | 76| ----------------------------------------------- | ---------------------------- | 77| string | Value of the configuration item in the form of a string. | 78 79**Error codes** 80 81For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 82 83| ID | Error Message | 84| --------------- | --------------- | 85| 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). | 86| 24700101 | All unknown errors | 87| 24700201 | Fatal service error, for example, service died | 88 89**Example** 90 91```ts 92import { drm } from '@kit.DrmKit'; 93import { BusinessError } from '@kit.BasicServicesKit'; 94 95let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 96try { 97 let configValue: string = mediaKeySystem.getConfigurationString("vendor"); 98} catch (err) { 99 let error = err as BusinessError; 100 console.error(`getConfigurationString ERROR: ${error}`); 101} 102``` 103 104## setConfigurationByteArray 105 106setConfigurationByteArray(configName: string, value: Uint8Array): void 107 108Sets a configuration item in the form of a byte array. 109 110**Atomic service API**: This API can be used in atomic services since API version 14. 111 112**System capability**: SystemCapability.Multimedia.Drm.Core 113 114**Parameters** 115 116| Name | Type | Mandatory| Description | 117| -------- | ----------------------------------------------- | ---- | ---------------------------- | 118| configName | string | Yes | Name 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](arkts-apis-drm-e.md#predefinedconfigname). | 119| value | Uint8Array | Yes | Value of the configuration item in the form of an array. The specific value is determined by the DRM solution on the device. | 120 121**Error codes** 122 123For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 124 125| ID | Error Message | 126| --------------- | --------------- | 127| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 128| 24700101 | All unknown errors. | 129| 24700201 | Fatal service error, for example, service died. | 130 131**Example** 132 133```ts 134import { drm } from '@kit.DrmKit'; 135import { BusinessError } from '@kit.BasicServicesKit'; 136 137let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 138// Set configValue based on project requirements. 139let configValue: Uint8Array = new Uint8Array([0x00, 0x00, 0x00, 0x00]); 140try { 141 // Ensure that byteArrayConfigName of the current DRM solution is configurable. 142 mediaKeySystem.setConfigurationByteArray("byteArrayConfigName", configValue); 143} catch (err) { 144 let error = err as BusinessError; 145 console.error(`setConfigurationByteArray ERROR: ${error}`); 146} 147``` 148 149## getConfigurationByteArray 150 151getConfigurationByteArray(configName: string): Uint8Array 152 153Obtains the value of a configuration item in the form of a byte array. 154 155**Atomic service API**: This API can be used in atomic services since API version 14. 156 157**System capability**: SystemCapability.Multimedia.Drm.Core 158 159**Parameters** 160 161| Name | Type | Mandatory| Description | 162| -------- | ----------------------------------------------- | ---- | ---------------------------- | 163| configName | string | Yes | Name 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](arkts-apis-drm-e.md#predefinedconfigname). | 164 165**Return value** 166 167| Type | Description | 168| ----------------------------------------------- | ---------------------------- | 169| Uint8Array | Value of the configuration item in the form of an array. | 170 171**Error codes** 172 173For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 174 175| ID | Error Message | 176| --------------- | --------------- | 177| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 178| 24700101 | All unknown errors | 179| 24700201 | Fatal service error, for example, service died | 180 181**Example** 182 183```ts 184import { drm } from '@kit.DrmKit'; 185import { BusinessError } from '@kit.BasicServicesKit'; 186 187let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 188try { 189 let configValue: Uint8Array = mediaKeySystem.getConfigurationByteArray("deviceUniqueId"); // Ensure that deviceUniqueId exists. 190} catch (err) { 191 let error = err as BusinessError; 192 console.error(`getConfigurationByteArray ERROR: ${error}`); 193} 194``` 195 196## getStatistics 197 198getStatistics(): StatisticKeyValue[] 199 200Obtains 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. 201 202**Atomic service API**: This API can be used in atomic services since API version 14. 203 204**System capability**: SystemCapability.Multimedia.Drm.Core 205 206**Return value** 207 208| Type | Description | 209| ----------------------------------------------- | ---------------------------- | 210| [StatisticKeyValue[]](arkts-apis-drm-i.md#statistickeyvalue) | Statistical information. | 211 212**Error codes** 213 214For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 215 216| ID | Error Message | 217| --------------- | --------------- | 218| 24700101 | All unknown errors | 219| 24700201 | Fatal service error, for example, service died | 220 221**Example** 222 223```ts 224import { drm } from '@kit.DrmKit'; 225import { BusinessError } from '@kit.BasicServicesKit'; 226 227let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 228try { 229 let statisticKeyValue: drm.StatisticKeyValue[] = mediaKeySystem.getStatistics(); 230} catch (err) { 231 let error = err as BusinessError; 232 console.error(`getConfigurationByteArray ERROR: ${error}`); 233} 234``` 235 236## getMaxContentProtectionLevel 237 238getMaxContentProtectionLevel(): ContentProtectionLevel 239 240Obtains the maximum content protection level supported by the current DRM solution. 241 242**Atomic service API**: This API can be used in atomic services since API version 14. 243 244**System capability**: SystemCapability.Multimedia.Drm.Core 245 246**Return value** 247 248| Type | Description | 249| ----------------------------------------------- | ---------------------------- | 250| [ContentProtectionLevel](arkts-apis-drm-e.md#contentprotectionlevel) | Maximum content protection level. | 251 252**Error codes** 253 254For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 255 256| ID | Error Message | 257| --------------- | --------------- | 258| 24700101 | All unknown errors | 259| 24700201 | Fatal service error, for example, service died | 260 261**Example** 262 263```ts 264import { drm } from '@kit.DrmKit'; 265import { BusinessError } from '@kit.BasicServicesKit'; 266 267let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 268try { 269 let maxLevel: drm.ContentProtectionLevel = mediaKeySystem.getMaxContentProtectionLevel(); 270} catch (err) { 271 let error = err as BusinessError; 272 console.error(`getConfigurationByteArray ERROR: ${error}`); 273} 274``` 275 276## generateKeySystemRequest 277 278generateKeySystemRequest(): Promise<ProvisionRequest\> 279 280Generates a provision request. 281 282**Atomic service API**: This API can be used in atomic services since API version 14. 283 284**System capability**: SystemCapability.Multimedia.Drm.Core 285 286**Return value** 287 288| Type | Description | 289| ----------------------------------------------- | ---------------------------- | 290| Promise<[ProvisionRequest](arkts-apis-drm-i.md#provisionrequest)\> | Promise used to return the provision request obtained. If a DRM certificate already exists on the device, a failure message is returned. | 291 292**Error codes** 293 294For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 295 296| ID | Error Message | 297| --------------- | --------------- | 298| 24700101 | All unknown errors | 299| 24700201 | Fatal service error, for example, service died | 300 301**Example** 302 303```ts 304import { drm } from '@kit.DrmKit'; 305import { BusinessError } from '@kit.BasicServicesKit'; 306 307let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 308// Do not call this API if a DRM certificate already exists on the device. 309mediaKeySystem.generateKeySystemRequest().then((ProvisionRequest: drm.ProvisionRequest) => { 310 console.log("generateKeySystemRequest"); 311}).catch((err: BusinessError) => { 312 console.error(`generateKeySystemRequest: ERROR: ${err}`); 313}); 314``` 315 316## processKeySystemResponse 317 318processKeySystemResponse(response: Uint8Array): Promise<void\> 319 320Processes a provision response. 321 322**Atomic service API**: This API can be used in atomic services since API version 14. 323 324**System capability**: SystemCapability.Multimedia.Drm.Core 325 326**Parameters** 327 328| Name | Type | Mandatory| Description | 329| -------- | ----------------------------------------------- | ---- | ---------------------------- | 330| response | Uint8Array | Yes | Provision response. | 331 332**Return value** 333 334| Type | Description | 335| ----------------------------------------------- | ---------------------------- | 336| Promise<void\> | Promise | 337 338**Error codes** 339 340For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 341 342| ID | Error Message | 343| --------------- | --------------- | 344| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 345| 24700101 | All unknown errors | 346| 24700201 | Fatal service error, for example, service died | 347 348**Example** 349 350```ts 351import { drm } from '@kit.DrmKit'; 352import { BusinessError } from '@kit.BasicServicesKit'; 353 354let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 355// keySystemResponse is the response obtained from the DRM service. Pass in the actual data obtained. 356let keySystemResponse = new Uint8Array([0x00, 0x00, 0x00, 0x00]); 357mediaKeySystem.processKeySystemResponse(keySystemResponse).then(() => { 358 console.log("processKeySystemResponse"); 359}).catch((err: BusinessError) => { 360 console.error(`processKeySystemResponse: ERROR: ${err}`); 361}); 362``` 363 364## getCertificateStatus 365 366getCertificateStatus():CertificateStatus 367 368Obtains the status of the DRM certificate. 369 370**Atomic service API**: This API can be used in atomic services since API version 14. 371 372**System capability**: SystemCapability.Multimedia.Drm.Core 373 374**Return value** 375 376| Type | Description | 377| ----------------------------------------------- | ---------------------------- | 378| [CertificateStatus](arkts-apis-drm-e.md#certificatestatus) | Certificate status. | 379 380**Error codes** 381 382For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 383 384| ID | Error Message | 385| --------------- | --------------- | 386| 24700101 | All unknown errors | 387| 24700201 | Fatal service error, for example, service died | 388 389**Example** 390 391```ts 392import { drm } from '@kit.DrmKit'; 393import { BusinessError } from '@kit.BasicServicesKit'; 394 395let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 396try { 397 let certificateStatus: drm.CertificateStatus = mediaKeySystem.getCertificateStatus(); 398} catch (err) { 399 let error = err as BusinessError; 400 console.error(`getCertificateStatus ERROR: ${error}`); 401} 402``` 403 404## on('keySystemRequired') 405 406on(type: 'keySystemRequired', callback: (eventInfo: EventInfo) => void): void 407 408Subscribes to events indicating that the application requires a DRM certificate. 409 410**Atomic service API**: This API can be used in atomic services since API version 14. 411 412**System capability**: SystemCapability.Multimedia.Drm.Core 413 414**Parameters** 415 416| Name | Type | Mandatory| Description | 417| -------- | -------------------- | ---- | ------------------------------------- | 418| type | string | Yes | Event type. The event can be listened for when a MediaKeySystem instance is created. This event is triggered when the application requests a DRM certificate.| 419| callback | (eventInfo: \<[EventInfo](arkts-apis-drm-i.md#eventinfo)\>) => void | Yes | Callback used to return the event information. If this event callback is returned, a DRM certificate must be requested. | 420 421**Error codes** 422 423For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 424 425| ID | Error Message | 426| --------------- | --------------- | 427| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 428| 24700101 | All unknown errors | 429 430**Example** 431 432```ts 433import { drm } from '@kit.DrmKit'; 434 435let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 436mediaKeySystem.on('keySystemRequired', (eventInfo: drm.EventInfo) => { 437 console.log('keySystemRequired ' + 'extra: ' + eventInfo.extraInfo + 'data: ' + eventInfo.info); 438}); 439``` 440 441## off('keySystemRequired') 442 443off(type: 'keySystemRequired', callback?: (eventInfo: EventInfo) => void): void 444 445Unsubscribes from events indicating that the application requests a DRM certificate. 446 447**Atomic service API**: This API can be used in atomic services since API version 14. 448 449**System capability**: SystemCapability.Multimedia.Drm.Core 450 451**Parameters** 452 453| Name | Type | Mandatory| Description | 454| -------- | -------------------- | ---- | ------------------------------------- | 455| type | string | Yes | Event type. The event can be listened for when a MediaKeySystem instance is created.| 456| callback | (eventInfo: \<[EventInfo](arkts-apis-drm-i.md#eventinfo)\>) => void | No | Callback used to return the event information. | 457 458**Error codes** 459 460For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 461 462| ID | Error Message | 463| --------------- | --------------- | 464| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 465| 24700101 | All unknown errors | 466 467**Example** 468 469```ts 470let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 471mediaKeySystem.off('keySystemRequired'); 472``` 473 474## createMediaKeySession 475 476createMediaKeySession(level: ContentProtectionLevel): MediaKeySession 477 478Creates a MediaKeySession instance with the specified content protection level. 479 480**Atomic service API**: This API can be used in atomic services since API version 14. 481 482**System capability**: SystemCapability.Multimedia.Drm.Core 483 484**Parameters** 485 486| Name | Type | Mandatory| Description | 487| -------- | ----------------------------------------------- | ---- | ---------------------------- | 488| level | [ContentProtectionLevel](arkts-apis-drm-e.md#contentprotectionlevel) | Yes | Content protection level. | 489 490**Return value** 491 492| Type | Description | 493| ----------------------------------------------- | ---------------------------- | 494| [MediaKeySession](arkts-apis-drm-MediaKeySession.md) | MediaKeySession instance. | 495 496**Error codes** 497 498For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 499 500| ID | Error Message | 501| --------------- | --------------- | 502| 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. | 503| 24700101 | All unknown errors | 504| 24700104 | Meet max MediaKeySession num limit | 505| 24700201 | Fatal service error, for example, service died | 506 507**Example** 508 509```ts 510import { drm } from '@kit.DrmKit'; 511import { BusinessError } from '@kit.BasicServicesKit'; 512 513let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 514try { 515 let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession(drm.ContentProtectionLevel.CONTENT_PROTECTION_LEVEL_SW_CRYPTO); 516} catch (err) { 517 let error = err as BusinessError; 518 console.error(`createMediaKeySession ERROR: ${error}`); 519} 520``` 521 522## createMediaKeySession 523 524createMediaKeySession(): MediaKeySession 525 526Creates a MediaKeySession instance with the default content protection level of the DRM solution. 527 528**Atomic service API**: This API can be used in atomic services since API version 14. 529 530**System capability**: SystemCapability.Multimedia.Drm.Core 531 532**Return value** 533 534| Type | Description | 535| ----------------------------------------------- | ---------------------------- | 536| [MediaKeySession](arkts-apis-drm-MediaKeySession.md) | MediaKeySession instance. | 537 538**Error codes** 539 540For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 541 542| ID | Error Message | 543| --------------- | --------------- | 544| 24700101 | All unknown errors | 545| 24700104 | Meet max MediaKeySession num limit | 546| 24700201 | Fatal service error, for example, service died | 547 548**Example** 549 550```ts 551import { drm } from '@kit.DrmKit'; 552import { BusinessError } from '@kit.BasicServicesKit'; 553 554let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 555try { 556 let mediaKeySession: drm.MediaKeySession = mediaKeySystem.createMediaKeySession(); 557} catch (err) { 558 let error = err as BusinessError; 559 console.error(`createMediaKeySession ERROR: ${error}`); 560} 561``` 562 563## getOfflineMediaKeyIds 564 565getOfflineMediaKeyIds(): Uint8Array[] 566 567Obtains the IDs of offline media keys. 568 569**Atomic service API**: This API can be used in atomic services since API version 14. 570 571**System capability**: SystemCapability.Multimedia.Drm.Core 572 573**Return value** 574 575| Type | Description | 576| ----------------------------------------------- | ---------------------------- | 577| Uint8Array[] | Array holding the IDs of offline media keys. | 578 579**Error codes** 580 581For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 582 583| ID | Error Message | 584| --------------- | --------------- | 585| 24700101 | All unknown errors | 586| 24700201 | Fatal service error, for example, service died | 587 588**Example** 589 590```ts 591import { drm } from '@kit.DrmKit'; 592import { BusinessError } from '@kit.BasicServicesKit'; 593 594let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 595try { 596 let offlineMediaKeyIds: Uint8Array[] = mediaKeySystem.getOfflineMediaKeyIds(); 597} catch (err) { 598 let error = err as BusinessError; 599 console.error(`getOfflineMediaKeyIds ERROR: ${error}`); 600} 601``` 602 603## getOfflineMediaKeyStatus 604 605getOfflineMediaKeyStatus(mediaKeyId: Uint8Array): OfflineMediaKeyStatus 606 607Obtains the status of offline media keys with the specified IDs. 608 609**Atomic service API**: This API can be used in atomic services since API version 14. 610 611**System capability**: SystemCapability.Multimedia.Drm.Core 612 613**Parameters** 614 615| Name | Type | Mandatory| Description | 616| -------- | ----------------------------------------------- | ---- | ---------------------------- | 617| mediaKeyId | Uint8Array | Yes | Array holding the IDs of offline media keys. | 618 619**Return value** 620 621| Type | Description | 622| ----------------------------------------------- | ---------------------------- | 623| [OfflineMediaKeyStatus](arkts-apis-drm-e.md#offlinemediakeystatus) | Status of the offline media keys. | 624 625**Error codes** 626 627For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 628 629| ID | Error Message | 630| --------------- | --------------- | 631| 401 | The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 632| 24700101 | All unknown errors | 633| 24700201 | Fatal service error, for example, service died | 634 635**Example** 636 637```ts 638import { drm } from '@kit.DrmKit'; 639import { BusinessError } from '@kit.BasicServicesKit'; 640 641let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 642// mediaKeyId is the return value of processMediaKeyResponse or getOfflineMediaKeyIds. Pass in the actual data returned. 643let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]); 644try { 645 let configValue: drm.OfflineMediaKeyStatus = mediaKeySystem.getOfflineMediaKeyStatus(mediaKeyId); 646} catch (err) { 647 let error = err as BusinessError; 648 console.error(`getOfflineMediaKeyStatus ERROR: ${error}`); 649} 650``` 651 652## clearOfflineMediaKeys 653 654clearOfflineMediaKeys(mediaKeyId: Uint8Array): void 655 656Clears offline media keys by ID. 657 658**Atomic service API**: This API can be used in atomic services since API version 14. 659 660**System capability**: SystemCapability.Multimedia.Drm.Core 661 662**Parameters** 663 664| Name | Type | Mandatory| Description | 665| -------- | ----------------------------------------------- | ---- | ---------------------------- | 666| mediaKeyId | Uint8Array | Yes | Array holding the IDs of offline media keys. | 667 668**Error codes** 669 670For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 671 672| ID | Error Message | 673| --------------- | --------------- | 674| 401 | The parameter check failed.Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 675| 24700101 | All unknown errors | 676| 24700201 | Fatal service error, for example, service died | 677 678**Example** 679 680```ts 681import { drm } from '@kit.DrmKit'; 682import { BusinessError } from '@kit.BasicServicesKit'; 683 684let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 685// mediaKeyId is the return value of processMediaKeyResponse or getOfflineMediaKeyIds. Pass in the actual data returned. 686let mediaKeyId = new Uint8Array([0x00, 0x00, 0x00, 0x00]); 687try { 688 mediaKeySystem.clearOfflineMediaKeys(mediaKeyId); 689} catch (err) { 690 let error = err as BusinessError; 691 console.error(`clearOfflineMediaKeys ERROR: ${error}`); 692} 693``` 694 695## destroy 696 697destroy(): void 698 699Destroys this MediaKeySystem instance. 700 701**Atomic service API**: This API can be used in atomic services since API version 14. 702 703**System capability**: SystemCapability.Multimedia.Drm.Core 704 705**Error codes** 706 707For details about the error codes, see [DRM Error Codes](errorcode-drm.md). 708 709| ID | Error Message | 710| --------------- | --------------- | 711| 24700101 | All unknown errors | 712| 24700201 | Fatal service error, for example, service died | 713 714**Example** 715 716```ts 717import { drm } from '@kit.DrmKit'; 718import { BusinessError } from '@kit.BasicServicesKit'; 719 720let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm"); 721try { 722 mediaKeySystem.destroy(); 723} catch (err) { 724 let error = err as BusinessError; 725 console.error(`mediaKeySystem destroy ERROR: ${error}`); 726} 727``` 728