@@ -25,6 +25,9 @@ The full audio playback process includes creating an instance, setting the URI,
For details about the **src** media source input 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){
audioPlayer.on('dataLoad',()=>{// Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
...
...
@@ -80,7 +83,18 @@ function printfDescription(obj) {
letaudioPlayer=media.createAudioPlayer();
SetCallBack(audioPlayer);// Set the event callbacks.
// 2. Set the URI of the audio file.
audioPlayer.src='file:///data/data/ohos.xxx.xxx/files/test.mp3';// Set the src attribute and trigger the 'dataLoad' event callback.
@@ -23,6 +23,11 @@ For details about the APIs used for audio recording, see [js-apis-media.md](../r
The full audio recording process includes creating an instance, setting recording parameters, starting, pausing, resuming, and stopping recording, and releasing resources.
audioRecorder.on('prepare',()=>{// Set the 'prepare' event callback.
console.log('prepare success');
...
...
@@ -57,6 +62,31 @@ function SetCallBack(audioRecorder) {
});
}
// 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.
audioRecorder.on('prepare',()=>{// Set the 'prepare' event callback.
console.log('prepare success');
...
...
@@ -108,6 +143,32 @@ function SetCallBack(audioPlayer) {
console.log('audio recorder release success');
});
}
// 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.
@@ -28,10 +28,23 @@ For details about the APIs used for video playback, see [js-apis-media.md](../re
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 how to create an Xcomponent, see [Xcomponent Creation](#Xcomponent).
```js
importmediafrom'@ohos.multimedia.media'
importfileIOfrom'@ohos.fileio'
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
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.
@@ -23,6 +23,36 @@ For details about the APIs used for video recording, see [js-apis-media.md](../r
The full video recording process includes creating an instance, setting recording parameters, recording video, 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.