• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Functions
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
7## Modules to Import
8
9```ts
10import { drm } from '@kit.DrmKit';
11```
12
13## drm.createMediaKeySystem
14
15createMediaKeySystem(name: string): MediaKeySystem
16
17Creates a MediaKeySystem instance.
18
19**Atomic service API**: This API can be used in atomic services since API version 14.
20
21**System capability**: SystemCapability.Multimedia.Drm.Core
22
23**Parameters**
24
25| Name    | Type                                            | Mandatory| Description                          |
26| -------- | ----------------------------------------------- | ---- | ---------------------------- |
27| name  | string     | Yes  | DRM solution name.                  |
28
29**Return value**
30
31| Type                                            | Description                          |
32| ----------------------------------------------- | ---------------------------- |
33| [MediaKeySystem](arkts-apis-drm-MediaKeySystem.md)           | MediaKeySystem instance.                  |
34
35**Error codes**
36
37For details about the error codes, see [DRM Error Codes](errorcode-drm.md).
38
39| ID        | Error Message       |
40| --------------- | --------------- |
41| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.               |
42| 24700101                |  All unknown errors                  |
43| 24700103                |  Meet max MediaKeySystem num limit                  |
44| 24700201                |  Fatal service error, for example, service died                  |
45
46**Example**
47
48```ts
49import { drm } from '@kit.DrmKit';
50import { BusinessError } from '@kit.BasicServicesKit';
51try {
52  let mediaKeySystem: drm.MediaKeySystem = drm.createMediaKeySystem("com.clearplay.drm");
53} catch (err) {
54  let error = err as BusinessError;
55  console.error(`createMediaKeySystem ERROR: ${error}`);
56}
57```
58
59## drm.isMediaKeySystemSupported
60
61isMediaKeySystemSupported(name: string): boolean
62
63Checks whether the device supports the specified DRM solution.
64
65**Atomic service API**: This API can be used in atomic services since API version 14.
66
67**System capability**: SystemCapability.Multimedia.Drm.Core
68
69**Parameters**
70
71| Name    | Type                                            | Mandatory| Description                          |
72| -------- | ----------------------------------------------- | ---- | ---------------------------- |
73| name  | string     | Yes  | DRM solution name.                  |
74
75**Return value**
76
77| Type                                            | Description                          |
78| ----------------------------------------------- | ---------------------------- |
79| boolean          | Check result for the support of the DRM solution. **true** if supported, **false** otherwise.                  |
80
81**Error codes**
82
83For details about the error codes, see [DRM Error Codes](errorcode-drm.md).
84
85| ID        | Error Message       |
86| --------------- | --------------- |
87| 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).               |
88| 24700101                |  All unknown errors                  |
89| 24700201                |  Fatal service error, for example, service died                  |
90
91**Example**
92
93```ts
94import { drm } from '@kit.DrmKit';
95import { BusinessError } from '@kit.BasicServicesKit';
96
97try {
98  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm");
99  console.log("isMediaKeySystemSupported: ", supported);
100} catch (err) {
101  let error = err as BusinessError;
102  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
103}
104```
105
106## drm.isMediaKeySystemSupported
107
108isMediaKeySystemSupported(name: string, mimeType: string): boolean
109
110Checks whether the device supports the combination of the DRM solution and MIME type.
111
112**Atomic service API**: This API can be used in atomic services since API version 14.
113
114**System capability**: SystemCapability.Multimedia.Drm.Core
115
116**Parameters**
117
118| Name    | Type                                            | Mandatory| Description                          |
119| -------- | ----------------------------------------------- | ---- | ---------------------------- |
120| name  | string     | Yes  | DRM solution name.                  |
121| mimeType  | string     | Yes  | MIME type, which is determined by the DRM solution.                  |
122
123**Return value**
124
125| Type                                            | Description                          |
126| ----------------------------------------------- | ---------------------------- |
127| boolean          | Check result for the support of the combination. **true** if supported, **false** otherwise.                  |
128
129**Error codes**
130
131For details about the error codes, see [DRM Error Codes](errorcode-drm.md).
132
133| ID        | Error Message       |
134| --------------- | --------------- |
135| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.                |
136| 24700101                |  All unknown errors                  |
137| 24700201                |  Fatal service error, for example, service died                  |
138
139**Example**
140
141```ts
142import { drm } from '@kit.DrmKit';
143import { BusinessError } from '@kit.BasicServicesKit';
144
145try {
146  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm", "video/avc");
147  console.log("isMediaKeySystemSupported: ", supported);
148} catch (err) {
149  let error = err as BusinessError;
150  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
151}
152```
153
154## drm.isMediaKeySystemSupported
155
156isMediaKeySystemSupported(name: string, mimeType: string, level: ContentProtectionLevel): boolean
157
158Checks whether the device supports the combination of the DRM solution, MIME type, and content protection level.
159
160**Atomic service API**: This API can be used in atomic services since API version 14.
161
162**System capability**: SystemCapability.Multimedia.Drm.Core
163
164**Parameters**
165
166| Name    | Type                                            | Mandatory| Description                          |
167| -------- | ----------------------------------------------- | ---- | ---------------------------- |
168| name  | string     | Yes  | DRM solution name.                  |
169| mimeType  | string     | Yes  | MIME type, which is determined by the DRM solution.                  |
170| level  | [ContentProtectionLevel](arkts-apis-drm-e.md#contentprotectionlevel)     | Yes  | Content protection level.                  |
171
172**Return value**
173
174| Type                                            | Description                          |
175| ----------------------------------------------- | ---------------------------- |
176| boolean          | Check result for the support of the combination. **true** if supported, **false** otherwise.                  |
177
178**Error codes**
179
180For details about the error codes, see [DRM Error Codes](errorcode-drm.md).
181
182| ID        | Error Message       |
183| --------------- | --------------- |
184| 401                |  The parameter check failed. Possibly because: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.               |
185| 24700101                |  All unknown errors                  |
186| 24700201                |  Fatal service error, for example, service died                  |
187
188**Example**
189
190```ts
191import { drm } from '@kit.DrmKit';
192import { BusinessError } from '@kit.BasicServicesKit';
193
194try {
195  let supported: boolean = drm.isMediaKeySystemSupported("com.clearplay.drm", "video/avc", drm.ContentProtectionLevel.CONTENT_PROTECTION_LEVEL_SW_CRYPTO);
196  console.log("isMediaKeySystemSupported: ", supported);
197} catch (err) {
198  let error = err as BusinessError;
199  console.error(`isMediaKeySystemSupported ERROR: ${error}`);
200}
201```
202
203## drm.getMediaKeySystemUuid<sup>12+</sup>
204
205getMediaKeySystemUuid(name: string): string;
206
207Obtains the UUID of the DRM content protection system supported by the specified DRM solution.
208
209**Atomic service API**: This API can be used in atomic services since API version 14.
210
211**System capability**: SystemCapability.Multimedia.Drm.Core
212
213**Parameters**
214
215| Name    | Type                                            | Mandatory| Description                          |
216| -------- | ----------------------------------------------- | ---- | ---------------------------- |
217| name  | string     | Yes  | DRM solution name.                  |
218
219**Return value**
220
221| Type                                            | Description                          |
222| ----------------------------------------------- | ---------------------------- |
223| string  | UUID of the DRM content protection system.                  |
224
225**Error codes**
226
227For details about the error codes, see [DRM Error Codes](errorcode-drm.md).
228
229| ID        | Error Message       |
230| --------------- | --------------- |
231| 401                |  The parameter check failed.Possibly because: 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.                |
232| 24700101                |  All unknown errors                  |
233| 24700201                |  Fatal service error, for example, service died                  |
234
235**Example**
236
237```ts
238import { drm } from '@kit.DrmKit';
239import { BusinessError } from '@kit.BasicServicesKit';
240try {
241  let uuid: String = drm.getMediaKeySystemUuid("com.clearplay.drm");
242  console.log("getMediaKeySystemUuid: ", uuid);
243} catch (err) {
244  let error = err as BusinessError;
245  console.error(`getMediaKeySystemUuid ERROR: ${error}`);
246}
247```
248
249## drm.getMediaKeySystems<sup>12+</sup>
250
251getMediaKeySystems(): MediaKeySystemDescription[]
252
253Obtains the list of plugins supported by the device.
254
255**Atomic service API**: This API can be used in atomic services since API version 14.
256
257**System capability**: SystemCapability.Multimedia.Drm.Core
258
259**Return value**
260
261| Type                                            | Description                          |
262| ----------------------------------------------- | ---------------------------- |
263| [MediaKeySystemDescription[]](arkts-apis-drm-i.md#mediakeysystemdescription12)           | Array of the supported plugins.                  |
264
265**Error codes**
266
267For details about the error codes, see [DRM Error Codes](errorcode-drm.md).
268
269| ID        | Error Message       |
270| --------------- | --------------- |
271| 24700101                |  All unknown errors                  |
272| 24700201                |  Fatal service error, for example, service died                  |
273
274**Example**
275
276```ts
277import { drm } from '@kit.DrmKit';
278import { BusinessError } from '@kit.BasicServicesKit';
279try {
280  let description: drm.MediaKeySystemDescription[] = drm.getMediaKeySystems();
281} catch (err) {
282  let error = err as BusinessError;
283  console.error(`getMediaKeySystems ERROR: ${error}`);
284}
285```
286