@@ -22,32 +22,43 @@ For details about the APIs, see [AudioPlayer in the Media API](../reference/apis
The full audio playback process includes creating an instance, setting the URI, playing audio, seeking to the playback position, setting the volume, pausing playback, obtaining track information, stopping playback, resetting the player, and releasing resources.
For details about the **src**media source input types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
For details about the **src** types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
```js
importmediafrom'@ohos.multimedia.media'
importfileIOfrom'@ohos.fileio'
functionSetCallBack(audioPlayer){
// Print the stream track information.
functionprintfDescription(obj){
for(letiteminobj){
letproperty=obj[item];
console.info('audio key is '+item);
console.info('audio value is '+property);
}
}
// Set the player callbacks.
functionsetCallBack(audioPlayer){
audioPlayer.on('dataLoad',()=>{// Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
// The playback page is ready. You can click the Play button to start the playback.
audioPlayer.play();// The play() API can be invoked only after the 'dataLoad' event callback is complete. The 'play' event callback is then triggered.
});
audioPlayer.on('play',()=>{// Set the 'play' event callback.
console.info('audio play success');
// The Play button is changed to the pausable state.
audioPlayer.pause();// Trigger the 'pause' event callback and pause the playback.
});
audioPlayer.on('pause',()=>{// Set the 'pause' event callback.
console.info('audio pause success');
// The Play button is changed to the playable state.
audioPlayer.seek(5000);// Trigger the 'timeUpdate' event callback, and seek to 5000 ms for playback.
});
audioPlayer.on('stop',()=>{// Set the 'stop' event callback.
console.info('audio stop success');
// The playback stops, the playback progress bar returns to 0, and the Play button is changed to the playable state.
audioPlayer.reset();// Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song.
});
audioPlayer.on('reset',()=>{// Set the 'reset' event callback.
console.info('audio reset success');
// You can reconfigure the src attribute to play another audio file.
audioPlayer.release();// Release the AudioPlayer resources.
audioPlayer=undefined;
});
audioPlayer.on('timeUpdate',(seekDoneTime)=>{// Set the 'timeUpdate' event callback.
if(typeof(seekDoneTime)=='undefined'){
...
...
@@ -55,11 +66,20 @@ function SetCallBack(audioPlayer) {
return;
}
console.info('audio seek success, and seek time is '+seekDoneTime);
// The playback progress bar is updated to the seek position.
audioPlayer.setVolume(0.5);// Trigger the 'volumeChange' event callback.
});
audioPlayer.on('volumeChange',()=>{// Set the 'volumeChange' event callback.
console.info('audio volumeChange success');
// Display the updated volume.
audioPlayer.getTrackDescription((error,arrlist)=>{// Obtain the audio track information in callback mode.
setCallBack(audioPlayer);// Set the event callbacks.
// 2. Set the URI of the audio file selected by the user.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
letaudioPlayer=media.createAudioPlayer();// Create an AudioPlayer instance.
this.setCallBack(audioPlayer);// Set the event callbacks.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\02.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
letaudioPlayer=media.createAudioPlayer();// Create an AudioPlayer instance.
this.setCallBack(audioPlayer);// Set the event callbacks.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
letaudioPlayer=media.createAudioPlayer();// Create an AudioPlayer instance.
this.setCallBack(audioPlayer);// Set the event callbacks.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" command.
audioPlayer.src=fdPath;// Set the src attribute and trigger the 'dataLoad' event callback.
audioPlayer.loop=true;// Set the loop playback attribute.
});
audioPlayer.src=fdPath;// Set the src attribute and trigger the 'dataLoad' event callback.
}
}
```
## Samples
...
...
@@ -263,7 +257,6 @@ audioPlayer.loop = true; // Set the loop playback att
The following samples are provided to help you better understand how to develop audio playback:
-[`JsDistributedMusicPlayer`: Distributed Music Player (JS) (API7)](https://gitee.com/openharmony/app_samples/tree/master/ability/JsDistributedMusicPlayer)
-[`JsAudioPlayer`: Audio Playback and Management (JS) (API7)](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer)
-[`JsAudioPlayer`: Audio Playback and Management (JS, API 7)](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)
privatetestFdNumber;// Used to save the FD address.
lettestFdNumber;
functionSetCallBack(audioRecorder){
// Set the callbacks related to audio recording.
setCallBack(audioRecorder){
audioRecorder.on('prepare',()=>{// Set the 'prepare' event callback.
console.log('prepare success');
// The recording page is ready. You can click the Record button to start recording.
audioRecorder.start();// Call the start API to start recording and trigger the 'start' event callback.
});
audioRecorder.on('start',()=>{// Set the 'start' event callback.
console.log('audio recorder start success');
// The Record button is changed to the pausable state.
audioRecorder.pause();// Call the pause API to pause recording and trigger the 'pause' event callback.
});
audioRecorder.on('pause',()=>{// Set the 'pause' event callback.
console.log('audio recorder pause success');
// The Record button is changed to the recordable state.
audioRecorder.resume();// Call the resume API to resume recording and trigger the 'resume' event callback.
});
audioRecorder.on('resume',()=>{// Set the 'resume' event callback.
console.log('audio recorder resume success');
// The Record button is changed to the pausable state.
audioRecorder.stop();// Call the stop API to stop recording and trigger the 'stop' event callback.
});
audioRecorder.on('stop',()=>{// Set the 'stop' event callback.
console.log('audio recorder stop success');
});
audioRecorder.on('release',()=>{// Set the 'release' event callback.
console.log('audio recorder release success');
audioRecorder.reset();// Call the reset API to reset the recorder and trigger the 'reset' event callback.
});
audioRecorder.on('reset',()=>{// Set the 'reset' event callback.
console.log('audio recorder reset success');
// You need to reset the recording parameters for another recording.
audioRecorder.release();// Call the release API to release resources and trigger the 'release' event callback.
});
audioRecorder.on('release',()=>{// Set the 'release' event callback.
console.log('audio recorder release success');
audioRecorder=undefined;
});
audioRecorder.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}`);
});
}
}
// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
asyncfunctiongetFd(pathName){
// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Video/01.mp3.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
asyncgetFd(pathName){
letdisplayName=pathName;
constmediaTest=mediaLibrary.getMediaLibrary();
letfileKeyObj=mediaLibrary.FileKey;
...
...
@@ -80,41 +83,29 @@ async function getFd(pathName) {
privatetestFdNumber;// Used to save the FD address.
lettestFdNumber;
functionSetCallBack(audioRecorder){
// Set the callbacks related to audio recording.
setCallBack(audioRecorder){
audioRecorder.on('prepare',()=>{// Set the 'prepare' event callback.
console.log('prepare success');
// The recording page is ready. You can click the Record button to start recording.
audioRecorder.start();// Call the start API to start recording and trigger the 'start' event callback.
});
audioRecorder.on('start',()=>{// Set the 'start' event callback.
console.log('audio recorder start success');
// The Record button is changed to the pausable state.
audioRecorder.stop();// Call the stop API to stop recording and trigger the 'stop' event callback.
});
audioRecorder.on('stop',()=>{// Set the 'stop' event callback.
console.log('audio recorder stop success');
audioRecorder.release();// Call the release API to release resources and trigger the 'release' event callback.
});
audioRecorder.on('release',()=>{// Set the 'release' event callback.
console.log('audio recorder release success');
audioRecorder=undefined;
});
}
audioRecorder.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}`);
});
}
// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
asyncfunctiongetFd(pathName){
// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Video/01.mp3.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
asyncgetFd(pathName){
letdisplayName=pathName;
constmediaTest=mediaLibrary.getMediaLibrary();
letfileKeyObj=mediaLibrary.FileKey;
...
...
@@ -162,33 +161,35 @@ async function getFd(pathName) {
awaitthis.getFd('01.mp3');// Call the getFd method to obtain the FD address of the file to be recorded.
// 3. Set the recording parameters.
letaudioRecorderConfig={
audioEncodeBitRate:22050,
audioSampleRate:22050,
numberOfChannels:2,
format:media.AudioOutputFormat.AAC_ADTS,
uri:testFdNumber,// testFdNumber is generated by getFd.
uri:this.testFdNumber,// testFdNumber is generated by getFd.
location:{latitude:30,longitude:130},
audioEncoderMime:media.CodecMimeType.AUDIO_AAC,
fileFormat:media.ContainerFormatType.CFT_MPEG_4A,
}
audioRecorder.prepare(audioRecorderConfig);// Call the prepare method to trigger the 'prepare' event callback.
}
}
audioRecorder.prepare(audioRecorderConfig)
// 4. Start recording.
audioRecorder.start();// The start API can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete.
// 5. Stop recording.
audioRecorder.stop();// The stop API can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
// 6. Release resources.
audioRecorder.release();// The AudioRecorder resource is destroyed.
audioRecorder=undefined;
```
## Samples
The following samples are provided to help you better understand how to develop audio recording:
-[`Recorder`: Recorder (eTS, API 8)](https://gitee.com/openharmony/app_samples/tree/master/media/Recorder)
-[`eTsAudioPlayer`: Audio Player (eTS)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets)
You can use video playback APIs to convert video data into visible signals, play the signals using output devices, and manage playback tasks. This document describes the following video playback development scenarios: full-process, normal playback, video switching, and loop playback.
You can use video playback APIs to convert video data into visible signals, play the signals using output devices, and manage playback tasks. This document describes development for the following video playback scenarios: full-process, normal playback, video switching, and loop playback.
**Figure 1** Video playback state transition
...
...
@@ -22,11 +22,11 @@ Note: Video playback requires hardware capabilities such as display, audio, and
## Compatibility
You are advised to use the mainstream playback formats and resolutions, rather than custom or abnormal streams to avoid playback failure, frame freezing, and artifacts. The system is not affected by incompatibility issues. If such an error occurs, you can exit stream playback mode.
Use the mainstream playback formats and resolutions, rather than custom ones to avoid playback failures, frame freezing, and artifacts. The system is not affected by incompatibility issues. If such an issue occurs, you can exit stream playback mode.
The table below lists the mainstream playback formats and resolutions.
| Video Container Specification| Specification Description | Resolution |
| Video Container Format| Description | Resolution |
| mp4 | Video format: H.264/MPEG-2/MPEG-4/H.263; audio format: AAC/MP3| Mainstream resolutions, such as 1080p, 720p, 480p, and 270p|
| mkv | Video format: H.264/MPEG-2/MPEG-4/H.263; audio format: AAC/MP3| Mainstream resolutions, such as 1080p, 720p, 480p, and 270p|
...
...
@@ -41,143 +41,137 @@ For details about the APIs, see [VideoPlayer in the Media API](../reference/apis
The full video playback process includes creating an instance, setting the URL, setting the surface ID, preparing for video playback, playing video, pausing playback, obtaining track information, seeking to a playback position, setting the volume, setting the playback speed, stopping playback, resetting the playback configuration, and releasing resources.
For details about the **url**media source input types supported by **VideoPlayer**, see the [url attribute](../reference/apis/js-apis-media.md#videoplayer_attributes).
For details about the **url** types supported by **VideoPlayer**, see the [url attribute](../reference/apis/js-apis-media.md#videoplayer_attributes).
For details about how to create an XComponent, see [XComponent Creation](#xcomponent-creation).
For details about how to create an XComponent, see [XComponent](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/arkui-ts/ts-basic-components-xcomponent.md).
*Note: **SetSurface** must be called after the URL is set but before **Prepare** is called.
*Note: **setSurface** must be called after the URL is set but before **prepare** is called.
```js
importmediafrom'@ohos.multimedia.media'
importfileIOfrom'@ohos.fileio'
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer API.
letsurfaceID=undefined;// Used to save the surface ID returned by the XComponent interface.
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the XComponent is loaded.
// Report an error in the case of a function invocation failure.
functionfailureCallback(error){
exportclassVideoPlayerDemo{
// Report an error in the case of a function invocation failure.
failureCallback(error){
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
}
}
// Report an error in the case of a function invocation exception.
functioncatchCallback(error){
// Report an error in the case of a function invocation exception.
catchCallback(error){
console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`);
}
}
// Used to print the video track information.
functionprintfDescription(obj){
// Used to print the video track information.
printfDescription(obj){
for(letiteminobj){
letproperty=obj[item];
console.info('key is '+item);
console.info('value is '+property);
}
}
}
// Call createVideoPlayer to create a VideoPlayer instance.
awaitmedia.createVideoPlayer().then((video)=>{
asyncvideoPlayerDemo(){
letvideoPlayer=undefined;
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer API.
letsurfaceID=undefined;// Used to save the surface ID returned by the XComponent interface.
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the XComponent is loaded.
// Report an error in the case of a function invocation failure.
functionfailureCallback(error){
exportclassVideoPlayerDemo{
// Report an error in the case of a function invocation failure.
failureCallback(error){
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
}
}
// Report an error in the case of a function invocation exception.
functioncatchCallback(error){
// Report an error in the case of a function invocation exception.
catchCallback(error){
console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`);
}
// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
functionSetCallBack(videoPlayer){
videoPlayer.on('playbackCompleted',()=>{
console.info('video play finish');
}
awaitvideoPlayer.release().then(()=>{
console.info('release success');
},failureCallback).catch(catchCallback);
// Used to print the video track information.
printfDescription(obj){
for(letiteminobj){
letproperty=obj[item];
console.info('key is '+item);
console.info('value is '+property);
}
}
videoPlayer=undefined;
surfaceID=undefined;
asyncvideoPlayerDemo(){
letvideoPlayer=undefined;
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer API.
letsurfaceID=undefined;// Used to save the surface ID returned by the XComponent interface.
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the XComponent is loaded.
// Report an error in the case of a function invocation failure.
functionfailureCallback(error){
exportclassVideoPlayerDemo{
// Report an error in the case of a function invocation failure.
failureCallback(error){
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
}
}
// Report an error in the case of a function invocation exception.
functioncatchCallback(error){
// Report an error in the case of a function invocation exception.
catchCallback(error){
console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`);
}
// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
functionSetCallBack(videoPlayer){
videoPlayer.on('playbackCompleted',()=>{
console.info('video play finish');
}
awaitvideoPlayer.release().then(()=>{
console.info('release success');
},failureCallback).catch(catchCallback);
// Used to print the video track information.
printfDescription(obj){
for(letiteminobj){
letproperty=obj[item];
console.info('key is '+item);
console.info('value is '+property);
}
}
videoPlayer=undefined;
surfaceID=undefined;
asyncvideoPlayerDemo(){
letvideoPlayer=undefined;
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer API.
letsurfaceID=undefined;// Used to save the surface ID returned by the XComponent interface.
// The LoadXcomponent() API is used to obtain the surface ID and save it to the **surfaceID** variable. This API is automatically called when the XComponent is loaded.
// Report an error in the case of a function invocation failure.
functionfailureCallback(error){
exportclassVideoPlayerDemo{
// Report an error in the case of a function invocation failure.
failureCallback(error){
console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`);
}
}
// Report an error in the case of a function invocation exception.
functioncatchCallback(error){
// Report an error in the case of a function invocation exception.
catchCallback(error){
console.info(`catch error happened,error Name is ${error.name}`);
console.info(`catch error happened,error Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`);
}
}
// Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
functionSetCallBack(videoPlayer){
videoPlayer.on('playbackCompleted',()=>{
console.info('video play finish');
// Used to print the video track information.
printfDescription(obj){
for(letiteminobj){
letproperty=obj[item];
console.info('key is '+item);
console.info('value is '+property);
}
}
awaitvideoPlayer.release().then(()=>{
console.info('release success');
},failureCallback).catch(catchCallback);
sleep(time){
for(lett=Date.now();Date.now()-t<=time;);
}
videoPlayer=undefined;
surfaceID=undefined;
asyncvideoPlayerDemo(){
letvideoPlayer=undefined;
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent interface. For details about the document link, see the method of creating the XComponent.
letfdPath='fd://'
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" command.
The XComponent is used to obtain the surface ID during video playback. You need to create an xxx.hml file and add the following code to the xxx.hml file, where xxx is the same as that in the xxx.js file:
```js
<xcomponentid='Xcomponent'
if="{{isFlush}}"// Refresh the surface ID. To enable automatic loading of the XComponent and obtain the new surface ID, assign **false** to **isFlush** and then assign **true** to **isFlush**.
type='surface'
onload='LoadXcomponent'// Default interface for loading the XComponent.
style="width:720px;height:480px;border-color:red;border-width:5px;">// Set the window width, height, and other attributes.
@@ -16,21 +16,20 @@ During video recording, audio and video signals are captured, encoded, and saved
## How to Develop
For details about the APIs used for video recording, see [VideoRecorder in the Media API](../reference/apis/js-apis-media.md).
For details about the APIs, see [VideoRecorder in the Media API](../reference/apis/js-apis-media.md).
### Full-Process Scenario
The full video recording process includes creating an instance, setting recording parameters, recording video, pausing, resuming, and stopping recording, and releasing resources.
The full video recording process includes creating an instance, setting recording parameters, starting, pausing, resuming, and stopping recording, and releasing resources.
// pathName indicates the passed recording file name, for example, 01.mp4. The generated file address is /storage/media/100/local/files/Movies/01.mp4.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
asyncfunctiongetFd(pathName){
exportclassVideoRecorderDemo{
privatetestFdNumber;// Used to save the FD address.
// pathName indicates the passed recording file name, for example, 01.mp4. The generated file address is /storage/media/100/local/files/Video/01.mp4.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
asyncgetFd(pathName){
letdisplayName=pathName;
constmediaTest=mediaLibrary.getMediaLibrary();
letfileKeyObj=mediaLibrary.FileKey;
...
...
@@ -46,14 +45,31 @@ async function getFd(pathName) {
// Video recording depends on camera-related interfaces. The following operations can be performed only after the video output start interface is invoked.
// Video recording depends on camera-related APIs. The following operations can be performed only after the video output start API is invoked. For details about how to call the camera APIs, see the samples.