提交 c173fdb6 编写于 作者: G Gloria

Update docs against 17888+18042+18083+18426

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 485c3482
...@@ -14,7 +14,7 @@ The audio interruption policy determines the operations (for example, pause, res ...@@ -14,7 +14,7 @@ The audio interruption policy determines the operations (for example, pause, res
Two audio interruption modes, specified by [InterruptMode](../reference/apis/js-apis-audio.md#interruptmode9), are preset in the audio interruption policy: Two audio interruption modes, specified by [InterruptMode](../reference/apis/js-apis-audio.md#interruptmode9), are preset in the audio interruption policy:
- **SHARED_MODE**: Multiple audio streams created by an application share one audio focus. The concurrency rules between these audio streams are determined by the application, without the use of the audio interruption policy. However, if another application needs to play audio while one of these audio streams is being played, the audio interruption policy is triggered. - **SHARE_MODE**: Multiple audio streams created by an application share one audio focus. The concurrency rules between these audio streams are determined by the application, without the use of the audio interruption policy. However, if another application needs to play audio while one of these audio streams is being played, the audio interruption policy is triggered.
- **INDEPENDENT_MODE**: Each audio stream created by an application has an independent audio focus. When multiple audio streams are played concurrently, the audio interruption policy is triggered. - **INDEPENDENT_MODE**: Each audio stream created by an application has an independent audio focus. When multiple audio streams are played concurrently, the audio interruption policy is triggered.
......
...@@ -8,7 +8,7 @@ OpenHarmony provides multiple classes for you to develop audio playback applicat ...@@ -8,7 +8,7 @@ OpenHarmony provides multiple classes for you to develop audio playback applicat
- [AudioRenderer](using-audiorenderer-for-playback.md): provides ArkTS and JS API to implement audio output. It supports only the PCM format and requires applications to continuously write audio data. The applications can perform data preprocessing, for example, setting the sampling rate and bit width of audio files, before audio input. This class can be used to develop more professional and diverse playback applications. To use this class, you must have basic audio processing knowledge. - [AudioRenderer](using-audiorenderer-for-playback.md): provides ArkTS and JS API to implement audio output. It supports only the PCM format and requires applications to continuously write audio data. The applications can perform data preprocessing, for example, setting the sampling rate and bit width of audio files, before audio input. This class can be used to develop more professional and diverse playback applications. To use this class, you must have basic audio processing knowledge.
- [OpenSLES](using-opensl-es-for-playback.md): provides a set of standard, cross-platform, yet unique native audio APIs. It supports audio output in PCM format and is applicable to playback applications that are ported from other embedded platforms or that implements audio output at the native layer. - [OpenSL ES](using-opensl-es-for-playback.md): provides a set of standard, cross-platform, yet unique native audio APIs. It supports audio output in PCM format and is applicable to playback applications that are ported from other embedded platforms or that implements audio output at the native layer.
- [TonePlayer](using-toneplayer-for-playback.md): provides ArkTS and JS API to implement the playback of dialing tones and ringback tones. It can be used to play the content selected from a fixed type range, without requiring the input of media assets or audio data. This class is application to specific scenarios where dialing tones and ringback tones are played. is available only to system applications. - [TonePlayer](using-toneplayer-for-playback.md): provides ArkTS and JS API to implement the playback of dialing tones and ringback tones. It can be used to play the content selected from a fixed type range, without requiring the input of media assets or audio data. This class is application to specific scenarios where dialing tones and ringback tones are played. is available only to system applications.
......
...@@ -8,7 +8,7 @@ OpenHarmony provides multiple classes for you to develop audio recording applica ...@@ -8,7 +8,7 @@ OpenHarmony provides multiple classes for you to develop audio recording applica
- [AudioCapturer](using-audiocapturer-for-recording.md): provides ArkTS and JS API to implement audio input. It supports only the PCM format and requires applications to continuously read audio data. The application can perform data processing after audio output. This class can be used to develop more professional and diverse recording applications. To use this class, you must have basic audio processing knowledge. - [AudioCapturer](using-audiocapturer-for-recording.md): provides ArkTS and JS API to implement audio input. It supports only the PCM format and requires applications to continuously read audio data. The application can perform data processing after audio output. This class can be used to develop more professional and diverse recording applications. To use this class, you must have basic audio processing knowledge.
- [OpenSLES](using-opensl-es-for-recording.md): provides a set of standard, cross-platform, yet unique native audio APIs. It supports audio input in PCM format and is applicable to recording applications that are ported from other embedded platforms or that implements audio input at the native layer. - [OpenSL ES](using-opensl-es-for-recording.md): provides a set of standard, cross-platform, yet unique native audio APIs. It supports audio input in PCM format and is applicable to recording applications that are ported from other embedded platforms or that implements audio input at the native layer.
## Precautions for Developing Audio Recording Applications ## Precautions for Developing Audio Recording Applications
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## Multimedia Subsystem Architecture ## Multimedia Subsystem Architecture
The multimedia subsystem provides the capability of processing users' visual and auditory information. For example, it can be used to collect, compress, store, decompress, and play audio and video information. Based on the type of media information to process, the media system is usually divided into four modules: audio, media, camera, and image. The multimedia subsystem provides the capability of processing users' visual and auditory information. For example, it can be used to collect, compress, store, decompress, and play audio and video information. Based on the type of media information to process, the multimedia subsystem subsystem is usually divided into four modules: audio, media, camera, and image.
As shown in the figure below, the multimedia subsystem provides APIs for developing audio/video, camera, and gallery applications, and provides adaptation and acceleration for different hardware chips. In the middle part, it provides core media functionalities and management mechanisms in the form of services. As shown in the figure below, the multimedia subsystem provides APIs for developing audio/video, camera, and gallery applications, and provides adaptation and acceleration for different hardware chips. In the middle part, it provides core media functionalities and management mechanisms in the form of services.
......
...@@ -151,9 +151,6 @@ export default class AudioRendererDemo { ...@@ -151,9 +151,6 @@ export default class AudioRendererDemo {
console.info(`${TAG}: creating AudioRenderer success`); console.info(`${TAG}: creating AudioRenderer success`);
this.renderModel = renderer; this.renderModel = renderer;
this.renderModel.on('stateChange', (state) => { // Set the events to listen for. A callback is invoked when the AudioRenderer is switched to the specified state. this.renderModel.on('stateChange', (state) => { // Set the events to listen for. A callback is invoked when the AudioRenderer is switched to the specified state.
if (state == 1) {
console.info('audio renderer state is: STATE_PREPARED');
}
if (state == 2) { if (state == 2) {
console.info('audio renderer state is: STATE_RUNNING'); console.info('audio renderer state is: STATE_RUNNING');
} }
......
# AVSession Provider # AVSession Provider
An audio and video application needs to access the AVSession service as a provider in order to display media information in the controller (for example, Media Controller) and respond to control commands delivered by the controller. An audio and video application needs to access the AVSession service as a provider in order to display media information in the controller (for example, Media Controller) and respond to playback control commands delivered by the controller.
## Basic Concepts ## Basic Concepts
...@@ -14,22 +14,22 @@ The table below lists the key APIs used by the provider. The APIs use either a c ...@@ -14,22 +14,22 @@ The table below lists the key APIs used by the provider. The APIs use either a c
For details, see [AVSession Management](../reference/apis/js-apis-avsession.md). For details, see [AVSession Management](../reference/apis/js-apis-avsession.md).
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
| createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback&lt;AVSession&gt;): void | Creates an AVSession.<br>Only one AVSession can be created for a UIAbility.| | createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback&lt;AVSession&gt;): void | Creates an AVSession.<br>Only one AVSession can be created for a UIAbility.|
| setAVMetadata(data: AVMetadata, callback: AsyncCallback&lt;void&gt;): void | Sets AVSession metadata.| | setAVMetadata(data: AVMetadata, callback: AsyncCallback&lt;void&gt;): void | Sets AVSession metadata.|
| setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback&lt;void&gt;): void | Sets the AVSession playback state.| | setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback&lt;void&gt;): void | Sets the AVSession playback state.|
| setLaunchAbility(ability: WantAgent, callback: AsyncCallback&lt;void&gt;): void | Starts a UIAbility.| | setLaunchAbility(ability: WantAgent, callback: AsyncCallback&lt;void&gt;): void | Starts a UIAbility.|
| getController(callback: AsyncCallback&lt;AVSessionController&gt;): void | Obtains the controller of the AVSession.| | getController(callback: AsyncCallback&lt;AVSessionController&gt;): void | Obtains the controller of the AVSession.|
| activate(callback: AsyncCallback&lt;void&gt;): void | Activates the AVSession.| | activate(callback: AsyncCallback&lt;void&gt;): void | Activates the AVSession.|
| destroy(callback: AsyncCallback&lt;void&gt;): void | Destroys the AVSession.| | destroy(callback: AsyncCallback&lt;void&gt;): void | Destroys the AVSession.|
## How to Develop ## How to Develop
To enable an audio and video application to access the AVSession service as a provider, proceed as follows: To enable an audio and video application to access the AVSession service as a provider, proceed as follows:
1. Call an API in the **AVSessionManager** class to create and activate an **AVSession** object. 1. Call an API in the **AVSessionManager** class to create and activate an **AVSession** object.
```ts ```ts
import AVSessionManager from '@ohos.multimedia.avsession'; // Import the AVSessionManager module. import AVSessionManager from '@ohos.multimedia.avsession'; // Import the AVSessionManager module.
...@@ -46,10 +46,10 @@ To enable an audio and video application to access the AVSession service as a pr ...@@ -46,10 +46,10 @@ To enable an audio and video application to access the AVSession service as a pr
- AVPlaybackState - AVPlaybackState
The controller will call an API in the **AVSessionController** class to obtain the information and display or process the information. The controller will call an API in the **AVSessionController** class to obtain the information and display or process the information.
```ts ```ts
async setSessionInfo() { async setSessionInfo() {
// It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet above. // It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet in step 1.
let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION; let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION;
// The player logic that triggers changes in the session metadata and playback state is omitted here. // The player logic that triggers changes in the session metadata and playback state is omitted here.
// Set necessary session metadata. // Set necessary session metadata.
...@@ -80,13 +80,13 @@ To enable an audio and video application to access the AVSession service as a pr ...@@ -80,13 +80,13 @@ To enable an audio and video application to access the AVSession service as a pr
3. Set the UIAbility to be started by the controller. The UIAbility configured here is started when a user operates the UI of the controller, for example, clicking a widget in Media Controller. 3. Set the UIAbility to be started by the controller. The UIAbility configured here is started when a user operates the UI of the controller, for example, clicking a widget in Media Controller.
The UIAbility is set through the **WantAgent** API. For details, see [WantAgent](../reference/apis/js-apis-app-ability-wantAgent.md). The UIAbility is set through the **WantAgent** API. For details, see [WantAgent](../reference/apis/js-apis-app-ability-wantAgent.md).
```ts ```ts
import WantAgent from "@ohos.app.ability.wantAgent"; import WantAgent from "@ohos.app.ability.wantAgent";
``` ```
```ts ```ts
// It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet above. // It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet in step 1.
let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION; let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION;
let wantAgentInfo = { let wantAgentInfo = {
wants: [ wants: [
...@@ -104,14 +104,14 @@ To enable an audio and video application to access the AVSession service as a pr ...@@ -104,14 +104,14 @@ To enable an audio and video application to access the AVSession service as a pr
}) })
``` ```
4. Listen for control commands delivered by the controller, for example, Media Controller. 4. Listen for playback control commands delivered by the controller, for example, Media Controller.
> **NOTE** > **NOTE**
> >
> After the provider registers a listener for the control command event, the event will be reflected in **getValidCommands()** of the controller. In other words, the controller determines that the command is valid and triggers the corresponding event as required. To ensure that the control commands delivered by the controller can be executed normally, the provider should not use a null implementation for listening. > After the provider registers a listener for playback control commands, the commands will be reflected in **getValidCommands()** of the controller. In other words, the controller determines that the command is valid and triggers the corresponding event as required. To ensure that the playback control commands delivered by the controller can be executed normally, the provider should not use a null implementation for listening.
```ts ```ts
async setListenerForMesFromController() { async setListenerForMesFromController() {
// It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet above. // It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet in step 1.
let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION; let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION;
// Generally, logic processing on the player is implemented in the listener. // Generally, logic processing on the player is implemented in the listener.
// After the processing is complete, use the setter to synchronize the playback information. For details, see the code snippet above. // After the processing is complete, use the setter to synchronize the playback information. For details, see the code snippet above.
...@@ -140,16 +140,16 @@ To enable an audio and video application to access the AVSession service as a pr ...@@ -140,16 +140,16 @@ To enable an audio and video application to access the AVSession service as a pr
``` ```
5. Obtain an **AVSessionController** object for this **AVSession** object for interaction. 5. Obtain an **AVSessionController** object for this **AVSession** object for interaction.
```ts ```ts
async createControllerFromSession() { async createControllerFromSession() {
// It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet above. // It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet in step 1.
let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION; let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION;
// Obtain an AVSessionController object for this AVSession object. // Obtain an AVSessionController object for this AVSession object.
let controller: AVSessionManager.AVSessionController = await session.getController(); let controller: AVSessionManager.AVSessionController = await session.getController();
// The AVSessionController object can interact with the AVSession object, for example, by delivering a control command. // The AVSessionController object can interact with the AVSession object, for example, by delivering a playback control command.
let avCommand: AVSessionManager.AVControlCommand = {command:'play'}; let avCommand: AVSessionManager.AVControlCommand = {command:'play'};
controller.sendControlCommand(avCommand); controller.sendControlCommand(avCommand);
...@@ -164,11 +164,12 @@ To enable an audio and video application to access the AVSession service as a pr ...@@ -164,11 +164,12 @@ To enable an audio and video application to access the AVSession service as a pr
``` ```
6. When the audio and video application exits and does not need to continue playback, cancel the listener and destroy the **AVSession** object. 6. When the audio and video application exits and does not need to continue playback, cancel the listener and destroy the **AVSession** object.
The code snippet below is used for canceling the listener for control commands:
The code snippet below is used for canceling the listener for playback control commands:
```ts ```ts
async unregisterSessionListener() { async unregisterSessionListener() {
// It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet above. // It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet in step 1.
let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION; let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION;
// Cancel the listener of the AVSession object. // Cancel the listener of the AVSession object.
...@@ -180,11 +181,11 @@ To enable an audio and video application to access the AVSession service as a pr ...@@ -180,11 +181,11 @@ To enable an audio and video application to access the AVSession service as a pr
} }
``` ```
The code snippet below is used for destroying the AVSession object: The code snippet below is used for destroying the AVSession object:
```ts ```ts
async destroySession() { async destroySession() {
// It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet above. // It is assumed that an AVSession object has been created. For details about how to create an AVSession object, see the node snippet in step 1.
let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION; let session: AVSessionManager.AVSession = ALLREADY_CREATE_A_SESSION;
// Destroy the AVSession object. // Destroy the AVSession object.
session.destroy(function (err) { session.destroy(function (err) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册