diff --git a/en/application-dev/reference/apis/js-apis-media.md b/en/application-dev/reference/apis/js-apis-media.md index ef8c4857425a7dbd611eb3cd0a9ac7bcb2be6075..96b190f1f7f9166c68ef1fda64bb9a98bf6b269d 100644 --- a/en/application-dev/reference/apis/js-apis-media.md +++ b/en/application-dev/reference/apis/js-apis-media.md @@ -277,10 +277,10 @@ For details about the audio playback demo, see [Audio Playback Development](../. | Name | Type | Readable| Writable| Description | | ------------------------------- | ----------------------------------- | ---- | ---- | ------------------------------------------------------------ | -| src | string | Yes | Yes | Audio file URI. The mainstream audio formats (M4A, AAC, MPEG-3, OGG, and WAV) are supported.
**Examples of supported URI schemes**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.INTERNET (The latter is required only when online resources are used.)| -| fdSrc9+ | [AVFileDescriptor](#interruptmode9) | Yes | Yes | Description of the audio file. This attribute is required when audio resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Music 1 (address offset: 0, byte length: 100)
Music 2 (address offset: 101; byte length: 50)
Music 3 (address offset: 151, byte length: 150)
1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
If the file is an independent music file, use **src=fd://xx**.

**Required permissions**: ohos.permission.READ_MEDIA| +| src | string | Yes | Yes | Audio file URI. The mainstream audio formats (M4A, AAC, MPEG-3, OGG, and WAV) are supported.
**Examples of supported URI schemes**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.INTERNET| +| fdSrc9+ | [AVFileDescriptor](#avfiledescriptor9) | Yes | Yes | Description of the audio file. This attribute is required when audio resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Music 1 (address offset: 0, byte length: 100)
Music 2 (address offset: 101; byte length: 50)
Music 3 (address offset: 151, byte length: 150)
1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
If the file is an independent music file, use **src=fd://xx**.
| | loop | boolean | Yes | Yes | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite. | -| audioInterruptMode9+ | [InterruptMode](#interruptmode9) | Yes | Yes | Audio interruption mode. | +| audioInterruptMode9+ | [audio.InterruptMode](js-apis-audio.md#interruptmode9) | Yes | Yes | Audio interruption mode. | | currentTime | number | Yes | No | Current audio playback position, in ms. | | duration | number | Yes | No | Audio duration, in ms. | | state | [AudioState](#audiostate) | Yes | No | Audio playback state. This state cannot be used as the condition for triggering the call of **play()**, **pause()**, or **stop()**.| @@ -442,7 +442,7 @@ function printfDescription(obj) { } } -audioPlayer.getTrackDescription((error, arrlist) => { +audioPlayer.getTrackDescription((error, ) => { if (arrlist != null) { for (let i = 0; i < arrlist.length; i++) { printfDescription(arrlist[i]); @@ -477,7 +477,7 @@ function printfDescription(obj) { console.info('audio value is ' + property); } } - +let arrayDescription = null audioPlayer.getTrackDescription().then((arrlist) => { if (arrlist != null) { arrayDescription = arrlist; @@ -535,6 +535,8 @@ Subscribes to the audio playback events. **Example** ```js +import fileio from '@ohos.fileio' + let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance. audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully. console.info('audio set source success'); @@ -574,11 +576,11 @@ audioPlayer.on('error', (error) => { // Set the 'error' event callback }); // Set the FD (local playback) of the video file selected by the user. -let fdPath = 'fd://' +let fdPath = 'fd://'; // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" command. let path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; +fileio.open(path).then((fdValue) => { + fdPath = fdPath + '' + fdValue; console.info('open fd success fd is' + fdPath); }, (err) => { console.info('open fd failed err is' + err); @@ -646,21 +648,19 @@ Enumerates the audio playback states. You can obtain the state through the **sta **System capability**: SystemCapability.Multimedia.Media.AudioPlayer -| Name | Type | Description | -| ------------------ | ------ | ---------------------------------------------- | -| idle | string | No audio playback is in progress. The audio player is in this state after the **'dataload'** or **'reset'** event is triggered.| -| playing | string | Audio playback is in progress. The audio player is in this state after the **'play'** event is triggered. | -| paused | string | Audio playback is paused. The audio player is in this state after the **'pause'** event is triggered. | -| stopped | string | Audio playback is stopped. The audio player is in this state after the **'stop'** event is triggered. | -| error8+ | string | Audio playback is in the error state. | +| Name | Type | Description | +| ------- | ------ | ---------------------------------------------- | +| idle | string | No audio playback is in progress. The audio player is in this state after the **'dataload'** or **'reset'** event is triggered.| +| playing | string | Audio playback is in progress. The audio player is in this state after the **'play'** event is triggered. | +| paused | string | Audio playback is paused. The audio player is in this state after the **'pause'** event is triggered. | +| stopped | string | Audio playback is stopped. The audio player is in this state after the **'stop'** event is triggered. | +| error | string | Audio playback is in the error state. | ## AVFileDescriptor9+ Describes audio and video file resources. It is used to specify a particular resource for playback based on its offset and length within a file. -**System capability**: SystemCapability.Multimedia.Media.AudioPlayer - -**Parameters** +**System capability**: SystemCapability.Multimedia.Media.Core | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | @@ -668,17 +668,6 @@ Describes audio and video file resources. It is used to specify a particular res | offset | number | Yes | Resource offset, which needs to be entered based on the preset resource information. An invalid value causes a failure to parse audio and video resources.| | length | number | Yes | Resource length, which needs to be entered based on the preset resource information. An invalid value causes a failure to parse audio and video resources.| -## InterruptMode9+ - -Describes the audio interruption mode. - -**System capability**: SystemCapability.Multimedia.Media.AudioPlayer - -| Name | Default Value| Description | -| ---------------------------- | ------ | ---------- | -| SHARE_MODE | 0 | Shared mode.| -| INDEPENDENT_MODE| 1 | Independent mode. | - ## VideoPlayer8+ Provides APIs to manage and play video. Before calling an API of **VideoPlayer**, you must call [createVideoPlayer()](#mediacreatevideoplayer8) to create a [VideoPlayer](#videoplayer8) instance. @@ -691,11 +680,11 @@ For details about the video playback demo, see [Video Playback Development](../. | Name | Type | Readable| Writable| Description | | ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ | -| url8+ | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.
**Example of supported URIs**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.INTERNET (The latter is required only when online resources are used.)| -| fdSrc9+ | [AVFileDescriptor](#interruptmode9) | Yes| Yes| Description of a video file. This attribute is required when video resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Video 1 (address offset: 0, byte length: 100)
Video 2 (address offset: 101; byte length: 50)
Video 3 (address offset: 151, byte length: 150)
1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
To play an independent video file, use **src=fd://xx**.
**Note**:
**Required permissions**: ohos.permission.READ_MEDIA| +| url8+ | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.
**Example of supported URIs**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
**Required permissions**: ohos.permission.INTERNET| +| fdSrc9+ | [AVFileDescriptor](#avfiledescriptor9) | Yes| Yes| Description of a video file. This attribute is required when video resources of an application are continuously stored in a file.
**Example:**
Assume that a music file that stores continuous music resources consists of the following:
Video 1 (address offset: 0, byte length: 100)
Video 2 (address offset: 101; byte length: 50)
Video 3 (address offset: 151, byte length: 150)
1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
To play an independent video file, use **src=fd://xx**.
| | loop8+ | boolean | Yes | Yes | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite. | | videoScaleType9+ | [VideoScaleType](#videoscaletype9) | Yes | Yes | Video scale type. | -| audioInterruptMode9+ | [InterruptMode](#interruptmode9) | Yes | Yes | Audio interruption mode. | +| audioInterruptMode9+ | [audio.InterruptMode](js-apis-audio.md#interruptmode9) | Yes | Yes | Audio interruption mode. | | currentTime8+ | number | Yes | No | Current video playback position, in ms. | | duration8+ | number | Yes | No | Video duration, in ms. The value **-1** indicates the live mode. | | state8+ | [VideoPlayState](#videoplaystate8) | Yes | No | Video playback state. | @@ -722,6 +711,7 @@ Sets **SurfaceId**. This API uses an asynchronous callback to return the result. **Example** ```js +let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId, (err) => { if (err == null) { console.info('setDisplaySurface success!'); @@ -756,6 +746,7 @@ Sets **SurfaceId**. This API uses a promise to return the result. **Example** ```js +let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId).then(() => { console.info('setDisplaySurface success'); }).catch((error) => { @@ -1062,8 +1053,7 @@ Seeks to the specified playback position. This API uses an asynchronous callback ```js import media from '@ohos.multimedia.media' let seekTime = 5000; -let seekMode = media.SeekMode.SEEK_NEXT_SYNC; -videoPlayer.seek(seekTime, seekMode, (err, result) => { +videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err, result) => { if (err == null) { console.info('seek success!'); } else { @@ -1096,6 +1086,7 @@ Seeks to the specified playback position. If **mode** is not specified, the next **Example** ```js +import media from '@ohos.multimedia.media' let seekTime = 5000; videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete. console.info('seek success'); @@ -1103,7 +1094,7 @@ videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates th console.info(`video catchCallback, error:${error}`); }); -videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { +videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => { console.info('seek success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1162,7 +1153,7 @@ Sets the volume. This API uses a promise to return the result. ```js let vol = 0.5; -videoPlayer.setVolume(vol).then() => { +videoPlayer.setVolume(vol).then(() => { console.info('setVolume success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1212,7 +1203,7 @@ Releases the video playback resource. This API uses a promise to return the resu **Example** ```js -videoPlayer.release().then() => { +videoPlayer.release().then(() => { console.info('release success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1245,7 +1236,7 @@ function printfDescription(obj) { } videoPlayer.getTrackDescription((error, arrlist) => { - if (arrlist) != null) { + if ((arrlist) != null) { for (let i = 0; i < arrlist.length; i++) { printfDescription(arrlist[i]); } @@ -1351,7 +1342,7 @@ Sets the video playback speed. This API uses a promise to return the result. import media from '@ohos.multimedia.media' let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; -videoPlayer.setSpeed(speed).then() => { +videoPlayer.setSpeed(speed).then(() => { console.info('setSpeed success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1410,7 +1401,7 @@ Selects a bit rate from available ones, which can be obtained by calling [availa ```js let bitrate = 1024000; -videoPlayer.selectBitrate(bitrate).then() => { +videoPlayer.selectBitrate(bitrate).then(() => { console.info('selectBitrate success'); }).catch((error) => { console.info(`video catchCallback, error:${error}`); @@ -1613,30 +1604,24 @@ Enumerates the video scale modes. ## MediaDescription8+ -### [key : string] : Object - Defines media information in key-value mode. **System capability**: SystemCapability.Multimedia.Media.Core -| Name | Type | Description | -| ----- | ------ | ------------------------------------------------------------ | -| key | string | Key of the media information. For details about the keys, see [MediaDescriptionKey](#mediadescriptionkey8).| -| value | any | Value of the key. For details about the values, see [MediaDescriptionKey](#mediadescriptionkey8).| - **Example** ```js +import media from '@ohos.multimedia.media' function printfItemDescription(obj, key) { let property = obj[key]; - console.info('audio key is ' + key); - console.info('audio value is ' + property); + console.info('audio key is ' + key); // Specify a key. For details about the keys, see [MediaDescriptionKey]. + console.info('audio value is ' + property); // Obtain the value of the key. The value can be any type. For details about the types, see [MediaDescriptionKey]. } - +let audioPlayer = media.createAudioPlayer(); audioPlayer.getTrackDescription((error, arrlist) => { if (arrlist != null) { for (let i = 0; i < arrlist.length; i++) { - printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track. + printfItemDescription(arrlist[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track. } } else { console.log(`audio getTrackDescription fail, error:${error}`); @@ -1808,7 +1793,7 @@ Subscribes to the audio recording events. **Example** ```js -let audiorecorder = media.createAudioRecorder(); // Create an AudioRecorder instance. +let audioRecorder = media.createAudioRecorder(); // Create an AudioRecorder instance. let audioRecorderConfig = { audioEncoder : media.AudioEncoder.AAC_LC, , audioEncodeBitRate : 22050, @@ -1864,10 +1849,19 @@ Subscribes to audio recording error events. After an error event is reported, yo **Example** ```js +let audioRecorderConfig = { + audioEncoder : media.AudioEncoder.AAC_LC, , + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + location : { latitude : 30, longitude : 130}, +} audioRecorder.on('error', (error) => { // Set the 'error' event callback. console.info(`audio error called, error: ${error}`); }); -audioRecorder.prepare(); // Do no set any parameter in prepare and trigger the 'error' event callback. +audioRecorder.prepare(audioRecorderConfig); // Do no set any parameter in prepare and trigger the 'error' event callback. ``` ## AudioRecorderConfig @@ -2058,18 +2052,17 @@ media.createVideoRecorder().then((recorder) => { if (recorder != null) { videoRecorder = recorder; console.info('createVideoRecorder success'); + videoRecorder.prepare(videoConfig).then(() => { + console.info('prepare success'); + }).catch((err) => { + console.info('prepare failed and catch error is ' + err.message); + }); } else { console.info('createVideoRecorder failed'); } }).catch((err) => { console.info('catch err error message is ' + err.message); }); - -videoRecorder.prepare(videoConfig).then(() => { - console.info('prepare success'); -}).catch((err) => { - console.info('prepare failed and catch error is ' + err.message); -}); ``` ### getInputSurface9+ @@ -2484,7 +2477,9 @@ Subscribes to video recording error events. After an error event is reported, yo ```js videoRecorder.on('error', (error) => { // Set the 'error' event callback. console.info(`audio error called, error: ${error}`); +} // This event is reported when an error occurs during the retrieval of videoRecordState. +}); ``` ## VideoRecordState9+ @@ -2515,7 +2510,7 @@ Describes the video recording parameters. | profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. | | 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)
![](figures/en-us_image_url.png)
**Required permissions**: ohos.permission.READ_MEDIA| +| url | string | Yes | Video output URL. Supported: fd://xx (fd number)
![](figures/en-us_image_url.png) | ## AudioSourceType9+