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}`);
...
...
@@ -92,10 +92,10 @@ function setCallBack(audioPlayer) {
}
asyncfunctionaudioPlayerDemo(){
// 1. Create an audioPlayer instance.
// 1. Create an AudioPlayer instance.
letaudioPlayer=media.createAudioPlayer();
setCallBack(audioPlayer);// Set the event callbacks.
// 2. Set the URI of the audio file selected by the user.
// 2. Set the URI of the audio file.
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.
@@ -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,14 +119,14 @@ 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=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',()=>{// Sets 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.
}
}
```
...
...
@@ -256,7 +256,7 @@ export class AudioDemo {
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, 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)
-[<idp:inline class="- topic/inline " val="code" displayname="code" id="code04927441464" tempcmdid="code04927441464">JsDistributedMusicPlayer</idp:inline>: Distributed Music Player (JS, API version 7)](https://gitee.com/openharmony/app_samples/tree/master/ability/JsDistributedMusicPlayer)
-[<idp:inline class="- topic/inline " val="code" displayname="code" id="code4276559568" tempcmdid="code4276559568">JsAudioPlayer</idp:inline>: Audio Playback and Management (JS, API version 7)](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer)
@@ -30,35 +30,35 @@ export class AudioRecorderDemo {
// Set the callbacks related to audio recording.
setCallBack(audioRecorder){
audioRecorder.on('prepare',()=>{// Set the 'prepare' event callback.
audioRecorder.on('prepare',()=>{// Set the prepare event callback.
console.log('prepare success');
audioRecorder.start();// Call the start API to start recording and trigger the 'start' event callback.
audioRecorder.start();// Call the start API to start recording and trigger the start event callback.
});
audioRecorder.on('start',()=>{// Set the 'start' event callback.
audioRecorder.on('start',()=>{// Set the start event callback.
console.log('audio recorder start success');
audioRecorder.pause();// Call the pause API to pause recording and trigger the 'pause' event callback.
audioRecorder.pause();// Call the pause API to pause recording and trigger the pause event callback.
});
audioRecorder.on('pause',()=>{// Set the 'pause' event callback.
audioRecorder.on('pause',()=>{// Set the pause event callback.
console.log('audio recorder pause success');
audioRecorder.resume();// Call the resume API to resume recording and trigger the 'resume' event callback.
audioRecorder.resume();// Call the resume API to resume recording and trigger the resume event callback.
});
audioRecorder.on('resume',()=>{// Set the 'resume' event callback.
audioRecorder.on('resume',()=>{// Set the resume event callback.
console.log('audio recorder resume success');
audioRecorder.stop();// Call the stop API to stop recording and trigger the 'stop' event callback.
audioRecorder.stop();// Call the stop API to stop recording and trigger the stop event callback.
});
audioRecorder.on('stop',()=>{// Set the 'stop' event callback.
audioRecorder.on('stop',()=>{// Set the stop event callback.
console.log('audio recorder stop success');
audioRecorder.reset();// Call the reset API to reset the recorder and trigger the 'reset' event callback.
audioRecorder.reset();// Call the reset API to reset the recorder and trigger the reset event callback.
});
audioRecorder.on('reset',()=>{// Set the 'reset' event callback.
audioRecorder.on('reset',()=>{// Set the reset event callback.
console.log('audio recorder reset success');
audioRecorder.release();// Call the release API to release resources and trigger the 'release' event callback.
audioRecorder.release();// Call the release API to release resources and trigger the release event callback.
});
audioRecorder.on('release',()=>{// Set 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.
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}`);
...
...
@@ -103,7 +103,7 @@ export class AudioRecorderDemo {
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);// Call the prepare method to trigger the prepare event callback.
}
}
```
...
...
@@ -120,23 +120,23 @@ export class AudioRecorderDemo {
// Set the callbacks related to audio recording.
setCallBack(audioRecorder){
audioRecorder.on('prepare',()=>{// Set the 'prepare' event callback.
audioRecorder.on('prepare',()=>{// Set the prepare event callback.
console.log('prepare success');
audioRecorder.start();// Call the start API to start recording and trigger the 'start' event callback.
audioRecorder.start();// Call the start API to start recording and trigger the start event callback.
});
audioRecorder.on('start',()=>{// Set the 'start' event callback.
audioRecorder.on('start',()=>{// Set the start event callback.
console.log('audio recorder start success');
audioRecorder.stop();// Call the stop API to stop recording and trigger the 'stop' event callback.
audioRecorder.stop();// Call the stop API to stop recording and trigger the stop event callback.
});
audioRecorder.on('stop',()=>{// Set 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.release();// Call the release API to release resources and trigger the release event callback.
});
audioRecorder.on('release',()=>{// Set 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.
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}`);
...
...
@@ -181,7 +181,7 @@ export class AudioRecorderDemo {
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);// Call the prepare method to trigger the prepare event callback.
}
}
```
...
...
@@ -190,6 +190,7 @@ export class AudioRecorderDemo {
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)
-[<idp:inline class="- topic/inline " val="code" displayname="code" id="code15884933169" tempcmdid="code15884933169">Recorder</idp:inline>: Recorder (eTS, API version 8)](https://gitee.com/openharmony/app_samples/tree/master/media/Recorder)
-[<idp:inline class="- topic/inline " val="code" displayname="code" id="code563211231612" tempcmdid="code563211231612">JsRecorder</idp:inline>: Recorder (JS, API version 8)](https://gitee.com/openharmony/app_samples/tree/master/media/JSRecorder)
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.
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent API. 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.
@@ -205,7 +205,7 @@ export class VideoPlayerDemo {
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.
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent API. 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.
@@ -292,7 +292,7 @@ export class VideoPlayerDemo {
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.
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent API. 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.
@@ -407,7 +407,7 @@ export class VideoPlayerDemo {
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.
letsurfaceID='test'// The surfaceID parameter is used for screen display. Its value is obtained through the XComponent API. 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.