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