未验证 提交 6290f722 编写于 作者: O openharmony_ci 提交者: Gitee

!23946 systemSoundManager arkts 整改

Merge pull request !23946 from zhangkai/master
......@@ -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,14 +452,14 @@ on(type: 'audioInterrupt', callback: Callback<audio.InterruptEvent>): void
**示例:**
```js
```ts
import audio from '@ohos.multimedia.audio';
let isPlaying; // 标识符,表示是否正在渲染
let isDucked; // 标识符,表示是否被降低音量
let isPlaying: boolean; // 标识符,表示是否正在渲染
let isDucked: boolean; // 标识符,表示是否被降低音量
systemRingtonePlayer.on('audioInterrupt', async(interruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
systemRingtonePlayer.on('audioInterrupt', async(interruptEvent: audio.InterruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
// 由系统进行操作,强制打断音频渲染,应用需更新自身状态及显示内容等
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
......@@ -455,7 +485,7 @@ if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
default:
break;
}
} else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
} else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
// 由应用进行操作,应用可以自主选择响应操作或忽略该事件
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME:
......@@ -466,6 +496,6 @@ if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
default:
break;
}
}
}
});
```
\ No newline at end of file
......@@ -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&gt
**示例:**
```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}`);
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册