audioPlayer.stop();// Trigger the stop event callback to stop the playback.
audioPlayer.stop();// Trigger the 'stop' event callback to stop the playback.
});
});
audioPlayer.on('finish',()=>{// Set the finish event callback, which is triggered when the playback is complete.
audioPlayer.on('finish',()=>{// Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish');
});
audioPlayer.on('error',(error)=>{// Set the error event callback.
audioPlayer.on('error',(error)=>{// Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`);
...
...
@@ -107,7 +107,7 @@ async function audioPlayerDemo() {
}).catch((err)=>{
console.info('open fd failed err is'+err);
});
audioPlayer.src=fdPath;// Set the src attribute and trigger the dataLoad event callback.
audioPlayer.src=fdPath;// Set the src attribute and trigger the 'dataLoad' event callback.
}
```
...
...
@@ -119,16 +119,16 @@ import fileIO from '@ohos.fileio'
exportclassAudioDemo{
// Set the player callbacks.
setCallBack(audioPlayer){
audioPlayer.on('dataLoad',()=>{// Set the dataLoad event callback, which is triggered when the src attribute is set successfully.
audioPlayer.on('dataLoad',()=>{// Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
audioPlayer.play();// Call the play() API to start the playback and trigger the play event callback.
audioPlayer.play();// Call the play() API to start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play',()=>{// Set the play event callback.
audioPlayer.on('play',()=>{// Set the 'play' event callback.
console.info('audio play success');
});
audioPlayer.on('finish',()=>{// Set the finish event callback, which is triggered when the playback is complete.
audioPlayer.on('finish',()=>{// Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish');
audioPlayer.release();// Release the AudioPlayer resources.
audioPlayer.release();// Release the AudioPlayer instance.
audioPlayer=undefined;
});
}
...
...
@@ -147,7 +147,7 @@ export class AudioDemo {
}).catch((err)=>{
console.info('open fd failed err is'+err);
});
audioPlayer.src=fdPath;// Set the src attribute and trigger the dataLoad event callback.
audioPlayer.src=fdPath;// Set the src attribute and trigger the 'dataLoad' event callback.
}
}
```
...
...
@@ -161,15 +161,15 @@ export class AudioDemo {
// Set the player callbacks.
privateisNextMusic=false;
setCallBack(audioPlayer){
audioPlayer.on('dataLoad',()=>{// Set the dataLoad event callback, which is triggered when the src attribute is set successfully.
audioPlayer.on('dataLoad',()=>{// Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
audioPlayer.play();// Call the play() API to start the playback and trigger the play event callback.
audioPlayer.play();// Call the play() API to start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play',()=>{// Set the play event callback.
audioPlayer.on('play',()=>{// Set the 'play' event callback.
console.info('audio play success');
audioPlayer.reset();// Call the reset() API and trigger the reset event callback.
audioPlayer.reset();// Call the reset() API and trigger the 'reset' event callback.
});
audioPlayer.on('reset',()=>{// Set the reset event callback.
audioPlayer.on('reset',()=>{// Set the 'reset' event callback.
console.info('audio play success');
if(!this.isNextMusic){// When isNextMusic is false, changing songs is implemented.
this.nextMusic(audioPlayer);// Changing songs is implemented.
...
...
@@ -193,7 +193,7 @@ export class AudioDemo {
}).catch((err)=>{
console.info('open fd failed err is'+err);
});
audioPlayer.src=nextFdPath;// Set the src attribute and trigger the dataLoad event callback.
audioPlayer.src=nextFdPath;// Set the src attribute and trigger the 'dataLoad' event callback.
}
asyncaudioPlayerDemo(){
...
...
@@ -210,7 +210,7 @@ export class AudioDemo {
}).catch((err)=>{
console.info('open fd failed err is'+err);
});
audioPlayer.src=fdPath;// Set the src attribute and trigger the dataLoad event callback.
audioPlayer.src=fdPath;// Set the src attribute and trigger the 'dataLoad' event callback.
}
}
```
...
...
@@ -223,12 +223,12 @@ import fileIO from '@ohos.fileio'
exportclassAudioDemo{
// Set the player callbacks.
setCallBack(audioPlayer){
audioPlayer.on('dataLoad',()=>{// Set the dataLoad event callback, which is triggered when the src attribute is set successfully.
audioPlayer.on('dataLoad',()=>{// Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
audioPlayer.loop=true;// Set the loop playback attribute.
audioPlayer.play();// Call the play() API to start the playback and trigger the play event callback.
audioPlayer.play();// Call the play() API to start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play',()=>{// Sets the play event callback to start loop playback.
audioPlayer.on('play',()=>{// Set the 'play' event callback to start loop playback.
console.info('audio play success');
});
}
...
...
@@ -247,7 +247,7 @@ export class AudioDemo {
}).catch((err)=>{
console.info('open fd failed err is'+err);
});
audioPlayer.src=fdPath;// Set the src attribute and trigger the dataLoad event callback.
audioPlayer.src=fdPath;// Set the src attribute and trigger the 'dataLoad' event callback.
}
}
```
...
...
@@ -257,7 +257,6 @@ export class AudioDemo {
The following samples are provided to help you better understand how to develop audio playback:
-[`JsDistributedMusicPlayer`: Distributed Music Player (JS, API version 7)](https://gitee.com/openharmony/app_samples/tree/master/ability/JsDistributedMusicPlayer)
-[`JsAudioPlayer`: Audio Playback and Management (JS, API version 7)](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer)
-[`JsAudioPlayer`: Audio Playback and Management (JS, API version 8)](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer)
-[`eTsAudioPlayer`: Audio Player (eTS)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets)
| src | string | Yes | Yes | Audio media URI. The mainstream audio formats (MPEG-4, AAC, MPEG-3, OGG, and WAV) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xx<br><br>2. HTTP network playback: http://xx<br>3. HLS network playback path (under development)<br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.|
| src | string | Yes | Yes | Audio media URI. The mainstream audio formats (MPEG-4, AAC, MPEG-3, OGG, and WAV) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xx<br><br>2. HTTP network playback: http://xx<br>3. HTTPS network playback: https://xx<br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.|
| loop | boolean | Yes | Yes | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite. |
| currentTime | number | Yes | No | Current audio playback position. |
| duration | number | Yes | No | Audio duration. |
...
...
@@ -501,7 +501,7 @@ Subscribes to the audio buffering update event.
| type | string | Yes | Type of the event to subscribe to, which is 'bufferingUpdate' in this example. |
| type | string | Yes | Event type, which is 'bufferingUpdate' in this case. |
| callback | function | Yes | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|
**Example**
...
...
@@ -525,7 +525,7 @@ Subscribes to the audio playback events.
| type | string | Yes | Type of the event to subscribe to. The following events are supported: 'play' \| 'pause' \| 'stop' \| 'reset' \| 'dataLoad' \| 'finish' \| 'volumeChange'<br>- The 'play' event is triggered when the [play()](#audioplayer_play) API is called and audio playback starts.<br>- The 'pause' event is triggered when the [pause()](#audioplayer_pause) API is called and audio playback is paused.<br>- The 'stop' event is triggered when the [stop()](#audioplayer_stop) API is called and audio playback stops.<br>- The 'reset' event is triggered when the [reset()](#audioplayer_reset) API is called and audio playback is reset.<br>- The 'dataLoad' event is triggered when the audio data is loaded, that is, when the **src** attribute is configured.<br>- The 'finish' event is triggered when the audio playback is finished.<br>- The 'volumeChange' event is triggered when the [setVolume()](#audioplayer_setvolume) API is called and the playback volume is changed.|
| type | string | Yes | Event type. The following events are supported:<br>- 'play': triggered when the [play()](#audioplayer_play) API is called and audio playback starts.<br>- 'pause': triggered when the [pause()](#audioplayer_pause) API is called and audio playback is paused.<br>- 'stop': triggered when the [stop()](#audioplayer_stop) API is called and audio playback stops.<br>- 'reset': triggered when the [reset()](#audioplayer_reset) API is called and audio playback is reset.<br>- 'dataLoad': triggered when the audio data is loaded, that is, when the **src** attribute is configured.<br>- 'finish': triggered when the audio playback is finished.<br>- 'volumeChange': triggered when the [setVolume()](#audioplayer_setvolume) API is called and the playback volume is changed. |
| callback | () => void | Yes | Callback invoked when the event is triggered. |
**Example**
...
...
@@ -598,7 +598,7 @@ Subscribes to the 'timeUpdate' event.
| type | string | Yes | Type of the event to subscribe to, which is 'timeUpdate' in this API.<br>The 'timeUpdate' event is triggered when the [seek()](#audioplayer_seek) API is called.|
| type | string | Yes | Event type, which is 'timeUpdate' in this case.<br>The 'timeUpdate' event is triggered when the [seek()](#audioplayer_seek) API is called.|
| callback | Callback\<number> | Yes | Callback invoked when the event is triggered. The input parameter of the callback is the time when the seek operation is successful. |
**Example**
...
...
@@ -626,7 +626,7 @@ Subscribes to the audio playback error event.
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this API.<br>The 'error' event is triggered when an error occurs during audio playback.|
| type | string | Yes | Event type, which is 'error' in this case.<br>The 'error' event is triggered when an error occurs during audio playback.|
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
**Example**
...
...
@@ -656,7 +656,7 @@ Enumerates the audio playback states. You can obtain the state through the **sta
## VideoPlayer<sup>8+</sup>
Provides APIs to manage and play video. Before calling an API of the **VideoPlayer** class, you must call [createVideoPlayer()](#mediacreatevideoplayer8) to create a [VideoPlayer](#videoplayer8) instance.
Provides APIs to manage and play video. Before calling an API of **VideoPlayer**, you must call [createVideoPlayer()](#mediacreatevideoplayer8) to create a [VideoPlayer](#videoplayer8) instance.
For details about the video playback demo, see [Video Playback Development](../../media/video-playback.md).
...
...
@@ -666,7 +666,7 @@ For details about the video playback demo, see [Video Playback Development](../.
| url<sup>8+</sup> | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xx<br><br>2. HTTP network playback: http://xx<br>3. HLS network playback path (under development)<br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.|
| url<sup>8+</sup> | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xx<br><br>2. HTTP network playback: http://xx<br>3. HTTPS network playback: https://xx<br>3. HLS network playback: http://xx or https://xx<br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.|
| loop<sup>8+</sup> | boolean | Yes | Yes | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite. |
| currentTime<sup>8+</sup> | number | Yes | No | Current video playback position. |
| duration<sup>8+</sup> | number | Yes | No | Video duration. The value **-1** indicates the live streaming mode. |
...
...
@@ -1003,7 +1003,8 @@ Seeks to the specified playback position. The next key frame at the specified po
**Example**
```js
videoPlayer.seek((seekTime,err)=>{
letseekTime=5000;
videoPlayer.seek(seekTime,(err,result)=>{
if(typeof(err)=='undefined'){
console.info('seek success!');
}else{
...
...
@@ -1031,7 +1032,10 @@ Seeks to the specified playback position. This API uses a callback to return the
Selects a bit rate from available bit rates. This API uses a callback to return the result. The available bit rates can be obtained by calling [availableBitrateCollected](#on('availableBitrateCollected')<sup>9+</sup>).
| bitrate | number | Yes | Bit rate to select, which is used in the HLS multi-bit rate scenario. The unit is bit/s. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the set value is returned, the operation is successful; otherwise, the operation fails.|
**Example**
```js
letbitrate=1024000;
videoPlayer.selectBitrate(bitrate,(err,result)=>{
if(typeof(err)=='undefined'){
console.info('selectBitrate success!');
}else{
console.info('selectBitrate fail!');
}
});
```
### selectBitrate<sup>9+</sup>
selectBitrate(bitrate:number): Promise\<number>
Selects a bit rate from available bit rates. This API uses a promise to return the result. The available bit rates can be obtained by calling [availableBitrateCollected](#on('availableBitrateCollected')<sup>9+</sup>).
| type | string | Yes | Type of the event to subscribe to, which is 'bufferingUpdate' in this example. |
| type | string | Yes | Event type, which is 'bufferingUpdate' in this case. |
| callback | function | Yes | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|
**Example**
...
...
@@ -1376,7 +1448,7 @@ Subscribes to the frame rendering start event.
| type | string | Yes | Type of the event to subscribe to, which is 'videoSizeChanged' in this example.|
| type | string | Yes | Event type, which is 'videoSizeChanged' in this case.|
| callback | function | Yes | Callback invoked when the event is triggered. **width** indicates the video width, and **height** indicates the video height. |
**Example**
...
...
@@ -1423,7 +1495,7 @@ Subscribes to the video playback error event.
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this API.<br>The 'error' event is triggered when an error occurs during video playback.|
| type | string | Yes | Event type, which is 'error' in this case.<br>The 'error' event is triggered when an error occurs during video playback.|
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
**Example**
...
...
@@ -1437,6 +1509,31 @@ videoPlayer.on('error', (error) => { // Set the 'error' event callback.
videoPlayer.setVolume(3);// Set volume to an invalid value to trigger the 'error' event.
Implements audio recording. Before calling an API of the **AudioRecorder** class, you must call [createAudioRecorder()](#mediacreateaudiorecorder) to create an [AudioRecorder](#audiorecorder) instance.
Implements audio recording. Before calling an API of **AudioRecorder**, you must call [createAudioRecorder()](#mediacreateaudiorecorder) to create an [AudioRecorder](#audiorecorder) instance.
For details about the audio recording demo, see [Audio Recording Development](../../media/audio-recorder.md).
| config | [AudioRecorderConfig](#audiorecorderconfig) | Yes | Audio recording parameters, including the audio output URI, [encoding format](#audioencoder), sampling rate, number of audio channels, and [output format](#audiooutputformat).|
| config | [AudioRecorderConfig](#audiorecorderconfig) | Yes | Audio recording parameters, including the audio output URI, encoding format, sampling rate, number of audio channels, and output format.|
**Example**
...
...
@@ -1668,7 +1765,7 @@ Subscribes to the audio recording events.
| type | string | Yes | Type of the event to subscribe to. The following events are supported: 'prepare'\|'start'\| 'pause' \| 'resume' \|'stop'\|'release'\|'reset'<br>- The 'prepare' event is triggered when the [prepare](#audiorecorder_prepare) API is called and the audio recording parameters are set.<br>- The 'start' event is triggered when the [start](#audiorecorder_start) API is called and audio recording starts.<br>- The 'pause' event is triggered when the [pause](#audiorecorder_pause) API is called and audio recording is paused.<br>- The 'resume' event is triggered when the [resume](#audiorecorder_resume) API is called and audio recording is resumed.<br>- The 'stop' event is triggered when the [stop](#audiorecorder_stop) API is called and audio recording stops.<br>- The 'release' event is triggered when the [release](#audiorecorder_release) API is called and the recording resource is released.<br>- The 'reset' event is triggered when the [reset](#audiorecorder_reset) API is called and audio recording is reset.|
| type | string | Yes | Event type. The following events are supported: 'prepare'\|'start'\| 'pause' \| 'resume' \|'stop'\|'release'\|'reset'<br>- The 'prepare' event is triggered when the [prepare](#audiorecorder_prepare) API is called and the audio recording parameters are set.<br>- The 'start' event is triggered when the [start](#audiorecorder_start) API is called and audio recording starts.<br>- The 'pause' event is triggered when the [pause](#audiorecorder_pause) API is called and audio recording is paused.<br>- The 'resume' event is triggered when the [resume](#audiorecorder_resume) API is called and audio recording is resumed.<br>- The 'stop' event is triggered when the [stop](#audiorecorder_stop) API is called and audio recording stops.<br>- The 'release' event is triggered when the [release](#audiorecorder_release) API is called and the recording resource is released.<br>- The 'reset' event is triggered when the [reset](#audiorecorder_reset) API is called and audio recording is reset.|
| callback | ()=>void | Yes | Callback invoked when the event is triggered. |
**Example**
...
...
@@ -1726,7 +1823,7 @@ Subscribes to the audio recording error event.
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this API.<br>The 'error' event is triggered when an error occurs during audio recording.|
| type | string | Yes | Event type, which is 'error' in this case.<br>The 'error' event is triggered when an error occurs during audio recording.|
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
| audioEncoder | [AudioEncoder](#audioencoder) | No | Audio encoding format. The default value is **AAC_LC**. |
| audioEncoder<sup>(deprecated)</sup> | [AudioEncoder](#audioencoder) | No | Audio encoding format. The default value is **AAC_LC**.<br>**Note**: This parameter is deprecated since API version 8. Use **audioEncoderMime** instead. |
| audioEncodeBitRate | number | No | Audio encoding bit rate. The default value is **48000**. |
| audioSampleRate | number | No | Audio sampling rate. The default value is **48000**. |
| numberOfChannels | number | No | Number of audio channels. The default value is **2**. |
| format | [AudioOutputFormat](#audiooutputformat) | No | Audio output format. The default value is **MPEG_4**. |
| format<sup>(deprecated)</sup> | [AudioOutputFormat](#audiooutputformat) | No | Audio output format. The default value is **MPEG_4**.<br>**Note**: This parameter is deprecated since API version 8. Use **fileFormat** instead. |
| location | [Location](#location) | No | Geographical location of the recorded audio. |
| uri | string | Yes | Audio output URI. Supported: fd://xx (fd number)<br><br>The file must be created by the caller and granted with proper permissions.|
| uri | string | Yes | Audio output URI. Supported: fd://xx (fd number)<br><br>The file must be created by the caller and granted with proper permissions.|
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this API.<br>The 'error' event is triggered when an error occurs during video recording.|
| type | string | Yes | Event type, which is 'error' in this case.<br>The 'error' event is triggered when an error occurs during video recording.|
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
**Example**
...
...
@@ -2388,7 +2485,7 @@ Describes the video recording parameters.
| rotation | number | No | Rotation angle of the recorded video. |
| location | [Location](#location) | No | Geographical location of the recorded video. |
| url | string | Yes | Video output URL. Supported: fd://xx (fd number)<br><br>The file must be created by the caller and granted with proper permissions.|
| url | string | Yes | Video output URL. Supported: fd://xx (fd number)<br><br>The file must be created by the caller and granted with proper permissions.|