diff --git a/en/application-dev/media/audio-playback.md b/en/application-dev/media/audio-playback.md index 2124319f5e48f70657ce21c8d4f90b35136b2a37..dea72108451e84d1b6c3b23a9b40df11ed4b31a2 100644 --- a/en/application-dev/media/audio-playback.md +++ b/en/application-dev/media/audio-playback.md @@ -16,7 +16,7 @@ You can use audio playback APIs to convert audio data into audible analog signal ## How to Develop -For details about the APIs used for audio playback, see [AudioPlayer in the Media API](../reference/apis/js-apis-media.md). +For details about the APIs, see [AudioPlayer in the Media API](../reference/apis/js-apis-media.md). ### Full-Process Scenario @@ -84,7 +84,8 @@ let audioPlayer = media.createAudioPlayer(); SetCallBack(audioPlayer); // Set the event callbacks. // 2. Set the URI of the audio file selected by the user. let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; +// 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'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); @@ -147,7 +148,8 @@ let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer inst SetCallBack(audioPlayer); // Set the event callbacks. /* Set the FD (local playback) of the audio file selected by the user. */ let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; +// 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'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); @@ -185,7 +187,8 @@ let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer inst SetCallBack(audioPlayer); // Set the event callbacks. /* Set the FD (local playback) of the audio file selected by the user. */ let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; +// 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'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); @@ -201,7 +204,8 @@ audioPlayer.reset(); /* Set the FD (local playback) of the audio file selected by the user. */ let fdNextPath = 'fd://' -let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; +// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\02.mp3 /data/accounts/account_0/appdata" command. +let nextPath = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp3'; await fileIO.open(nextPath).then(fdNumber) => { fdNextPath = fdNextPath + '' + fdNumber; console.info('open fd sucess fd is' + fdNextPath); @@ -239,6 +243,7 @@ SetCallBack(audioPlayer); // Set the event callbacks. /* Set the FD (local playback) of the audio file selected by the user. */ 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'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; @@ -252,3 +257,13 @@ await fileIO.open(path).then(fdNumber) => { audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback. audioPlayer.loop = true; // Set the loop playback attribute. ``` + +## Samples + +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) + +- [Audio Player](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS) diff --git a/en/application-dev/media/video-playback.md b/en/application-dev/media/video-playback.md index e3031c1f2d3da82979941feaa1564bc10aac1bbf..7520e2cfdc687e8596afa9558e3935812650ece5 100644 --- a/en/application-dev/media/video-playback.md +++ b/en/application-dev/media/video-playback.md @@ -95,7 +95,8 @@ await media.createVideoPlayer().then((video) => { // Set the FD (local playback) of the video file selected by the user. let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; +// 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.mp4'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); @@ -237,7 +238,8 @@ SetCallBack(videoPlayer); // Set the FD (local playback) of the video file selected by the user. let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; +// 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.mp4'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); @@ -323,7 +325,8 @@ SetCallBack(videoPlayer); // Set the FD (local playback) of the video file selected by the user. let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; +// 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.mp4'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); @@ -358,7 +361,8 @@ await videoPlayer.reset().then(() => { // Set the FD (local playback) of the video file selected by the user. let fdNextPath = 'fd://' -let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4'; +// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\02.mp3 /data/accounts/account_0/appdata" command. +let nextPath = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4'; await fileIO.open(nextPath).then(fdNumber) => { fdNextPath = fdNextPath + '' + fdNumber; console.info('open fd sucess fd is' + fdNextPath); @@ -444,7 +448,8 @@ SetCallBack(videoPlayer); // Set the FD (local playback) of the video file selected by the user. let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; +// 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.mp4'; await fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); diff --git a/en/application-dev/reference/apis/js-apis-media.md b/en/application-dev/reference/apis/js-apis-media.md index 27a2cd8bfe67534592f270299656f5adc53904dc..01c344e01074a9d2576367a76b09cdeb6a98e3ef 100644 --- a/en/application-dev/reference/apis/js-apis-media.md +++ b/en/application-dev/reference/apis/js-apis-media.md @@ -572,7 +572,8 @@ 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 path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; +// 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; console.info('open fd sucess fd is' + fdPath);