• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.systemSoundManager (系统声音管理)(系统接口)
2
3系统声音管理提供管理系统声音的一些基础能力,包括对系统铃声的资源设置与读取、获取系统铃声播放器等。
4
5> **说明:**
6>
7> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> - 本模块接口为系统接口。
9
10## 导入模块
11
12```ts
13import { systemSoundManager } from '@kit.AudioKit';
14```
15
16## 常量
17
18**系统接口:** 该接口为系统接口。
19
20**系统能力:** SystemCapability.Multimedia.SystemSound.Core
21
22| 名称                                      | 值   | 说明      |
23|------------------------------------------|-----|---------|
24| TONE_CATEGORY_RINGTONE<sup>12+</sup>     | 1   | 铃声类别。   |
25| TONE_CATEGORY_TEXT_MESSAGE<sup>12+</sup> | 2   | 短信铃声类别。 |
26| TONE_CATEGORY_NOTIFICATION<sup>12+</sup> | 4   | 通知铃声类别。 |
27| TONE_CATEGORY_ALARM<sup>12+</sup>        | 8   | 闹钟铃声类别。 |
28
29## RingtoneType
30
31枚举,铃声类型。
32
33**系统接口:** 该接口为系统接口。
34
35**系统能力:** SystemCapability.Multimedia.SystemSound.Core
36
37| 名称                            | 值  | 说明                                                                     |
38| ------------------------------- |----|------------------------------------------------------------------------|
39| RINGTONE_TYPE_DEFAULT<sup>(deprecated)</sup>           | 0  | 默认铃声类型。<br/> 从 API version 11 开始废弃。建议使用该枚举中的RINGTONE_TYPE_SIM_CARD_0替代。 |
40| RINGTONE_TYPE_SIM_CARD_0<sup>11+</sup> | 0  | sim卡1的铃声。                                                              |
41| RINGTONE_TYPE_MULTISIM<sup>(deprecated)</sup>          | 1  | 多SIM卡铃声类型。<br/> 从 API version 11 开始废弃。建议使用该枚举中的RINGTONE_TYPE_SIM_CARD_1替代。 |
42| RINGTONE_TYPE_SIM_CARD_1<sup>11+</sup> | 1  | sim卡2的铃声。                                                              |
43
44## SystemToneType<sup>11+</sup>
45
46枚举,系统铃声类型。
47
48**系统接口:** 该接口为系统接口。
49
50**系统能力:** SystemCapability.Multimedia.SystemSound.Core
51
52| 名称                            | 值   | 说明         |
53| ------------------------------- |-----|------------|
54| SYSTEM_TONE_TYPE_SIM_CARD_0     | 0   | sim卡1的短信提示音。 |
55| SYSTEM_TONE_TYPE_SIM_CARD_1     | 1   | sim卡2的短信提示音。 |
56| SYSTEM_TONE_TYPE_NOTIFICATION   | 32  | 通知提示音。     |
57
58
59## ToneCustomizedType<sup>12+</sup>
60
61枚举,铃声自定义类型。
62
63**系统接口:** 该接口为系统接口。
64
65**系统能力:** SystemCapability.Multimedia.SystemSound.Core
66
67| 名称                         | 值   | 说明         |
68| ----------------------------|-----|------------|
69| PRE_INSTALLED<sup>12+</sup> | 0   | 预安装铃声类型。 |
70| CUSTOMIZED<sup>12+</sup>    | 1   | 自定义铃声类型。 |
71
72## ToneAttrs<sup>12+</sup>
73
74管理铃声属性。在调用ToneAttrs<sup>12+</sup>的接口前,需要先通过[createCustomizedToneAttrs](#systemsoundmanagercreatecustomizedtoneattrs12)或[getDefaultRingtoneAttrs](#getdefaultringtoneattrs12)、[getRingtoneAttrList](#getringtoneattrlist12)等方法获取实例。
75
76### getTitle<sup>12+</sup>
77
78getTitle(): string
79
80获取铃声标题。
81
82**系统接口:** 该接口为系统接口。
83
84**系统能力:** SystemCapability.Multimedia.SystemSound.Core
85
86**返回值:**
87
88| 类型    | 说明  |
89|--------|-----|
90| string | 标题。 |
91
92**错误码:**
93
94| 错误码ID   | 错误信息              |
95|---------| -------------------- |
96| 202     | Caller is not a system application. |
97
98**示例:**
99
100```ts
101toneAttrs.getTitle();
102```
103
104### setTitle<sup>12+</sup>
105
106setTitle(title: string): void
107
108设置铃声标题。
109
110**系统接口:** 该接口为系统接口。
111
112**系统能力:** SystemCapability.Multimedia.SystemSound.Core
113
114**参数:**
115
116| 参数名  | 类型    | 必填 | 说明          |
117| -------| -------| ---- | ------------|
118| title  | string | 是   | 铃声的标题。   |
119
120**错误码:**
121
122| 错误码ID | 错误信息              |
123|-------| -------------------- |
124| 202   | Caller is not a system application. |
125| 401   | The parameters check failed. |
126
127**示例:**
128
129```ts
130let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
131let title = 'text';
132toneAttrs.setTitle(title);
133```
134
135### getFileName<sup>12+</sup>
136
137getFileName(): string
138
139获取铃声文件名。
140
141**系统接口:** 该接口为系统接口。
142
143**系统能力:** SystemCapability.Multimedia.SystemSound.Core
144
145**返回值:**
146
147| 类型    | 说明   |
148|--------|------|
149| string | 文件名。 |
150
151**错误码:**
152
153| 错误码ID | 错误信息              |
154|---------| -------------------- |
155| 202     | Caller is not a system application. |
156
157
158**示例:**
159
160```ts
161toneAttrs.getFileName();
162```
163
164### setFileName<sup>12+</sup>
165
166setFileName(name: string): void
167
168设置铃声文件名。
169
170**系统接口:** 该接口为系统接口。
171
172**系统能力:** SystemCapability.Multimedia.SystemSound.Core
173
174**参数:**
175
176| 参数名 | 类型    | 必填 | 说明         |
177| ------| -------|-----| ------------|
178| name  | string | 是   | 铃声的文件名。 |
179
180**错误码:**
181
182| 错误码ID | 错误信息              |
183|-------| -------------------- |
184| 202   | Caller is not a system application. |
185| 401   | The parameters check failed. |
186
187**示例:**
188
189```ts
190let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
191let fileName = 'textFileName';
192toneAttrs.setFileName(fileName);
193```
194
195### getUri<sup>12+</sup>
196
197getUri(): string
198
199获取铃声资源路径。
200
201**系统接口:** 该接口为系统接口。
202
203**系统能力:** SystemCapability.Multimedia.SystemSound.Core
204
205**返回值:**
206
207| 类型    | 说明                                                      |
208|--------|---------------------------------------------------------|
209| string | uri(如:'/data/storage/el2/base/RingTone/alarms/test.ogg')。 |
210
211**错误码:**
212
213| 错误码ID | 错误信息              |
214|---------| -------------------- |
215| 202     | Caller is not a system application. |
216
217**示例:**
218
219```ts
220toneAttrs.getUri();
221```
222
223### getCustomizedType<sup>12+</sup>
224
225getCustomizedType(): string
226
227获取铃声自定义类型。
228
229**系统接口:** 该接口为系统接口。
230
231**系统能力:** SystemCapability.Multimedia.SystemSound.Core
232
233**返回值:**
234
235| 类型                                         | 说明      |
236|--------------------------------------------|---------|
237| [ToneCustomizedType](#tonecustomizedtype12) | 定制铃音类型。 |
238
239**错误码:**
240
241| 错误码ID   | 错误信息              |
242|---------| -------------------- |
243| 202     | Caller is not a system application. |
244
245**示例:**
246
247```ts
248toneAttrs.getCustomizedType();
249```
250
251### setCategory<sup>12+</sup>
252
253setCategory(category: number): void
254
255设置铃声类别。
256
257**系统接口:** 该接口为系统接口。
258
259**系统能力:** SystemCapability.Multimedia.SystemSound.Core
260
261**参数:**
262
263| 参数名      | 类型      | 必填 | 说明       |
264|----------| ---------| ---- |----------|
265| category | number   | 是   | 铃声类别,取值参考[铃声类别的常量](#常量)。  |
266
267**错误码:**
268
269| 错误码ID | 错误信息              |
270|-------| -------------------- |
271| 202   | Caller is not a system application. |
272| 401   | The parameters check failed. |
273
274**示例:**
275
276```ts
277let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
278let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM; // 需更改为实际所需类型常量
279toneAttrs.setCategory(categoryValue);
280```
281
282### getCategory<sup>12+</sup>
283
284getCategory(): string
285
286获取铃声类别。
287
288**系统接口:** 该接口为系统接口。
289
290**系统能力:** SystemCapability.Multimedia.SystemSound.Core
291
292**返回值:**
293
294| 类型    | 说明     |
295|--------|--------|
296| number | 铃声类别,取值参考[铃声类别的常量](#常量)。 |
297
298**错误码:**
299
300| 错误码ID   | 错误信息              |
301|---------| -------------------- |
302| 202     | Caller is not a system application. |
303
304
305**示例:**
306
307```ts
308toneAttrs.getCategory();
309```
310
311## ToneAttrsArray<sup>12+</sup>
312
313type ToneAttrsArray = Array&lt;[ToneAttrs](#toneattrs12)&gt;
314
315铃音属性数组。
316
317**系统能力:** SystemCapability.Multimedia.SystemSound.Core
318
319| 类型                                     | 说明      |
320|----------------------------------------|---------|
321| Array&lt;[ToneAttrs](#toneattrs12)&gt; | 铃音属性数组。 |
322
323## systemSoundManager.createCustomizedToneAttrs<sup>12+</sup>
324
325createCustomizedToneAttrs(): ToneAttrs
326
327创建自定义铃声属性。
328
329**系统接口:** 该接口为系统接口。
330
331**系统能力:** SystemCapability.Multimedia.SystemSound.Core
332
333**返回值:**
334
335| 类型                        | 说明         |
336|---------------------------| ------------ |
337| [ToneAttrs](#toneattrs12) | 铃声属性类。 |
338
339**错误码:**
340
341以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
342
343| 错误码ID   | 错误信息              |
344|---------| -------------------- |
345| 202     | Caller is not a system application. |
346
347**示例:**
348```ts
349let toneAttrs: systemSoundManager.ToneAttrs = systemSoundManager.createCustomizedToneAttrs();
350```
351
352## systemSoundManager.getSystemSoundManager
353
354getSystemSoundManager(): SystemSoundManager
355
356获取系统声音管理器。
357
358**系统接口:** 该接口为系统接口。
359
360**系统能力:** SystemCapability.Multimedia.SystemSound.Core
361
362**返回值:**
363
364| 类型                          | 说明         |
365| ----------------------------- | ------------ |
366| [SystemSoundManager](#systemsoundmanager) | 系统声音管理类。 |
367
368**示例:**
369```ts
370let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
371```
372
373## SystemSoundManager
374
375管理系统声音。在调用SystemSoundManager的接口前,需要先通过[getSystemSoundManager](#systemsoundmanagergetsystemsoundmanager)创建实例。
376
377### setSystemRingtoneUri<sup>(deprecated)</sup>
378
379setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType, callback: AsyncCallback&lt;void&gt;): void
380
381设置系统铃声uri,使用callback方式异步返回结果。
382
383> **说明:**
384> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[setRingtoneUri](#setringtoneuri11)替代。
385
386**系统接口:** 该接口为系统接口。
387
388**系统能力:** SystemCapability.Multimedia.SystemSound.Core
389
390**参数:**
391
392| 参数名   | 类型                                      | 必填 | 说明                     |
393| -------- | ---------------------------------------- | ---- | ------------------------ |
394| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)   | 是   | 当前应用的上下文。           |
395| uri      | string                                   | 是   | 被设置的系统铃声的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
396| type     | [RingtoneType](#ringtonetype)            | 是   | 被设置的系统铃声的类型。     |
397| callback | AsyncCallback&lt;void&gt;                | 是   | 回调返回设置成功或失败。     |
398
399**示例:**
400
401```ts
402import { BusinessError } from '@kit.BasicServicesKit';
403import { common } from '@kit.AbilityKit';
404
405let context: Context = getContext(this);
406let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
407let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
408
409let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
410systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type, (err: BusinessError) => {
411  if (err) {
412    console.error(`Failed to set system ringtone uri. ${err}`);
413    return;
414  }
415  console.info(`Callback invoked to indicate a successful setting of the system ringtone uri.`);
416});
417```
418
419### setSystemRingtoneUri<sup>(deprecated)</sup>
420
421setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType): Promise&lt;void&gt;
422
423设置系统铃声uri,使用Promise方式异步返回结果。
424
425> **说明:**
426> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[setRingtoneUri](#setringtoneuri11)替代。
427
428**系统接口:** 该接口为系统接口。
429
430**系统能力:** SystemCapability.Multimedia.SystemSound.Core
431
432**参数:**
433
434| 参数名   | 类型                                      | 必填 | 说明                     |
435| -------- | ---------------------------------------- | ---- | ------------------------ |
436| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)  | 是   | 当前应用的上下文。         |
437| uri      | string                                   | 是   | 被设置的系统铃声的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
438| type     | [RingtoneType](#ringtonetype)            | 是   | 被设置的系统铃声的类型。   |
439
440**返回值:**
441
442| 类型                | 说明                            |
443| ------------------- | ------------------------------- |
444| Promise&lt;void&gt; | Promise回调返回设置成功或失败。   |
445
446**示例:**
447
448```ts
449import { BusinessError } from '@kit.BasicServicesKit';
450import { common } from '@kit.AbilityKit';
451
452let context: Context = getContext(this);
453let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
454let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
455
456let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
457systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type).then(() => {
458  console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`);
459}).catch ((err: BusinessError) => {
460  console.error(`Failed to set the system ringtone uri ${err}`);
461});
462```
463
464### getSystemRingtoneUri<sup>(deprecated)</sup>
465
466getSystemRingtoneUri(context: Context, type: RingtoneType, callback: AsyncCallback&lt;string&gt;): void
467
468获取系统铃声uri,使用callback方式异步返回结果。
469
470> **说明:**
471> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtoneUri](#getringtoneuri11)替代。
472
473**系统接口:** 该接口为系统接口。
474
475**系统能力:** SystemCapability.Multimedia.SystemSound.Core
476
477**参数:**
478
479| 参数名   | 类型                                                                    | 必填 | 说明                     |
480| -------- |-----------------------------------------------------------------------| ---- | ------------------------ |
481| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)   | 是   | 当前应用的上下文。         |
482| type     | [RingtoneType](#ringtonetype)                                         | 是   | 待获取的系统铃声的类型。    |
483| callback | AsyncCallback&lt;string&gt;                                           | 是   | 回调返回获取的系统铃声uri。 |
484
485**示例:**
486
487```ts
488import { BusinessError } from '@kit.BasicServicesKit';
489import { common } from '@kit.AbilityKit';
490
491let context: Context = getContext(this);
492let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
493
494let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
495systemSoundManagerInstance.getSystemRingtoneUri(context, type, (err: BusinessError, value: string) => {
496  if (err) {
497    console.error(`Failed to get system ringtone uri. ${err}`);
498    return;
499  }
500  console.info(`Callback invoked to indicate the value of the system ringtone uri is obtained ${value}.`);
501});
502```
503
504### getSystemRingtoneUri<sup>(deprecated)</sup>
505
506getSystemRingtoneUri(context: Context, type: RingtoneType): Promise&lt;string&gt;
507
508获取系统铃声uri,使用Promise方式异步返回结果。
509
510> **说明:**
511> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtoneUri](#getringtoneuri11)替代。
512
513**系统接口:** 该接口为系统接口。
514
515**系统能力:** SystemCapability.Multimedia.SystemSound.Core
516
517**参数:**
518
519| 参数名   | 类型                                                                   | 必填 | 说明                     |
520| -------- |----------------------------------------------------------------------| ---- | ------------------------ |
521| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)  | 是   | 当前应用的上下文。         |
522| type     | [RingtoneType](#ringtonetype)                                        | 是   | 被设置的系统铃声的类型。   |
523
524**返回值:**
525
526| 类型                | 说明                                |
527| ------------------- | ---------------------------------- |
528| Promise&lt;string&gt; | Promise回调返回获取的系统铃声uri。 |
529
530**示例:**
531
532```ts
533import { BusinessError } from '@kit.BasicServicesKit';
534import { common } from '@kit.AbilityKit';
535
536let context: Context = getContext(this);
537let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
538
539let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
540systemSoundManagerInstance.getSystemRingtoneUri(context, type).then((value: string) => {
541  console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`);
542}).catch ((err: BusinessError) => {
543  console.error(`Failed to get the system ringtone uri ${err}`);
544});
545```
546
547### getSystemRingtonePlayer<sup>(deprecated)</sup>
548
549getSystemRingtonePlayer(context: Context, type: RingtoneType, callback: AsyncCallback&lt;RingtonePlayer&gt;): void
550
551获取系统铃声播放器,使用callback方式异步返回结果。
552
553> **说明:**
554> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtonePlayer](#getringtoneplayer11)替代。
555
556**系统接口:** 该接口为系统接口。
557
558**系统能力:** SystemCapability.Multimedia.SystemSound.Core
559
560**参数:**
561
562| 参数名   | 类型                                      | 必填 | 说明                         |
563| -------- | -----------------------------------------| ---- | --------------------------- |
564| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)  | 是   | 当前应用的上下文。            |
565| type     | [RingtoneType](#ringtonetype)            | 是   | 待获取播放器的系统铃声的类型。 |
566| callback | AsyncCallback&lt;[RingtonePlayer](js-apis-inner-multimedia-ringtonePlayer-sys.md#ringtoneplayer)&gt; | 是 | 回调返回获取的系统铃声播放器。 |
567
568**示例:**
569
570```ts
571import { BusinessError } from '@kit.BasicServicesKit';
572import { common } from '@kit.AbilityKit';
573
574let context: Context = getContext(this);
575let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
576let systemRingtonePlayer: systemSoundManager.RingtonePlayer | undefined = undefined;
577
578let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
579systemSoundManagerInstance.getSystemRingtonePlayer(context, type, (err: BusinessError, value: systemSoundManager.RingtonePlayer) => {
580  if (err) {
581    console.error(`Failed to get system ringtone player. ${err}`);
582    return;
583  }
584  console.info(`Callback invoked to indicate the value of the system ringtone player is obtained.`);
585  systemRingtonePlayer = value;
586});
587```
588
589### getSystemRingtonePlayer<sup>(deprecated)</sup>
590
591getSystemRingtonePlayer(context: Context, type: RingtoneType): Promise&lt;RingtonePlayer&gt;
592
593获取系统铃声播放器,使用Promise方式异步返回结果。
594
595> **说明:**
596> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtonePlayer](#getringtoneplayer11)替代。
597
598**系统接口:** 该接口为系统接口。
599
600**系统能力:** SystemCapability.Multimedia.SystemSound.Core
601
602**参数:**
603
604| 参数名   | 类型                                                                  | 必填 | 说明                         |
605| -------- |---------------------------------------------------------------------| ---- | --------------------------- |
606| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。            |
607| type     | [RingtoneType](#ringtonetype)                                       | 是   | 待获取播放器的系统铃声的类型。 |
608
609**返回值:**
610
611| 类型                | 说明                            |
612| ------------------- | ------------------------------- |
613| Promise&lt;[RingtonePlayer](js-apis-inner-multimedia-ringtonePlayer-sys.md#ringtoneplayer)&gt; | Promise回调返回获取的系统铃声播放器。 |
614
615**示例:**
616
617```ts
618import { BusinessError } from '@kit.BasicServicesKit';
619import { common } from '@kit.AbilityKit';
620
621let context: Context = getContext(this);
622let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
623let systemRingtonePlayer: systemSoundManager.RingtonePlayer | undefined = undefined;
624
625let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
626systemSoundManagerInstance.getSystemRingtonePlayer(context, type).then((value: systemSoundManager.RingtonePlayer) => {
627  console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`);
628  systemRingtonePlayer = value;
629}).catch ((err: BusinessError) => {
630  console.error(`Failed to get the system ringtone player ${err}`);
631});
632```
633
634### setRingtoneUri<sup>11+</sup>
635
636setRingtoneUri(context: BaseContext, uri: string, type: RingtoneType): Promise&lt;void&gt;
637
638设置系统铃声uri,使用Promise方式异步返回结果。
639
640**系统接口:** 该接口为系统接口。
641
642**系统能力:** SystemCapability.Multimedia.SystemSound.Core
643
644**参数:**
645
646| 参数名   | 类型                            | 必填 | 说明                     |
647| -------- |-------------------------------| ---- | ------------------------ |
648| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)            | 是   | 当前应用的上下文。         |
649| uri      | string                        | 是   | 被设置的系统铃声的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
650| type     | [RingtoneType](#ringtonetype) | 是   | 被设置的系统铃声的类型。   |
651
652**返回值:**
653
654| 类型                | 说明                            |
655| ------------------- | ------------------------------- |
656| Promise&lt;void&gt; | Promise回调返回设置成功或失败。   |
657
658**错误码:**
659
660以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
661
662| 错误码ID | 错误信息              |
663| ------- | --------------------- |
664| 202 | Caller is not a system application. |
665| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
666| 5400103 | I/O error. |
667
668**示例:**
669
670```ts
671import { BusinessError } from '@kit.BasicServicesKit';
672import { common } from '@kit.AbilityKit';
673
674let context: common.BaseContext = getContext(this);
675let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
676let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
677
678let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
679systemSoundManagerInstance.setRingtoneUri(context, uri, type).then(() => {
680  console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`);
681}).catch ((err: BusinessError) => {
682  console.error(`Failed to set the system ringtone uri ${err}`);
683});
684```
685
686### getRingtoneUri<sup>11+</sup>
687
688getRingtoneUri(context: BaseContext, type: RingtoneType): Promise&lt;string&gt;
689
690获取系统铃声uri,使用Promise方式异步返回结果。
691
692**系统接口:** 该接口为系统接口。
693
694**系统能力:** SystemCapability.Multimedia.SystemSound.Core
695
696**参数:**
697
698| 参数名   | 类型                             | 必填 | 说明                     |
699| -------- | -------------------------------| ---- | ------------------------ |
700| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)| 是   | 当前应用的上下文。         |
701| type     | [RingtoneType](#ringtonetype)  | 是   | 被设置的系统铃声的类型。   |
702
703**返回值:**
704
705| 类型                | 说明                                |
706| ------------------- | ---------------------------------- |
707| Promise&lt;string&gt; | Promise回调返回获取的系统铃声uri。 |
708
709**错误码:**
710
711以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
712
713| 错误码ID | 错误信息              |
714| -------- | --------------------- |
715| 202 | Caller is not a system application. |
716| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
717| 5400103  | I/O error. |
718
719**示例:**
720
721```ts
722import { BusinessError } from '@kit.BasicServicesKit';
723import { common } from '@kit.AbilityKit';
724
725let context: common.BaseContext = getContext(this);
726let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
727
728let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
729systemSoundManagerInstance.getRingtoneUri(context, type).then((value: string) => {
730  console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`);
731}).catch ((err: BusinessError) => {
732  console.error(`Failed to get the system ringtone uri ${err}`);
733});
734```
735
736### getRingtonePlayer<sup>11+</sup>
737
738getRingtonePlayer(context: BaseContext, type: RingtoneType): Promise&lt;RingtonePlayer&gt;
739
740获取系统铃声播放器,使用Promise方式异步返回结果。
741
742**系统接口:** 该接口为系统接口。
743
744**系统能力:** SystemCapability.Multimedia.SystemSound.Core
745
746**参数:**
747
748| 参数名   | 类型                              | 必填 | 说明                         |
749| -------- | --------------------------------| ---- | --------------------------- |
750| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
751| type     | [RingtoneType](#ringtonetype)   | 是   | 待获取播放器的系统铃声的类型。 |
752
753**返回值:**
754
755| 类型                | 说明                            |
756| ------------------- | ------------------------------- |
757| Promise&lt;[RingtonePlayer](js-apis-inner-multimedia-ringtonePlayer-sys.md#ringtoneplayer)&gt; | Promise回调返回获取的系统铃声播放器。 |
758
759**错误码:**
760
761以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
762
763| 错误码ID | 错误信息              |
764| -------- | --------------------- |
765| 202 | Caller is not a system application. |
766| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
767
768**示例:**
769
770```ts
771import { BusinessError } from '@kit.BasicServicesKit';
772import { common } from '@kit.AbilityKit';
773
774let context: common.BaseContext = getContext(this);
775let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
776let systemRingtonePlayer: systemSoundManager.RingtonePlayer | undefined = undefined;
777
778let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
779systemSoundManagerInstance.getRingtonePlayer(context, type).then((value: systemSoundManager.RingtonePlayer) => {
780  console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`);
781  systemRingtonePlayer = value;
782}).catch ((err: BusinessError) => {
783  console.error(`Failed to get the system ringtone player ${err}`);
784});
785```
786
787### setSystemToneUri<sup>11+</sup>
788
789setSystemToneUri(context: BaseContext, uri: string, type: SystemToneType): Promise&lt;void&gt;
790
791设置系统提示音uri,使用Promise方式异步返回结果。
792
793**系统接口:** 该接口为系统接口。
794
795**系统能力:** SystemCapability.Multimedia.SystemSound.Core
796
797**参数:**
798
799| 参数名   | 类型                                  | 必填 | 说明                     |
800| -------- |-------------------------------------| ---- | ------------------------ |
801| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。         |
802| uri      | string                              | 是   | 被设置的系统提示音的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
803| type     | [SystemToneType](#systemtonetype11) | 是   | 被设置的系统提示音的类型。   |
804
805**返回值:**
806
807| 类型                | 说明                            |
808| ------------------- | ------------------------------- |
809| Promise&lt;void&gt; | Promise回调返回设置成功或失败。   |
810
811**错误码:**
812
813以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
814
815| 错误码ID | 错误信息              |
816| ------- | --------------------- |
817| 202 | Caller is not a system application. |
818| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
819| 5400103 | I/O error. |
820
821**示例:**
822
823```ts
824import { BusinessError } from '@kit.BasicServicesKit';
825import { common } from '@kit.AbilityKit';
826
827let context: common.BaseContext = getContext(this);
828let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
829let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
830
831let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
832systemSoundManagerInstance.setSystemToneUri(context, uri, type).then(() => {
833  console.info(`Promise returned to indicate a successful setting of the system tone uri.`);
834}).catch ((err: BusinessError) => {
835  console.error(`Failed to set the system tone uri ${err}`);
836});
837```
838
839### getSystemToneUri<sup>11+</sup>
840
841getSystemToneUri(context: BaseContext, type: SystemToneType): Promise&lt;string&gt;
842
843获取系统提示音uri,使用Promise方式异步返回结果。
844
845**系统接口:** 该接口为系统接口。
846
847**系统能力:** SystemCapability.Multimedia.SystemSound.Core
848
849**参数:**
850
851| 参数名   | 类型                                  | 必填 | 说明                     |
852| -------- |-------------------------------------| ---- | ------------------------ |
853| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。         |
854| type     | [SystemToneType](#systemtonetype11) | 是   | 被设置的系统提示音的类型。   |
855
856**返回值:**
857
858| 类型                | 说明                                |
859| ------------------- | ---------------------------------- |
860| Promise&lt;string&gt; | Promise回调返回获取的系统提示音uri。 |
861
862**错误码:**
863
864以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
865
866| 错误码ID | 错误信息              |
867| ------- | --------------------- |
868| 202 | Caller is not a system application. |
869| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
870| 5400103 | I/O error. |
871
872**示例:**
873
874```ts
875import { BusinessError } from '@kit.BasicServicesKit';
876import { common } from '@kit.AbilityKit';
877
878let context: common.BaseContext = getContext(this);
879let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
880
881let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
882systemSoundManagerInstance.getSystemToneUri(context, type).then((value: string) => {
883  console.info(`Promise returned to indicate that the value of the system tone uri is obtained ${value}.`);
884}).catch ((err: BusinessError) => {
885  console.error(`Failed to get the system tone uri ${err}`);
886});
887```
888
889### getSystemTonePlayer<sup>11+</sup>
890
891getSystemTonePlayer(context: BaseContext, type: SystemToneType): Promise&lt;SystemTonePlayer&gt;
892
893获取系统提示音播放器,使用Promise方式异步返回结果。
894
895**系统接口:** 该接口为系统接口。
896
897**系统能力:** SystemCapability.Multimedia.SystemSound.Core
898
899**参数:**
900
901| 参数名   | 类型                                  | 必填 | 说明                         |
902| -------- |-------------------------------------| ---- | --------------------------- |
903| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
904| type     | [SystemToneType](#systemtonetype11) | 是   | 待获取播放器的系统提示音的类型。 |
905
906**返回值:**
907
908| 类型                                                                                               | 说明                            |
909|--------------------------------------------------------------------------------------------------| ------------------------------- |
910| Promise&lt;[SystemTonePlayer](js-apis-inner-multimedia-systemTonePlayer-sys.md#systemtoneplayer)&gt; | Promise回调返回获取的系统提示音播放器。 |
911
912**错误码:**
913
914以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
915
916| 错误码ID | 错误信息              |
917| ------- | --------------------- |
918| 202 | Caller is not a system application. |
919| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
920
921**示例:**
922
923```ts
924import { BusinessError } from '@kit.BasicServicesKit';
925import { common } from '@kit.AbilityKit';
926
927let context: common.BaseContext = getContext(this);
928let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
929let systemTonePlayer: systemSoundManager.SystemTonePlayer | undefined = undefined;
930
931let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
932systemSoundManagerInstance.getSystemTonePlayer(context, type).then((value: systemSoundManager.SystemTonePlayer) => {
933  console.info(`Promise returned to indicate that the value of the system tone player is obtained.`);
934    systemTonePlayer = value;
935}).catch ((err: BusinessError) => {
936  console.error(`Failed to get the system tone player ${err}`);
937});
938```
939
940### getDefaultRingtoneAttrs<sup>12+</sup>
941
942getDefaultRingtoneAttrs(context: BaseContext, type: RingtoneType): Promise&lt;ToneAttrs&gt;
943
944获取系统铃声的属性,使用Promise方式异步返回结果。
945
946**系统接口:** 该接口为系统接口。
947
948**系统能力:** SystemCapability.Multimedia.SystemSound.Core
949
950**参数:**
951
952| 参数名   | 类型                                  | 必填 | 说明                         |
953| -------- |-------------------------------------| ---- | --------------------------- |
954| context  |[BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
955| type     |[RingtoneType](#ringtonetype)        | 是   | 被设置的系统铃声的类型。  |
956
957**返回值:**
958
959| 类型                                       | 说明                  |
960|------------------------------------------|---------------------|
961| Promise&lt;[ToneAttrs](#toneattrs12)&gt; | Promise回调返回系统铃声的属性。 |
962
963**错误码:**
964
965以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
966
967| 错误码ID | 错误信息              |
968| ------- | --------------------- |
969| 202 | Caller is not a system application. |
970| 401 | The parameters check failed. |
971| 5400103 | I/O error. |
972
973**示例:**
974
975```ts
976import { BusinessError } from '@kit.BasicServicesKit';
977import { common } from '@kit.AbilityKit';
978
979let context: common.BaseContext = getContext(this);
980let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
981
982let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
983systemSoundManagerInstance.getDefaultRingtoneAttrs(context, type).then((value: systemSoundManager.ToneAttrs) => {
984  console.info(`Promise returned to indicate that the value of the attributes of the default ringtone is obtained.`);
985}).catch ((err: BusinessError) => {
986  console.error(`Failed to get the default ring tone attrs ${err}`);
987});
988```
989
990### getRingtoneAttrList<sup>12+</sup>
991
992getRingtoneAttrList(context: BaseContext, type: RingtoneType): Promise&lt;ToneAttrsArray&gt;
993
994获取系统铃声的属性列表,使用Promise方式异步返回结果。
995
996**系统接口:** 该接口为系统接口。
997
998**系统能力:** SystemCapability.Multimedia.SystemSound.Core
999
1000**参数:**
1001
1002| 参数名   | 类型                                  | 必填 | 说明                         |
1003| -------- |-------------------------------------| ---- | --------------------------- |
1004| context  |[BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1005| type     |[RingtoneType](#ringtonetype)        | 是   | 被设置的系统铃声的类型。  |
1006
1007**返回值:**
1008
1009| 类型                                                 | 说明                    |
1010|----------------------------------------------------|-----------------------|
1011| Promise&lt;[ToneAttrsArray](#toneattrsarray12)&gt; | Promise回调返回系统铃声的属性列表。 |
1012
1013**错误码:**
1014
1015以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1016
1017| 错误码ID | 错误信息              |
1018| ------- | --------------------- |
1019| 202 | Caller is not a system application. |
1020| 401 | The parameters check failed. |
1021| 5400103 | I/O error. |
1022
1023**示例:**
1024
1025```ts
1026import { BusinessError } from '@kit.BasicServicesKit';
1027import { common } from '@kit.AbilityKit';
1028
1029let context: common.BaseContext = getContext(this);
1030let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
1031
1032let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1033systemSoundManagerInstance.getRingtoneAttrList(context, type).then((value: systemSoundManager.ToneAttrsArray) => {
1034  console.info(`Promise returned to indicate that the value of the attribute list of ringtone is obtained.`);
1035}).catch ((err: BusinessError) => {
1036  console.error(`Failed to get the attribute list of ringtone ${err}`);
1037});
1038```
1039
1040### getDefaultSystemToneAttrs<sup>12+</sup>
1041
1042getDefaultSystemToneAttrs(context: BaseContext, type: SystemToneType): Promise&lt;ToneAttrs&gt;
1043
1044获取系统提示音的属性,使用Promise方式异步返回结果。
1045
1046**系统接口:** 该接口为系统接口。
1047
1048**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1049
1050**参数:**
1051
1052| 参数名   | 类型                                                                          | 必填 | 说明                         |
1053| -------- |-----------------------------------------------------------------------------| ---- | --------------------------- |
1054| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1055| type     | [SystemToneType](#systemtonetype11)                                         | 是   | 待获取播放器的系统提示音的类型。 |
1056
1057**返回值:**
1058
1059| 类型                                      | 说明                   |
1060|-----------------------------------------|----------------------|
1061| Promise&lt;[ToneAttrs](#toneattrs12)&gt; | Promise回调返回系统提示音的属性。 |
1062
1063**错误码:**
1064
1065以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1066
1067| 错误码ID | 错误信息              |
1068| ------- | --------------------- |
1069| 202 | Caller is not a system application. |
1070| 401 | The parameters check failed. |
1071| 5400103 | I/O error. |
1072
1073**示例:**
1074
1075```ts
1076import { BusinessError } from '@kit.BasicServicesKit';
1077import { common } from '@kit.AbilityKit';
1078
1079let context: common.BaseContext = getContext(this);
1080let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
1081
1082let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1083systemSoundManagerInstance.getDefaultSystemToneAttrs(context, type).then((value: systemSoundManager.ToneAttrs) => {
1084  console.info(`Promise returned to indicate that the value of the attributes of the system ringtone is obtained.`);
1085}).catch ((err: BusinessError) => {
1086  console.error(`Failed to get the system tone attrs ${err}`);
1087});
1088```
1089
1090### getSystemToneAttrList<sup>12+</sup>
1091
1092getSystemToneAttrList(context: BaseContext, type: SystemToneType): Promise&lt;ToneAttrsArray&gt;
1093
1094获取系统提示音的属性列表,使用Promise方式异步返回结果。
1095
1096**系统接口:** 该接口为系统接口。
1097
1098**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1099
1100**参数:**
1101
1102| 参数名   | 类型                                                                          | 必填 | 说明                         |
1103| -------- |-----------------------------------------------------------------------------| ---- | --------------------------- |
1104| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1105| type     | [SystemToneType](#systemtonetype11)                                         | 是   | 待获取播放器的系统提示音的类型。  |
1106
1107**返回值:**
1108
1109| 类型                                                | 说明                     |
1110|---------------------------------------------------|------------------------|
1111| Promise&lt;[ToneAttrsArray](#toneattrsarray12)&gt; | Promise回调返回系统提示音的属性列表。 |
1112
1113**错误码:**
1114
1115以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1116
1117| 错误码ID | 错误信息              |
1118| ------- | --------------------- |
1119| 202 | Caller is not a system application. |
1120| 401 | The parameters check failed. |
1121| 5400103 | I/O error. |
1122
1123**示例:**
1124
1125```ts
1126import { BusinessError } from '@kit.BasicServicesKit';
1127import { common } from '@kit.AbilityKit';
1128
1129let context: common.BaseContext = getContext(this);
1130let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
1131
1132let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1133systemSoundManagerInstance.getSystemToneAttrList(context, type).then((value: systemSoundManager.ToneAttrsArray) => {
1134  console.info(`Promise returned to indicate that the value of the attribute list of system tone is obtained.`);
1135}).catch ((err: BusinessError) => {
1136  console.error(`Failed to get the attribute list of system tone ${err}`);
1137});
1138```
1139
1140### getDefaultAlarmToneAttrs<sup>12+</sup>
1141
1142getDefaultAlarmToneAttrs(context: BaseContext): Promise&lt;ToneAttrs&gt;
1143
1144获取系统闹铃的属性,使用Promise方式异步返回结果。
1145
1146**系统接口:** 该接口为系统接口。
1147
1148**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1149
1150**参数:**
1151
1152| 参数名   | 类型         | 必填 | 说明        |
1153| --------|------------| ---- |-----------|
1154| context | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。 |
1155
1156**返回值:**
1157
1158| 类型                                      | 说明                  |
1159|-----------------------------------------|---------------------|
1160| Promise&lt;[ToneAttrs](#toneattrs12)&gt; | Promise回调返回系统闹铃的属性。 |
1161
1162**错误码:**
1163
1164以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1165
1166| 错误码ID | 错误信息              |
1167| ------- | --------------------- |
1168| 202 | Caller is not a system application. |
1169| 401 | The parameters check failed. |
1170| 5400103 | I/O error. |
1171
1172**示例:**
1173
1174```ts
1175import { BusinessError } from '@kit.BasicServicesKit';
1176import { common } from '@kit.AbilityKit';
1177
1178let context: common.BaseContext = getContext(this);
1179
1180let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1181systemSoundManagerInstance.getDefaultAlarmToneAttrs(context).then((value: systemSoundManager.ToneAttrs) => {
1182  console.info(`Promise returned to indicate that the value of the attributes of the default alarm tone is obtained.`);
1183}).catch ((err: BusinessError) => {
1184  console.error(`Failed to get the default alarm tone attrs ${err}`);
1185});
1186```
1187
1188### setAlarmToneUri<sup>12+</sup>
1189
1190setAlarmToneUri(context: Context, uri: string): Promise&lt;void&gt;
1191
1192设置系统闹铃uri,使用Promise方式异步返回结果。
1193
1194**系统接口:** 该接口为系统接口。
1195
1196**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1197
1198**参数:**
1199
1200| 参数名   | 类型        | 必填 | 说明   |
1201| -------- | --------- | ---- |--------------------------|
1202| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。                                                                           |
1203| uri      | string    | 是   | 被设置的系统闹铃的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
1204
1205**返回值:**
1206
1207| 类型                | 说明                   |
1208| ------------------- |----------------------|
1209| Promise&lt;void&gt; | Promise回调返回设置成功或失败。  |
1210
1211**示例:**
1212
1213```ts
1214import { BusinessError } from '@kit.BasicServicesKit';
1215import { common } from '@kit.AbilityKit';
1216
1217let context: Context = getContext(this);
1218let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
1219
1220let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1221systemSoundManagerInstance.setAlarmToneUri(context, uri).then(() => {
1222  console.info(`Promise returned to indicate a successful setting of the alarm tone uri.`);
1223}).catch ((err: BusinessError) => {
1224  console.error(`Failed to set the alarm tone uri ${err}`);
1225});
1226```
1227
1228### getAlarmToneUri<sup>12+</sup>
1229
1230getAlarmToneUri(context: Context): Promise&lt;string&gt;
1231
1232获取系统当前闹铃uri,使用Promise方式异步返回结果。
1233
1234**系统接口:** 该接口为系统接口。
1235
1236**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1237
1238**参数:**
1239
1240| 参数名   | 类型      | 必填 | 说明              |
1241| -------- | --------| ---- |-----------------|
1242| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。  |
1243
1244**返回值:**
1245
1246| 类型                    | 说明                    |
1247|-----------------------|-----------------------|
1248| Promise&lt;string&gt; | Promise回调返回系统当前闹铃uri。 |
1249
1250**示例:**
1251
1252```ts
1253import { BusinessError } from '@kit.BasicServicesKit';
1254import { common } from '@kit.AbilityKit';
1255
1256let context: Context = getContext(this);
1257
1258let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1259systemSoundManagerInstance.getAlarmToneUri(context).then((value: string) => {
1260  console.info(`Promise returned to indicate that the value of alarm tone uri.`);
1261}).catch ((err: BusinessError) => {
1262  console.error(`Failed to get the alarm tone uri ${err}`);
1263});
1264```
1265
1266### getAlarmToneAttrList<sup>12+</sup>
1267
1268getAlarmToneAttrList(context: BaseContext): Promise&lt;ToneAttrsArray&gt;
1269
1270获取全部闹铃属性列表,使用Promise方式异步返回结果。
1271
1272**系统接口:** 该接口为系统接口。
1273
1274**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1275
1276**参数:**
1277
1278| 参数名   | 类型            | 必填 | 说明                         |
1279| -------- |--------------| ---- | --------------------------- |
1280| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)  | 是   | 当前应用的上下文。            |
1281
1282**返回值:**
1283
1284| 类型                                                 | 说明                   |
1285|----------------------------------------------------|----------------------|
1286| Promise&lt;[ToneAttrsArray](#toneattrsarray12)&gt; | Promise回调返回全部闹铃属性列表。 |
1287
1288**错误码:**
1289
1290以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1291
1292| 错误码ID | 错误信息              |
1293| ------- | --------------------- |
1294| 202 | Caller is not a system application. |
1295| 401 | The parameters check failed. |
1296| 5400103 | I/O error. |
1297
1298**示例:**
1299
1300```ts
1301import { BusinessError } from '@kit.BasicServicesKit';
1302import { common } from '@kit.AbilityKit';
1303
1304let context: common.BaseContext = getContext(this);
1305
1306let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1307systemSoundManagerInstance.getAlarmToneAttrList(context).then((value: systemSoundManager.ToneAttrsArray) => {
1308  console.info(`Promise returned to indicate that the value of the attribute list of alarm tone is obtained.`);
1309}).catch ((err: BusinessError) => {
1310  console.error(`Failed to get the attribute list of alarm tone ${err}`);
1311});
1312```
1313
1314### openAlarmTone<sup>12+</sup>
1315
1316openAlarmTone(context: Context, uri: string): Promise&lt;number&gt;
1317
1318打开闹铃文件,使用Promise方式异步返回结果。
1319
1320**系统接口:** 该接口为系统接口。
1321
1322**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1323
1324**参数:**
1325
1326| 参数名   | 类型       | 必填 | 说明                                                                                  |
1327| -------- | ---------| ---- |-------------------------------------------------------------------------------------|
1328| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。                                                                           |
1329| uri      | string   | 是   | 被设置的系统闹铃的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
1330
1331**返回值:**
1332
1333| 类型                    | 说明             |
1334|-----------------------|----------------|
1335| Promise&lt;number&gt; | Promise回调返回fd。 |
1336
1337**错误码:**
1338
1339以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1340
1341| 错误码ID | 错误信息              |
1342| ------- | --------------------- |
1343| 202 | Caller is not a system application. |
1344| 401 | The parameters check failed. |
1345| 5400103 | I/O error. |
1346| 20700001 | Tone type mismatch, e.g. tone of uri is notification instead of alarm. |
1347
1348**示例:**
1349
1350```ts
1351import { BusinessError } from '@kit.BasicServicesKit';
1352import { common } from '@kit.AbilityKit';
1353
1354let context: Context = getContext(this);
1355let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
1356
1357let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1358systemSoundManagerInstance.openAlarmTone(context, uri).then((value: number) => {
1359  console.info(`Promise returned to indicate the value of fd.`);
1360}).catch ((err: BusinessError) => {
1361  console.error(`Failed to open alarm tone ${err}`);
1362});
1363```
1364
1365### close<sup>12+</sup>
1366
1367close(fd: number): Promise&lt;void&gt;
1368
1369关闭闹铃文件,使用Promise方式异步返回结果。
1370
1371**系统接口:** 该接口为系统接口
1372
1373**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1374
1375**参数:**
1376
1377| 参数名 | 类型   | 必填 | 说明                                           |
1378|-----| --------| ---- |----------------------------------------------|
1379| fd  | number  | 是   | 文件描述符,通过[openAlarmTone](#openalarmtone12)获取。 |
1380
1381**返回值:**
1382
1383| 类型                  | 说明             |
1384|---------------------|----------------|
1385| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1386
1387**错误码:**
1388
1389以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1390
1391| 错误码ID | 错误信息              |
1392| ------- | --------------------- |
1393| 202 | Caller is not a system application. |
1394| 401 | The parameters check failed. |
1395| 5400103 | I/O error. |
1396
1397**示例:**
1398
1399```ts
1400import { BusinessError } from '@kit.BasicServicesKit';
1401import { common } from '@kit.AbilityKit';
1402
1403let context: Context = getContext(this);
1404let fd = 50; // 需更改为目标铃声的fd
1405
1406let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1407systemSoundManagerInstance.close(fd).then(() => {
1408  console.info(`Promise returned to indicate that the fd has been close.`);
1409}).catch ((err: BusinessError) => {
1410  console.error(`Failed to close fd ${err}`);
1411});
1412```
1413
1414### addCustomizedTone<sup>12+</sup>
1415
1416addCustomizedTone(context: BaseContext, toneAttr: ToneAttrs, externalUri: string): Promise&lt;string&gt;
1417
1418通过铃音uri将自定义铃音添加到铃音库,使用Promise方式异步返回结果。
1419
1420**系统接口:** 该接口为系统接口。
1421
1422**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1423
1424**参数:**
1425
1426| 参数名 | 类型        | 必填 | 说明            |
1427|-----|-----------| ---- |---------------|
1428| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。     |
1429| toneAttr  | ToneAttrs | 是   | 铃音属性。         |
1430| externalUri  | string    | 是   | 外部存储器中的铃音uri。 |
1431
1432**返回值:**
1433
1434| 类型                    | 说明                      |
1435|-----------------------|-------------------------|
1436| Promise&lt;string&gt; | Promise回调返回铃音在铃音库中的uri。 |
1437
1438**错误码:**
1439
1440以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1441
1442| 错误码ID   | 错误信息              |
1443|---------| -------------------- |
1444| 201     | Permission denied. |
1445| 202     | Caller is not a system application. |
1446| 401     | The parameters check failed. |
1447| 5400102     | Operation is not allowed, e.g. ringtone to add is not customized. |
1448| 5400103 | I/O error. |
1449
1450**示例:**
1451
1452```ts
1453import { BusinessError } from '@kit.BasicServicesKit';
1454import { common } from '@kit.AbilityKit';
1455
1456let context: Context = getContext(this);
1457let title = 'test'; // 需更改为实际名称
1458let fileName = 'displayName_test'; // 需更改为实际文件名
1459let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM;
1460
1461let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
1462toneAttrs.setTitle(title);
1463toneAttrs.setFileName(fileName);
1464toneAttrs.setCategory(categoryValue);
1465
1466let path = 'file://data/test.ogg'; // 需更改为实际铃音uri
1467
1468let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1469systemSoundManagerInstance.addCustomizedTone(context, toneAttrs, path).then((value: string) => {
1470  console.info(`Promise returned to indicate that the value of tone uri in ringtone library.`);
1471}).catch ((err: BusinessError) => {
1472  console.error(`Failed to add customized tone ${err}`);
1473});
1474```
1475
1476### addCustomizedTone<sup>12+</sup>
1477
1478addCustomizedTone(context: BaseContext, toneAttr: ToneAttrs, fd: number, offset?: number, length?: number): Promise&lt;string&gt;
1479
1480通过文件描述符fd将自定义铃音添加到铃音库,使用Promise方式异步返回结果。
1481
1482**系统接口:** 该接口为系统接口。
1483
1484**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1485
1486**参数:**
1487
1488| 参数名 | 类型        | 必填 | 说明                                                                     |
1489|-----|-----------|----|------------------------------------------------------------------------|
1490| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是  | 当前应用的上下文。                                                              |
1491| toneAttr | [ToneAttrs](#toneattrs12) | 是  | 铃音属性。                                                                  |
1492| fd  | number    | 是  | 文件描述符,可通过[fs.open](../apis-core-file-kit/js-apis-file-fs.md#fsopen)获取。 |
1493| offset | number    | 否  | 读取数据的偏移量(以字节为单位)。默认情况下为0。                                              |
1494| length | number    | 否  | 读取的数据的长度(以字节为单位)。默认情况下,长度为偏移后的剩余全部字节数。                                 |
1495
1496**返回值:**
1497
1498| 类型                    | 说明                      |
1499|-----------------------|-------------------------|
1500| Promise&lt;string&gt; | Promise回调返回铃音在铃音库中的uri。 |
1501
1502**错误码:**
1503
1504以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1505
1506| 错误码ID   | 错误信息              |
1507|---------| -------------------- |
1508| 201     | Permission denied. |
1509| 202     | Caller is not a system application. |
1510| 401     | The parameters check failed. |
1511| 5400102     | Operation is not allowed, e.g. ringtone to add is not customized. |
1512| 5400103 | I/O error. |
1513
1514**示例:**
1515
1516```ts
1517import { BusinessError } from '@kit.BasicServicesKit';
1518import { common } from '@kit.AbilityKit';
1519
1520let context: Context = getContext(this);
1521let title = 'test'; // 需更改为实际名称
1522let fileName = 'displayName_test'; // 需更改为实际文件名
1523let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM;
1524
1525let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
1526toneAttrs.setTitle(title);
1527toneAttrs.setFileName(fileName);
1528toneAttrs.setCategory(categoryValue);
1529
1530let fd = 10; // 需更改为实际铃音fd,
1531let offset = 0; // 需更改为实际所需偏移量
1532let length = 50; // 需更改为实际所需数据长度
1533
1534let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1535systemSoundManagerInstance.addCustomizedTone(context, toneAttrs, fd, offset, length).then((value: string) => {
1536  console.info(`Promise returned to indicate that the value of tone uri in ringtone library.`);
1537}).catch ((err: BusinessError) => {
1538  console.error(`Failed to add customized tone ${err}`);
1539});
1540```
1541
1542### removeCustomizedTone<sup>12+</sup>
1543
1544removeCustomizedTone(context: BaseContext, uri: string): Promise&lt;void&gt;
1545
1546从铃音库中删除自定义铃音,使用Promise方式异步返回结果。
1547
1548**系统接口:** 该接口为系统接口。
1549
1550**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1551
1552**参数:**
1553
1554| 参数名 | 类型        | 必填 | 说明                                                                                                      |
1555|-----|-----------| ---- |---------------------------------------------------------------------------------------------------------|
1556| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。                                                                                               |
1557| uri  | string    | 是   | 铃音uri,可通过[addCustomizedTone](#addcustomizedtone12)或[getAlarmToneAttrList](#getalarmtoneattrlist12)等方法获取 |
1558
1559**返回值:**
1560
1561| 类型                  | 说明                    |
1562|---------------------|-----------------------|
1563| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1564
1565**错误码:**
1566
1567以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1568
1569| 错误码ID   | 错误信息              |
1570|---------| -------------------- |
1571| 201     | Permission denied. |
1572| 202     | Caller is not a system application. |
1573| 401     | The parameters check failed. |
1574| 5400102     | Operation is not allowed, e.g. ringtone to add is not customized. |
1575| 5400103 | I/O error. |
1576
1577**示例:**
1578
1579```ts
1580import { BusinessError } from '@kit.BasicServicesKit';
1581import { common } from '@kit.AbilityKit';
1582
1583let context: Context = getContext(this);
1584let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
1585
1586let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1587systemSoundManagerInstance.removeCustomizedTone(context, uri).then(() => {
1588  console.info(`Promise returned to indicate that the customized tone has been deleted.`);
1589}).catch ((err: BusinessError) => {
1590  console.error(`Failed to delete customized tone ${err}`);
1591});
1592```
1593
1594## RingtonePlayer<sup>10+</sup>
1595
1596type RingtonePlayer = _RingtonePlayer;
1597
1598系统铃音播放器对象。
1599
1600**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1601
1602| 类型              |说明     |
1603|-----------------|-------|
1604| _RingtonePlayer | 系统铃音播放器。 |
1605
1606## SystemTonePlayer<sup>11+</sup>
1607
1608type SystemTonePlayer = _SystemTonePlayer;
1609
1610系统提示音播放器对象。
1611
1612**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1613
1614| 类型              | 说明        |
1615|-----------------|-----------|
1616| _SystemTonePlayer | 系统提示音播放器。 |
1617
1618## RingtoneOptions<sup>10+</sup>
1619
1620type RingtoneOptions = _RingtoneOptions;
1621
1622系统铃音播放器配置项。
1623
1624**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1625
1626| 类型              | 说明          |
1627|-----------------|-------------|
1628| _RingtoneOptions | 系统铃音播放器配置项。 |
1629
1630## SystemToneOptions<sup>11+</sup>
1631
1632type SystemToneOptions = _SystemToneOptions;
1633
1634系统提示音播放器配置项。
1635
1636**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1637
1638| 类型              | 说明            |
1639|-----------------|---------------|
1640| _SystemToneOptions | 系统提示音音播放器配置项。 |
1641
1642
1643
1644