未验证 提交 55f7cb37 编写于 作者: O openharmony_ci 提交者: Gitee

!2383 Done! 2190:媒体指南修复

Merge pull request !2383 from wusongqing/TR2190
...@@ -20,7 +20,7 @@ For details about the APIs used for audio playback, see [js-apis-media.md](../re ...@@ -20,7 +20,7 @@ For details about the APIs used for audio playback, see [js-apis-media.md](../re
### Full-Process Scenario ### Full-Process Scenario
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 resources, and releasing resources. 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** media source input types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
...@@ -82,7 +82,7 @@ function printfDescription(obj) { ...@@ -82,7 +82,7 @@ function printfDescription(obj) {
// 1. Create an audioPlayer instance. // 1. Create an audioPlayer instance.
let audioPlayer = media.createAudioPlayer(); let audioPlayer = media.createAudioPlayer();
SetCallBack(audioPlayer); // Set the event callbacks. SetCallBack(audioPlayer); // Set the event callbacks.
// 2. Set the URI of the audio file. // 2. Set the URI of the audio file selected by the user.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -95,8 +95,8 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -95,8 +95,8 @@ await fileIO.open(path).then(fdNumber) => {
}); });
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.
// 3. Play the audio. // 3. Play the audio file.
audioPlayer.play(); // The play() method can be invoked only after the 'dataLoad' event callback is complete. The 'play' event callback is triggered. audioPlayer.play(); // The play() API can be invoked only after the 'dataLoad' event callback is complete. The 'play' event callback is triggered.
// 4. Seek to the playback position. // 4. Seek to the playback position.
audioPlayer.seek(30000); // Trigger the 'timeUpdate' event callback, and seek to 30000 ms for playback. audioPlayer.seek(30000); // Trigger the 'timeUpdate' event callback, and seek to 30000 ms for playback.
// 5. Set the volume. // 5. Set the volume.
...@@ -113,9 +113,9 @@ audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track ...@@ -113,9 +113,9 @@ audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track
console.log(`audio getTrackDescription fail, error:${error.message}`); console.log(`audio getTrackDescription fail, error:${error.message}`);
} }
}); });
// 8. Stop playback. // 8. Stop the playback.
audioPlayer.stop(); // Trigger the 'stop' event callback. audioPlayer.stop(); // Trigger the 'stop' event callback.
// 9. Reset the playback resources. // 9. Reset the player.
audioPlayer.reset(); // Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song. audioPlayer.reset(); // Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song.
// 10. Release the resource. // 10. Release the resource.
audioPlayer.release(); // Release the AudioPlayer instance. audioPlayer.release(); // Release the AudioPlayer instance.
...@@ -131,7 +131,7 @@ import fileIO from '@ohos.fileio' ...@@ -131,7 +131,7 @@ import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) { function 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'); console.info('audio set source success');
audioPlayer.play(); // Call the play() method 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'); console.info('audio play success');
...@@ -169,7 +169,7 @@ import fileIO from '@ohos.fileio' ...@@ -169,7 +169,7 @@ import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) { function 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'); console.info('audio set source success');
audioPlayer.play(); // Call the play() method 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'); console.info('audio play success');
...@@ -222,7 +222,7 @@ import fileIO from '@ohos.fileio' ...@@ -222,7 +222,7 @@ import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) { function 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'); console.info('audio set source success');
audioPlayer.play(); // Call the play() method 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'); console.info('audio play success');
......
...@@ -103,15 +103,15 @@ let audioRecorderConfig = { ...@@ -103,15 +103,15 @@ let audioRecorderConfig = {
} }
audioRecorder.prepare(audioRecorderConfig); audioRecorder.prepare(audioRecorderConfig);
// 4. Start recording. // 4. Start recording.
audioRecorder.start(); // The start method can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete. audioRecorder.start(); // The start API can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete.
// 5. Pause recording. // 5. Pause recording.
audioRecorder.pause(); // The pause method can be called to trigger the 'pause' event callback only after the 'start' event callback is complete. audioRecorder.pause(); // The pause API can be called to trigger the 'pause' event callback only after the 'start' event callback is complete.
// 6. Resume recording. // 6. Resume recording.
audioRecorder.resume(); // The resume method can be called to trigger the 'resume' event callback only after the 'pause' event callback is complete. audioRecorder.resume(); // The resume API can be called to trigger the 'resume' event callback only after the 'pause' event callback is complete.
// 7. Stop recording. // 7. Stop recording.
audioRecorder.stop(); // The stop method can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete. audioRecorder.stop(); // The stop API can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
// 8. Reset recording. // 8. Reset recording.
audioRecorder.reset(); // The prepare method can be called for another recording only after the 'reset' event callback is complete. audioRecorder.reset(); // The prepare API can be called for another recording only after the 'reset' event callback is complete.
// 9. Release resources. // 9. Release resources.
audioRecorder.release(); // The AudioRecorder resource is destroyed. audioRecorder.release(); // The AudioRecorder resource is destroyed.
audioRecorder = undefined; audioRecorder = undefined;
...@@ -185,9 +185,9 @@ let audioRecorderConfig = { ...@@ -185,9 +185,9 @@ let audioRecorderConfig = {
} }
audioRecorder.prepare(audioRecorderConfig) audioRecorder.prepare(audioRecorderConfig)
// 4. Start recording. // 4. Start recording.
audioRecorder.start(); // The start method can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete. 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. // 5. Stop recording.
audioRecorder.stop(); // The stop method can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete. 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. // 6. Release resources.
audioRecorder.release(); // The AudioRecorder resource is destroyed. audioRecorder.release(); // The AudioRecorder resource is destroyed.
audioRecorder = undefined; audioRecorder = undefined;
......
...@@ -36,10 +36,10 @@ For details about how to create an Xcomponent, see [Xcomponent Creation](#Xcompo ...@@ -36,10 +36,10 @@ For details about how to create an Xcomponent, see [Xcomponent Creation](#Xcompo
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method. let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. let surfaceID = 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. // 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.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
...@@ -170,10 +170,10 @@ surfaceID = undefined; ...@@ -170,10 +170,10 @@ surfaceID = undefined;
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method. let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. let surfaceID = 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. // 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.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
...@@ -256,10 +256,10 @@ await videoPlayer.play().then(() => { ...@@ -256,10 +256,10 @@ await videoPlayer.play().then(() => {
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method. let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. let surfaceID = 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. // 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.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
...@@ -377,10 +377,10 @@ await videoPlayer.play().then(() => { ...@@ -377,10 +377,10 @@ await videoPlayer.play().then(() => {
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method. let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer API.
let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface. let surfaceID = 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. // 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.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
...@@ -462,8 +462,9 @@ await videoPlayer.play().then(() => { ...@@ -462,8 +462,9 @@ await videoPlayer.play().then(() => {
### Xcomponent Creation ### Xcomponent Creation
```js
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: 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
<xcomponent id = 'Xcomponent' <xcomponent id = '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**. 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' type = 'surface'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册