未验证 提交 14179ef3 编写于 作者: O openharmony_ci 提交者: Gitee

!23943 arkts格式整改

Merge pull request !23943 from zhangkai/monthly_20230815
......@@ -6,52 +6,55 @@
主要包括查询和设置当前音频播放流的音效模式,音效模式包括EFFECT_NONE关闭音效模式和EFFECT_DEFAULT默认音效模式。默认音效模式会根据创建音频流的ContentType和StreamUsage自动加载对应场景的音效。
### 获取播放实例(示例代码仅支持JS格式)
### 获取播放实例
管理播放实例音效的接口是getAudioEffectMode()查询当前音频播放流的音效模式和setAudioEffectMode(mode: AudioEffectMode)设置当前音频播放流的音效模式,在使用之前,需要使用createAudioRenderer(options: AudioRendererOptions)先创建音频播放流AudioRenderer实例。
1. 步骤一:导入音频接口。
```js
```ts
import audio from '@ohos.multimedia.audio';
```
2. 步骤二:配置音频渲染参数并创建AudioRenderer实例,音频渲染参数的详细信息可以查看[AudioRendererOptions](../reference/apis/js-apis-audio.md#audiorendereroptions8),创建AudioRenderer实例时会默认挂载EFFECT_DEFAULT模式音效。
```js
let audioStreamInfo = {
```ts
import audio from '@ohos.multimedia.audio';
import { BusinessError } from '@ohos.base';
let audioStreamInfo: audio.AudioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
};
let audioRendererInfo = {
let audioRendererInfo: audio.AudioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
};
let audioRendererOptions = {
let audioRendererOptions: audio.AudioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
};
audio.createAudioRenderer(audioRendererOptions, (err, data) => {
audio.createAudioRenderer(audioRendererOptions, (err: BusinessError, data: audio.AudioRenderer) => {
if (err) {
console.error(`Invoke createAudioRenderer failed, code is ${err.code}, message is ${err.message}`);
return;
} else {
console.info('Invoke createAudioRenderer succeeded.');
let audioRenderer = data;
let audioRenderer: audio.AudioRenderer = data;
}
});
```
### 查询当前播放实例的音效模式(示例代码仅支持JS格式)
### 查询当前播放实例的音效模式
```js
audioRenderer.getAudioEffectMode((err, effectmode) => {
```ts
import { BusinessError } from '@ohos.base';
audioRenderer.getAudioEffectMode((err: BusinessError, effectmode: audio.AudioEffectMode) => {
if (err) {
console.error(`Failed to get params, code is ${err.code}, message is ${err.message}`);
return;
......@@ -61,12 +64,13 @@
});
```
### 设置当前播放实例的音效模式(示例代码仅支持JS格式)
### 设置当前播放实例的音效模式
关闭系统音效:
```js
audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_NONE, (err) => {
```ts
import { BusinessError } from '@ohos.base';
audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_NONE, (err: BusinessError) => {
if (err) {
console.error(`Failed to set params, code is ${err.code}, message is ${err.message}`);
return;
......@@ -78,8 +82,9 @@
开启系统音效默认模式:
```js
audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err) => {
```ts
import { BusinessError } from '@ohos.base';
audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err: BusinessError) => {
if (err) {
console.error(`Failed to set params, code is ${err.code}, message is ${err.message}`);
return;
......@@ -94,20 +99,21 @@
主要包括全局音效查询相应StreamUsage对应场景的音效模式。
对于播放音频类的应用,开发者需要关注该应用的音频流使用什么音效模式并做出相应的操作,比如音乐App播放时,应选择音乐场景下的模式。在使用查询接口前,开发者需要使用getStreamManager()创建一个AudioStreamManager音频流管理实例。
### 获取音频流管理接口(示例代码仅支持JS格式)
### 获取音频流管理接口
1.创建AudioStreamManager实例。在使用AudioStreamManager的API前,需要使用getStreamManager()创建一个AudioStreamManager实例。
```js
```ts
import audio from '@ohos.multimedia.audio';
let audioManager = audio.getAudioManager();
let audioStreamManager = audioManager.getStreamManager();
```
### 查询对应场景的音效模式(示例代码仅支持JS格式)
### 查询对应场景的音效模式
```js
audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MEDIA, async (err, audioEffectInfoArray) => {
```ts
import { BusinessError } from '@ohos.base';
audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MEDIA, async (err: BusinessError, audioEffectInfoArray: audio.AudioEffectInfoArray) => {
if (err) {
console.error('Failed to get effect info array');
return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册