提交 ff58c21e 编写于 作者: Z zhangkai269

systemSoundManager arkts 整改

Signed-off-by: Nzhangkai269 <zhangkai269@huawei.com>
上级 295273c3
...@@ -12,7 +12,7 @@ ringtonePlayer需要和[@ohos.multimedia.systemSoundManager](js-apis-systemSound ...@@ -12,7 +12,7 @@ ringtonePlayer需要和[@ohos.multimedia.systemSoundManager](js-apis-systemSound
## 导入模块 ## 导入模块
```js ```ts
import systemSoundManager from '@ohos.multimedia.systemSoundManager'; import systemSoundManager from '@ohos.multimedia.systemSoundManager';
``` ```
...@@ -45,8 +45,8 @@ import systemSoundManager from '@ohos.multimedia.systemSoundManager'; ...@@ -45,8 +45,8 @@ import systemSoundManager from '@ohos.multimedia.systemSoundManager';
**示例:** **示例:**
```js ```ts
let state = systemRingtonePlayer.state; let state: media.AVPlayerState = systemRingtonePlayer.state;
``` ```
### getTitle ### getTitle
...@@ -67,8 +67,10 @@ getTitle(callback: AsyncCallback&lt;string&gt;): void ...@@ -67,8 +67,10 @@ getTitle(callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```ts
systemRingtonePlayer.getTitle((err, value) => { import { BusinessError } from '@ohos.base';
systemRingtonePlayer.getTitle((err: BusinessError, value: string) => {
if (err) { if (err) {
console.error(`Failed to get system ringtone title. ${err}`); console.error(`Failed to get system ringtone title. ${err}`);
return; return;
...@@ -95,10 +97,12 @@ getTitle(): Promise&lt;string&gt; ...@@ -95,10 +97,12 @@ getTitle(): Promise&lt;string&gt;
**示例:** **示例:**
```js ```ts
systemRingtonePlayer.getTitle().then((value) => { import { BusinessError } from '@ohos.base';
systemRingtonePlayer.getTitle().then((value: string) => {
console.info(`Promise returned to indicate that the value of the system ringtone title is obtained ${value}.`); console.info(`Promise returned to indicate that the value of the system ringtone title is obtained ${value}.`);
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to get the system ringtone title ${err}`); console.error(`Failed to get the system ringtone title ${err}`);
}); });
``` ```
...@@ -121,12 +125,13 @@ getAudioRendererInfo(callback: AsyncCallback&lt;audio.AudioRendererInfo&gt;): vo ...@@ -121,12 +125,13 @@ getAudioRendererInfo(callback: AsyncCallback&lt;audio.AudioRendererInfo&gt;): vo
**示例:** **示例:**
```js ```ts
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
import { BusinessError } from '@ohos.base';
let audioRendererInfo: audio.AudioRendererInfo = null; let audioRendererInfo: audio.AudioRendererInfo = null;
systemRingtonePlayer.getAudioRendererInfo((err, value) => { systemRingtonePlayer.getAudioRendererInfo((err: BusinessError, value: audio.AudioRendererInfo) => {
if (err) { if (err) {
console.error(`Failed to get ringtone AudioRendererInfo. ${err}`); console.error(`Failed to get ringtone AudioRendererInfo. ${err}`);
return; return;
...@@ -154,15 +159,16 @@ getAudioRendererInfo(): Promise&lt;audio.AudioRendererInfo&gt; ...@@ -154,15 +159,16 @@ getAudioRendererInfo(): Promise&lt;audio.AudioRendererInfo&gt;
**示例:** **示例:**
```js ```ts
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
import { BusinessError } from '@ohos.base';
let audioRendererInfo: audio.AudioRendererInfo = null; let audioRendererInfo: audio.AudioRendererInfo = null;
systemRingtonePlayer.getAudioRendererInfo().then((value) => { systemRingtonePlayer.getAudioRendererInfo().then((value: audio.AudioRendererInfo) => {
console.info(`Promise returned to indicate that the value of the ringtone AudioRendererInfo is obtained ${value}.`); console.info(`Promise returned to indicate that the value of the ringtone AudioRendererInfo is obtained ${value}.`);
audioRendererInfo = value; audioRendererInfo = value;
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to get the ringtone AudioRendererInfo ${err}`); console.error(`Failed to get the ringtone AudioRendererInfo ${err}`);
}); });
``` ```
...@@ -186,10 +192,16 @@ configure(options: RingtoneOptions, callback: AsyncCallback&lt;void&gt;): void ...@@ -186,10 +192,16 @@ configure(options: RingtoneOptions, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let ringtoneOptions = {volume: 0.5, loop: true}; import { BusinessError } from '@ohos.base';
class RingtoneOptions {
volume: number;
loop: boolean;
}
let ringtoneOptions: RingtoneOptions = {volume: 0.5, loop: true};
systemRingtonePlayer.configure(ringtoneOptions, (err) => { systemRingtonePlayer.configure(ringtoneOptions, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to configure ringtone options. ${err}`); console.error(`Failed to configure ringtone options. ${err}`);
return; return;
...@@ -222,12 +234,18 @@ configure(options: RingtoneOptions): Promise&lt;void&gt; ...@@ -222,12 +234,18 @@ configure(options: RingtoneOptions): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let ringtoneOptions = {volume: 0.5, loop: true}; import { BusinessError } from '@ohos.base';
class RingtoneOptions {
volume: number;
loop: boolean;
}
let ringtoneOptions: RingtoneOptions = {volume: 0.5, loop: true};
systemRingtonePlayer.configure(ringtoneOptions).then(() => { systemRingtonePlayer.configure(ringtoneOptions).then(() => {
console.info(`Promise returned to indicate a successful setting of ringtone options.`); console.info(`Promise returned to indicate a successful setting of ringtone options.`);
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to configure ringtone options. ${err}`); console.error(`Failed to configure ringtone options. ${err}`);
}); });
``` ```
...@@ -250,8 +268,10 @@ start(callback: AsyncCallback&lt;void&gt;): void ...@@ -250,8 +268,10 @@ start(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
systemRingtonePlayer.start((err) => { import { BusinessError } from '@ohos.base';
systemRingtonePlayer.start((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to start playing ringtone. ${err}`); console.error(`Failed to start playing ringtone. ${err}`);
return; return;
...@@ -278,10 +298,12 @@ start(): Promise&lt;void&gt; ...@@ -278,10 +298,12 @@ start(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
systemRingtonePlayer.start().then(() => { systemRingtonePlayer.start().then(() => {
console.info(`Promise returned to indicate a successful starting of ringtone.`); console.info(`Promise returned to indicate a successful starting of ringtone.`);
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to start playing ringtone. ${err}`); console.error(`Failed to start playing ringtone. ${err}`);
}); });
``` ```
...@@ -304,8 +326,10 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -304,8 +326,10 @@ stop(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
systemRingtonePlayer.stop((err) => { import { BusinessError } from '@ohos.base';
systemRingtonePlayer.stop((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to stop playing ringtone. ${err}`); console.error(`Failed to stop playing ringtone. ${err}`);
return; return;
...@@ -332,10 +356,12 @@ stop(): Promise&lt;void&gt; ...@@ -332,10 +356,12 @@ stop(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
systemRingtonePlayer.stop().then(() => { systemRingtonePlayer.stop().then(() => {
console.info(`Promise returned to indicate a successful stopping of ringtone.`); console.info(`Promise returned to indicate a successful stopping of ringtone.`);
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to stop playing ringtone. ${err}`); console.error(`Failed to stop playing ringtone. ${err}`);
}); });
``` ```
...@@ -358,8 +384,10 @@ release(callback: AsyncCallback&lt;void&gt;): void ...@@ -358,8 +384,10 @@ release(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
systemRingtonePlayer.release((err) => { import { BusinessError } from '@ohos.base';
systemRingtonePlayer.release((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to release ringtone player. ${err}`); console.error(`Failed to release ringtone player. ${err}`);
return; return;
...@@ -386,10 +414,12 @@ release(): Promise&lt;void&gt; ...@@ -386,10 +414,12 @@ release(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
systemRingtonePlayer.release().then(() => { systemRingtonePlayer.release().then(() => {
console.info(`Promise returned to indicate a successful releasing of ringtone player.`); console.info(`Promise returned to indicate a successful releasing of ringtone player.`);
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to release ringtone player. ${err}`); console.error(`Failed to release ringtone player. ${err}`);
}); });
``` ```
...@@ -422,50 +452,50 @@ on(type: 'audioInterrupt', callback: Callback&lt;audio.InterruptEvent&gt;): void ...@@ -422,50 +452,50 @@ on(type: 'audioInterrupt', callback: Callback&lt;audio.InterruptEvent&gt;): void
**示例:** **示例:**
```js ```ts
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
let isPlaying; // 标识符,表示是否正在渲染 let isPlaying: boolean; // 标识符,表示是否正在渲染
let isDucked; // 标识符,表示是否被降低音量 let isDucked: boolean; // 标识符,表示是否被降低音量
systemRingtonePlayer.on('audioInterrupt', async(interruptEvent) => { systemRingtonePlayer.on('audioInterrupt', async(interruptEvent: audio.InterruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) { if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
// 由系统进行操作,强制打断音频渲染,应用需更新自身状态及显示内容等 // 由系统进行操作,强制打断音频渲染,应用需更新自身状态及显示内容等
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE: case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
// 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent // 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent
console.info('Force paused. Update playing status and stop writing'); console.info('Force paused. Update playing status and stop writing');
isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作 isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作
break; break;
case audio.InterruptHint.INTERRUPT_HINT_STOP: case audio.InterruptHint.INTERRUPT_HINT_STOP:
// 音频流已被停止,永久失去焦点,若想恢复渲染,需用户主动触发 // 音频流已被停止,永久失去焦点,若想恢复渲染,需用户主动触发
console.info('Force stopped. Update playing status and stop writing'); console.info('Force stopped. Update playing status and stop writing');
isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作 isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作
break; break;
case audio.InterruptHint.INTERRUPT_HINT_DUCK: case audio.InterruptHint.INTERRUPT_HINT_DUCK:
// 音频流已被降低音量渲染 // 音频流已被降低音量渲染
console.info('Force ducked. Update volume status'); console.info('Force ducked. Update volume status');
isDucked = true; // 简化处理,代表应用更新音量状态的若干操作 isDucked = true; // 简化处理,代表应用更新音量状态的若干操作
break; break;
case audio.InterruptHint.INTERRUPT_HINT_UNDUCK: case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
// 音频流已被恢复正常音量渲染 // 音频流已被恢复正常音量渲染
console.info('Force ducked. Update volume status'); console.info('Force ducked. Update volume status');
isDucked = false; // 简化处理,代表应用更新音量状态的若干操作 isDucked = false; // 简化处理,代表应用更新音量状态的若干操作
break; break;
default: default:
break; break;
} }
} else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) { } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
// 由应用进行操作,应用可以自主选择响应操作或忽略该事件 // 由应用进行操作,应用可以自主选择响应操作或忽略该事件
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME: case audio.InterruptHint.INTERRUPT_HINT_RESUME:
// 建议应用继续渲染(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复渲染) // 建议应用继续渲染(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复渲染)
console.info('Resume force paused renderer or ignore'); console.info('Resume force paused renderer or ignore');
// 若选择继续渲染,需在此处主动执行开始渲染的若干操作 // 若选择继续渲染,需在此处主动执行开始渲染的若干操作
break; break;
default: default:
break; break;
} }
} }
}); });
``` ```
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
## 导入模块 ## 导入模块
```js ```ts
import systemSoundManager from '@ohos.multimedia.systemSoundManager'; import systemSoundManager from '@ohos.multimedia.systemSoundManager';
``` ```
...@@ -44,8 +44,8 @@ getSystemSoundManager(): SystemSoundManager ...@@ -44,8 +44,8 @@ getSystemSoundManager(): SystemSoundManager
| [SystemSoundManager](#systemsoundmanager) | 系统声音管理类。 | | [SystemSoundManager](#systemsoundmanager) | 系统声音管理类。 |
**示例:** **示例:**
```js ```ts
let systemSoundManagerInstance = systemSoundManager.getSystemSoundManager(); let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
``` ```
## SystemSoundManager ## SystemSoundManager
...@@ -73,12 +73,14 @@ setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType, callback ...@@ -73,12 +73,14 @@ setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType, callback
**示例:** **示例:**
```js ```ts
let context = this.context; import { BusinessError } from '@ohos.base';
let context: Context = this.context;
let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
let type = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT; let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type, (err) => { systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to set system ringtone uri. ${err}`); console.error(`Failed to set system ringtone uri. ${err}`);
return; return;
...@@ -113,14 +115,16 @@ setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType): Promise ...@@ -113,14 +115,16 @@ setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType): Promise
**示例:** **示例:**
```js ```ts
let context = this.context; import { BusinessError } from '@ohos.base';
let context: Context = this.context;
let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
let type = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT; let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type).then(() => { systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type).then(() => {
console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`); console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`);
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to set the system ringtone uri ${err}`); console.error(`Failed to set the system ringtone uri ${err}`);
}); });
``` ```
...@@ -145,11 +149,13 @@ getSystemRingtoneUri(context: Context, type: RingtoneType, callback: AsyncCallba ...@@ -145,11 +149,13 @@ getSystemRingtoneUri(context: Context, type: RingtoneType, callback: AsyncCallba
**示例:** **示例:**
```js ```ts
let context = this.context; import { BusinessError } from '@ohos.base';
let type = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
let context: Context = this.context;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
systemSoundManagerInstance.getSystemRingtoneUri(context, type, (err, value) => { systemSoundManagerInstance.getSystemRingtoneUri(context, type, (err: BusinessError, value: string) => {
if (err) { if (err) {
console.error(`Failed to get system ringtone uri. ${err}`); console.error(`Failed to get system ringtone uri. ${err}`);
return; return;
...@@ -183,13 +189,15 @@ getSystemRingtoneUri(context: Context, type: RingtoneType): Promise&lt;string&gt ...@@ -183,13 +189,15 @@ getSystemRingtoneUri(context: Context, type: RingtoneType): Promise&lt;string&gt
**示例:** **示例:**
```js ```ts
let context = this.context; import { BusinessError } from '@ohos.base';
let type = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
systemSoundManagerInstance.getSystemRingtoneUri(context, type).then((value) => { let context: Context = this.context;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
systemSoundManagerInstance.getSystemRingtoneUri(context, type).then((value: string) => {
console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`); console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`);
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to get the system ringtone uri ${err}`); console.error(`Failed to get the system ringtone uri ${err}`);
}); });
``` ```
...@@ -214,12 +222,14 @@ getSystemRingtonePlayer(context: Context, type: RingtoneType, callback: AsyncCal ...@@ -214,12 +222,14 @@ getSystemRingtonePlayer(context: Context, type: RingtoneType, callback: AsyncCal
**示例:** **示例:**
```js ```ts
let context = this.context; import { BusinessError } from '@ohos.base';
let type = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
let systemRingtonePlayer = null; let context: Context = this.context;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
let systemRingtonePlayer: systemSoundManager.RingtonePlayer = null;
systemSoundManagerInstance.getSystemRingtonePlayer(context, type, (err, value) => { systemSoundManagerInstance.getSystemRingtonePlayer(context, type, (err: BusinessError, value: systemSoundManager.RingtonePlayer) => {
if (err) { if (err) {
console.error(`Failed to get system ringtone player. ${err}`); console.error(`Failed to get system ringtone player. ${err}`);
return; return;
...@@ -254,15 +264,17 @@ getSystemRingtonePlayer(context: Context, type: RingtoneType): Promise&lt;Ringto ...@@ -254,15 +264,17 @@ getSystemRingtonePlayer(context: Context, type: RingtoneType): Promise&lt;Ringto
**示例:** **示例:**
```js ```ts
let context = this.context; import { BusinessError } from '@ohos.base';
let type = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
let systemRingtonePlayer = null; let context: Context = this.context;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
let systemRingtonePlayer: systemSoundManager.RingtonePlayer = null;
systemSoundManagerInstance.getSystemRingtonePlayer(context, type).then((value) => { systemSoundManagerInstance.getSystemRingtonePlayer(context, type).then((value: systemSoundManager.RingtonePlayer) => {
console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`); console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`);
systemRingtonePlayer = value; systemRingtonePlayer = value;
}).catch ((err) => { }).catch ((err: BusinessError) => {
console.error(`Failed to get the system ringtone player ${err}`); console.error(`Failed to get the system ringtone player ${err}`);
}); });
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册