diff --git a/zh-cn/application-dev/media/audio-playback.md b/zh-cn/application-dev/media/audio-playback.md
index 757d99fdc6ca84fc2aab9acf1d36531a5a46df70..a142a8b010630fa19349c78e8b40bfd956042695 100644
--- a/zh-cn/application-dev/media/audio-playback.md
+++ b/zh-cn/application-dev/media/audio-playback.md
@@ -25,6 +25,9 @@
AudioPlayer支持的src媒体源输入类型可参考:[src属性说明](../reference/apis/js-apis-media.md#audioplayer_属性)
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
@@ -80,7 +83,18 @@ function printfDescription(obj) {
let audioPlayer = media.createAudioPlayer();
SetCallBack(audioPlayer); //设置事件回调
//2、用户选择音频,设置uri
-audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
+
+audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
//3、播放音频
audioPlayer.play(); //需等待'dataLoad'事件回调完成后,才可调用play进行播放,触发'play'事件回调
//4、跳转播放位置
@@ -111,6 +125,9 @@ audioPlayer = undefined;
### 正常播放场景
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
@@ -128,13 +145,27 @@ function SetCallBack(audioPlayer) {
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例
SetCallBack(audioPlayer); //设置事件回调
-/* 用户选择音频,设置uri */
-audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
+/* 用户选择视频设置fd(本地播放) */
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
+
+audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
```
### 切歌场景
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
@@ -152,16 +183,42 @@ function SetCallBack(audioPlayer) {
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例
SetCallBack(audioPlayer); //设置事件回调
-/* 用户选择音频,设置uri */
-audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
+/* 用户选择视频设置fd(本地播放) */
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
+
+audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
/* 播放一段时间后,下发切歌指令 */
audioPlayer.reset();
-audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/next.mp3';
+
+/* 用户选择视频设置fd(本地播放) */
+let fdNextPath = 'fd://'
+let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
+await fileIO.open(nextPath).then(fdNumber) => {
+ fdNextPath = fdNextPath + '' + fdNumber;
+ console.info('open fd sucess fd is' + fdNextPath);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
+audioPlayer.src = fdNextPath;
```
### 单曲循环场景
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success');
@@ -179,7 +236,19 @@ function SetCallBack(audioPlayer) {
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例
SetCallBack(audioPlayer); //设置事件回调
-/* 用户选择音频,设置uri */
-audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调
-audioPlayer.loop = true; //设置循环播放属性
+
+/* 用户选择视频设置fd(本地播放) */
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
+
+audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
+audioPlayer.loop = true; //设置循环播放属性
```
\ No newline at end of file
diff --git a/zh-cn/application-dev/media/audio-recorder.md b/zh-cn/application-dev/media/audio-recorder.md
index 0d1acf4df17b871b3d390e83469c411adde046c6..7e52686c95eb380bbb58d468b764f8eafbbc2d41 100644
--- a/zh-cn/application-dev/media/audio-recorder.md
+++ b/zh-cn/application-dev/media/audio-recorder.md
@@ -23,6 +23,11 @@
包含流程:创建实例,设置录制参数,录制音频,暂停录制,恢复录制,停止录制,释放资源等流程。
```js
+import media from '@ohos.multimedia.media'
+import mediaLibrary from '@ohos.multimedia.mediaLibrary'
+
+let testFdNumber;
+
function SetCallBack(audioRecorder) {
audioRecorder.on('prepare', () => { // 设置'prepare'事件回调
console.log('prepare success');
@@ -57,6 +62,31 @@ function SetCallBack(audioRecorder) {
});
}
+// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3
+// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
+async function getFd(pathName) {
+ let displayName = pathName;
+ const mediaTest = mediaLibrary.getMediaLibrary();
+ let fileKeyObj = mediaLibrary.FileKey;
+ let mediaType = mediaLibrary.MediaType.VIDEO;
+ let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
+ let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
+ if (dataUri != undefined) {
+ let args = dataUri.id.toString();
+ let fetchOp = {
+ selections : fileKeyObj.ID + "=?",
+ selectionArgs : [args],
+ }
+ let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
+ let fileAsset = await fetchFileResult.getAllObject();
+ let fdNumber = await fileAsset[0].open('Rw');
+ fdNumber = "fd://" + fdNumber.toString();
+ testFdNumber = fdNumber;
+ }
+}
+
+await getFd('01.mp3');
+
// 1.创建实例
let audioRecorder = media.createAudioRecorder();
// 2.设置回调
@@ -68,7 +98,7 @@ let audioRecorderConfig = {
audioSampleRate : 22050,
numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS,
- uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', // 文件需先由调用者创建,并给予适当的权限
+ uri : testFdNumber, // testFdNumber由getFd生成
location : { latitude : 30, longitude : 130},
}
audioRecorder.prepare(audioRecorderConfig);
@@ -92,6 +122,11 @@ audioRecorder = undefined;
与全流程场景不同,不包括暂停录制,恢复录制的过程。
```js
+import media from '@ohos.multimedia.media'
+import mediaLibrary from '@ohos.multimedia.mediaLibrary'
+
+let testFdNumber;
+
function SetCallBack(audioPlayer) {
audioRecorder.on('prepare', () => { // 设置'prepare'事件回调
console.log('prepare success');
@@ -108,6 +143,32 @@ function SetCallBack(audioPlayer) {
console.log('audio recorder release success');
});
}
+
+// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3
+// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
+async function getFd(pathName) {
+ let displayName = pathName;
+ const mediaTest = mediaLibrary.getMediaLibrary();
+ let fileKeyObj = mediaLibrary.FileKey;
+ let mediaType = mediaLibrary.MediaType.VIDEO;
+ let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
+ let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
+ if (dataUri != undefined) {
+ let args = dataUri.id.toString();
+ let fetchOp = {
+ selections : fileKeyObj.ID + "=?",
+ selectionArgs : [args],
+ }
+ let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
+ let fileAsset = await fetchFileResult.getAllObject();
+ let fdNumber = await fileAsset[0].open('Rw');
+ fdNumber = "fd://" + fdNumber.toString();
+ testFdNumber = fdNumber;
+ }
+}
+
+await getFd('01.mp3');
+
// 1.创建实例
let audioRecorder = media.createAudioRecorder();
// 2.设置回调
@@ -119,7 +180,7 @@ let audioRecorderConfig = {
audioSampleRate : 22050,
numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS,
- uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', // 文件需先由调用者创建,并给予适当的权限
+ uri : testFdNumber, // testFdNumber由getFd生成
location : { latitude : 30, longitude : 130},
}
audioRecorder.prepare(audioRecorderConfig)
diff --git a/zh-cn/application-dev/media/video-playback.md b/zh-cn/application-dev/media/video-playback.md
index 5fe625c1dfb1e1b29f3f009fdb42ea96ab9a5c30..708a3e20e8d1423ed8d92abab6f4c6b0e1019a76 100644
--- a/zh-cn/application-dev/media/video-playback.md
+++ b/zh-cn/application-dev/media/video-playback.md
@@ -30,10 +30,21 @@
VideoPlayer支持的url媒体源输入类型可参考:[url属性说明](../reference/apis/js-apis-media.md#videoplayer_属性)
+Xcomponent创建方法可参考:[Xcomponent创建方法](#Xcomponent创建方法)
+
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
+// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
+LoadXcomponent() {
+ surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
+ console.info('LoadXcomponent surfaceID is' + surfaceID);
+}
+
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
@@ -67,10 +78,19 @@ await media.createVideoPlayer().then((video) => {
}
}, failureCallback).catch(catchCallback);
-// 用户选择视频设置url
-videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
+// 用户选择视频设置fd(本地播放)
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
-// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
+videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
@@ -147,9 +167,18 @@ surfaceID = undefined;
### 正常播放场景
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
+// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
+LoadXcomponent() {
+ surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
+ console.info('LoadXcomponent surfaceID is' + surfaceID);
+}
+
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
@@ -191,10 +220,19 @@ await media.createVideoPlayer().then((video) => {
// 设置事件回调
SetCallBack(videoPlayer);
-// 用户选择视频设置url
-videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
+// 用户选择视频设置fd(本地播放)
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
-// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
+videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
@@ -215,9 +253,18 @@ await videoPlayer.play().then(() => {
### 切视频场景
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
+// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
+LoadXcomponent() {
+ surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
+ console.info('LoadXcomponent surfaceID is' + surfaceID);
+}
+
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
@@ -259,10 +306,19 @@ await media.createVideoPlayer().then((video) => {
// 设置事件回调
SetCallBack(videoPlayer);
-// 用户选择视频设置url
-videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
+// 用户选择视频设置fd(本地播放)
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
-// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
+videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
@@ -285,7 +341,19 @@ await videoPlayer.reset().then(() => {
console.info('reset success');
}, failureCallback).catch(catchCallback);
-videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/next.mp4';
+// 用户选择视频设置fd(本地播放)
+let fdNextPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
+
+videoPlayer.url = fdNextPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
@@ -306,9 +374,18 @@ await videoPlayer.play().then(() => {
### 单个视频循环场景
```js
+import media from '@ohos.multimedia.media'
+import fileIO from '@ohos.fileio'
+
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
+// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用
+LoadXcomponent() {
+ surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
+ console.info('LoadXcomponent surfaceID is' + surfaceID);
+}
+
// 函数调用发生错误时用于上报错误信息
function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`);
@@ -350,10 +427,19 @@ await media.createVideoPlayer().then((video) => {
// 设置事件回调
SetCallBack(videoPlayer);
-// 用户选择视频设置url
-videoPlayer.url = 'file:///data/data/ohos.xxx.xxx/files/test.mp4';
+// 用户选择视频设置fd(本地播放)
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
-// 该处需要调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中
+videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
@@ -372,4 +458,16 @@ videoPlayer.loop = true;
await videoPlayer.play().then(() => {
console.info('play success');
}, failureCallback).catch(catchCallback);
-```
\ No newline at end of file
+```
+
+### Xcomponent创建方法
+
+```js
+播放视频中获取surfaceID依赖了Xcomponent,需要创建一个和xxx.js同名的xxx.hml文件,xxx.hml里面需要添加如下代码:
+ // 设置窗口宽高等属性
+
+```
diff --git a/zh-cn/application-dev/media/video-recorder.md b/zh-cn/application-dev/media/video-recorder.md
index 0537f4f1da61bb8da57e65c20104ddf336aa362b..e684b2230ad3c9f839a1be48badcd0b40d0c55a6 100644
--- a/zh-cn/application-dev/media/video-recorder.md
+++ b/zh-cn/application-dev/media/video-recorder.md
@@ -23,6 +23,36 @@
包含流程:创建实例,设置录制参数,录制视频,暂停录制,恢复录制,停止录制,释放资源等流程。
```js
+import media from '@ohos.multimedia.media'
+import mediaLibrary from '@ohos.multimedia.mediaLibrary'
+
+let testFdNumber;
+
+// pathName是传入的录制文件名,例如:01.mp4,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp4
+// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
+async function getFd(pathName) {
+ let displayName = pathName;
+ const mediaTest = mediaLibrary.getMediaLibrary();
+ let fileKeyObj = mediaLibrary.FileKey;
+ let mediaType = mediaLibrary.MediaType.VIDEO;
+ let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
+ let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
+ if (dataUri != undefined) {
+ let args = dataUri.id.toString();
+ let fetchOp = {
+ selections : fileKeyObj.ID + "=?",
+ selectionArgs : [args],
+ }
+ let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
+ let fileAsset = await fetchFileResult.getAllObject();
+ let fdNumber = await fileAsset[0].open('Rw');
+ fdNumber = "fd://" + fdNumber.toString();
+ testFdNumber = fdNumber;
+ }
+}
+
+await getFd('01.mp4');
+
let videoProfile = {
audioBitrate : 48000,
audioChannels : 2,
@@ -40,7 +70,7 @@ let videoConfig = {
audioSourceType : 1,
videoSourceType : 0,
profile : videoProfile,
- url : 'file:///data/media/01.mp4',
+ url : testFdNumber, // testFdNumber由getFd生成
orientationHint : 0,
location : { latitude : 30, longitude : 130 },
}
@@ -61,6 +91,7 @@ function catchCallback(error) {
let videoRecorder = null; // videoRecorder空对象在createVideoRecorder成功后赋值
let surfaceID = null; // 用于保存getInputSurface返回的surfaceID
+
// 创建videoRecorder对象
await media.createVideoRecorder().then((recorder) => {
console.info('case createVideoRecorder called');
diff --git a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png
deleted file mode 100644
index 1e2cc34bf20dcd27dc9dff6a3eb6eb56dd4809c4..0000000000000000000000000000000000000000
Binary files a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png and /dev/null differ
diff --git a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_url.png b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_url.png
new file mode 100644
index 0000000000000000000000000000000000000000..aa3175e145cfce399bef43bf5c7a2ac7feb0a576
Binary files /dev/null and b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_url.png differ
diff --git a/zh-cn/application-dev/reference/apis/js-apis-media.md b/zh-cn/application-dev/reference/apis/js-apis-media.md
index 74a1d0b8f40b304115e2cf22f1de6520f76c4a9a..4ffe5de81d8edf6ae9ccf47fdc972fcd0d6d11b9 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-media.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-media.md
@@ -34,64 +34,7 @@ createAudioPlayer(): [AudioPlayer](#audioplayer)
**示例:**
```js
-var audioPlayer = media.createAudioPlayer();
-```
-
-## media.createAudioPlayerAsync8+
-
-createAudioPlayerAsync(callback: AsyncCallback\<[AudioPlayer](#audioplayer)>): void
-
-异步方式创建音频播放实例。通过注册回调函数获取返回值。
-
-**参数:**
-
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ------------------------------------------ | ---- | ------------------------------ |
-| callback | AsyncCallback<[AudioPlayer](#audioplayer)> | 是 | 异步创建音频播放实例回调方法。 |
-
-**示例:**
-
-```js
-media.createAudioPlayerAsync((error, audio) => {
- if (typeof(audio) != 'undefined') {
- audioPlayer = audio;
- console.info('audio createAudioPlayerAsync success');
- } else {
- console.info(`audio createAudioPlayerAsync fail, error:${error.message}`);
- }
-});
-```
-
-## media.createAudioPlayerAsync8+
-
-createAudioPlayerAsync: Promise<[AudioPlayer](#audioplayer)>
-
-异步方式创建音频播放实例。通过Promise获取返回值。
-
-**返回值:**
-
-| 类型 | 说明 |
-| ------------------------------------ | ----------------------------------- |
-| Promise<[AudioPlayer](#audioplayer)> | 异步创建音频播放实例Promise返回值。 |
-
-**示例:**
-
-```js
-function failureCallback(error) {
- console.info(`audio failureCallback, error:${error.message}`);
-}
-function catchCallback(error) {
- console.info(`audio catchCallback, error:${error.message}`);
-}
-
-await media.createAudioPlayerAsync.then((audio) => {
- if (typeof(audio) != 'undefined') {
- audioPlayer = audio;
- console.info('audio createAudioPlayerAsync success');
- } else {
- console.info('audio createAudioPlayerAsync fail');
- }
-}, failureCallback).catch(catchCallback);
+let audioPlayer = media.createAudioPlayer();
```
## media.createVideoPlayer8+
@@ -109,6 +52,8 @@ createVideoPlayer(callback: AsyncCallback\<[VideoPlayer](#videoplayer8)>): void
**示例:**
```js
+let videoPlayer
+
media.createVideoPlayer((error, video) => {
if (typeof(video) != 'undefined') {
videoPlayer = video;
@@ -134,6 +79,8 @@ createVideoPlayer: Promise<[VideoPlayer](#videoplayer8)>
**示例:**
```js
+let videoPlayer
+
function failureCallback(error) {
console.info(`video failureCallback, error:${error.message}`);
}
@@ -169,66 +116,9 @@ createAudioRecorder(): AudioRecorder
let audiorecorder = media.createAudioRecorder();
```
-## media.createAudioRecorderAsync8+
+## media.createVideoRecorder8+
-createAudioRecorderAsync(callback: AsyncCallback\<[AudioRecorder](#audiorecorder)>): void
-
-异步方式创建音频录制实例。通过注册回调函数获取返回值。
-
-**参数:**
-
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ---------------------------------------------- | ---- | ------------------------------ |
-| callback | AsyncCallback<[AudioRecorder](#audiorecorder)> | 是 | 异步创建音频录制实例回调方法。 |
-
-**示例:**
-
-```js
-media.createAudioRecorderAsync((error, audio) => {
- if (typeof(audio) != 'undefined') {
- audioRecorder = audio;
- console.info('audio createAudioRecorderAsync success');
- } else {
- console.info(`audio createAudioRecorderAsync fail, error:${error.message}`);
- }
-});
-```
-
-## media.createAudioRecorderAsync8+
-
-createAudioRecorderAsync: Promise<[AudioRecorder](#audiorecorder)>
-
-异步方式创建音频录制实例。通过Promise获取返回值。
-
-**返回值:**
-
-| 类型 | 说明 |
-| ---------------------------------------- | ----------------------------------- |
-| Promise<[AudioRecorder](#audiorecorder)> | 异步创建音频录制实例Promise返回值。 |
-
-**示例:**
-
-```js
-function failureCallback(error) {
- console.info(`audio failureCallback, error:${error.message}`);
-}
-function catchCallback(error) {
- console.info(`audio catchCallback, error:${error.message}`);
-}
-
-await media.createAudioRecorderAsync.then((audio) => {
- if (typeof(audio) != 'undefined') {
- audioRecorder = audio;
- console.info('audio createAudioRecorderAsync success');
- } else {
- console.info('audio createAudioRecorderAsync fail');
- }
-}, failureCallback).catch(catchCallback);
-```
-
-## media.createVideoRecorderAsync8+
-
-createVideoRecorderAsync(callback: AsyncCallback\<[VideoRecorder](#videorecorder8)>): void
+createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder8)>): void
异步方式创建视频录制实例。通过注册回调函数获取返回值。
@@ -241,19 +131,21 @@ createVideoRecorderAsync(callback: AsyncCallback\<[VideoRecorder](#videorecorder
**示例:**
```js
-media.createVideoRecorderAsync((error, video) => {
+let videoRecorder
+
+media.createVideoRecorder((error, video) => {
if (typeof(video) != 'undefined') {
videoRecorder = video;
- console.info('video createVideoRecorderAsync success');
+ console.info('video createVideoRecorder success');
} else {
- console.info(`video createVideoRecorderAsync fail, error:${error.message}`);
+ console.info(`video createVideoRecorder fail, error:${error.message}`);
}
});
```
-## media.createVideoRecorderAsync8+
+## media.createVideoRecorder8+
-createVideoRecorderAsync: Promise<[VideoRecorder](#videorecorder8)>
+createVideoRecorder: Promise<[VideoRecorder](#videorecorder8)>
异步方式创建视频录制实例。通过Promise获取返回值。
@@ -266,6 +158,8 @@ createVideoRecorderAsync: Promise<[VideoRecorder](#videorecorder8)>
**示例:**
```js
+let videoRecorder
+
function failureCallback(error) {
console.info(`video failureCallback, error:${error.message}`);
}
@@ -273,12 +167,12 @@ function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`);
}
-await media.createVideoRecorderAsync.then((video) => {
+await media.createVideoRecorder.then((video) => {
if (typeof(video) != 'undefined') {
videoRecorder = video;
- console.info('video createVideoRecorderAsync success');
+ console.info('video createVideoRecorder success');
} else {
- console.info('video createVideoRecorderAsync fail');
+ console.info('video createVideoRecorder fail');
}
}, failureCallback).catch(catchCallback);
```
@@ -362,7 +256,7 @@ Codec MIME类型枚举
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ |
-| src | string | 是 | 是 | 音频媒体URI,支持当前主流的音频格式(mp4、aac、mp3、ogg)。
**支持路径示例**:
1、本地绝对路径:file:///data/data/ohos.xxx.xxx/files/test.mp4
![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)
2、http网络播放路径:开发中
3、hls网络播放路径:开发中
4、fd类型播放:开发中
**注意事项**:
媒体素材需至少赋予读权限后,才可正常播放 |
+| src | string | 是 | 是 | 音频媒体URI,支持当前主流的音频格式(mp4、aac、mp3、ogg)。
**支持路径示例**:
1、fd类型播放:fd://xxx
![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)
2、http网络播放路径:开发中
3、hls网络播放路径:开发中
**注意事项**:
媒体素材需至少赋予读权限后,才可正常播放 |
| loop | boolean | 是 | 是 | 音频循环播放属性,设置为'true'表示循环播放。 |
| currentTime | number | 是 | 否 | 音频的当前播放位置。 |
| duration | number | 是 | 否 | 音频时长。 |
@@ -639,7 +533,19 @@ audioPlayer.on('error', (error) => { //设置'error'事件回调
console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`);
});
-audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp4'; //设置src属性,并触发'dataLoad'事件回调
+
+// 用户选择视频设置fd(本地播放)
+let fdPath = 'fd://'
+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);
+}, (err) => {
+ console.info('open fd failed err is' + err);
+}),catch((err) => {
+ console.info('open fd failed err is' + err);
+});
+audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
```
### on('timeUpdate')
@@ -714,7 +620,7 @@ audioPlayer.setVolume(3); //设置volume为无效值,触发'error'事件
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ |
-| url | string | 是 | 是 | 视频媒体URL,支持当前主流的视频格式(mp4、mpeg-ts、webm、mkv)。
**支持路径示例**:
1. 本地绝对路径:file:///data/data/ohos.xxx.xxx/files/test.mp4
![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)
**注意事项**:
媒体素材需至少赋予读权限后,才可正常播放 |
+| url | string | 是 | 是 | 视频媒体URL,支持当前主流的视频格式(mp4、mpeg-ts、webm、mkv)。
**支持路径示例**:
1. fd类型播放:fd://xxx
![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)
**注意事项**:
媒体素材需至少赋予读权限后,才可正常播放 |
| loop | boolean | 是 | 是 | 视频循环播放属性,设置为'true'表示循环播放。 |
| currentTime | number | 是 | 否 | 视频的当前播放位置。 |
| duration | number | 是 | 否 | 视频时长,返回-1表示直播模式 |
@@ -1530,7 +1436,7 @@ audioPlayer.getTrackDescription((error, arrlist) => {
## AudioRecorder
-音频录制管理类,用于录制音频媒体。在调用AudioRecorder的方法前,需要先通过[createAudioRecorder()](#media.createaudiorecorder) 或[createAudioRecorderAsync()](#media.createaudiorecorderasync8)构建一个[AudioRecorder](#audiorecorder)实例。
+音频录制管理类,用于录制音频媒体。在调用AudioRecorder的方法前,需要先通过[createAudioRecorder()](#media.createaudiorecorder) 构建一个[AudioRecorder](#audiorecorder)实例。
音频录制demo可参考:[音频录制开发指导](../../media/audio-recorder.md)
@@ -1555,7 +1461,7 @@ let audioRecorderConfig = {
audioSampleRate : 22050,
numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS,
- uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', // 文件需先由调用者创建,并给予适当的权限
+ uri : 'fd://1', // 文件需先由调用者创建,并给予适当的权限
location : { latitude : 30, longitude : 130},
}
audioRecorder.on('prepare', () => { //设置'prepare'事件回调
@@ -1681,7 +1587,7 @@ let audioRecorderConfig = {
audioSampleRate : 22050,
numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS,
- uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', // 文件需先由调用者创建,并给予适当的权限
+ uri : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限
location : { latitude : 30, longitude : 130},
}
audioRecorder.on('error', (error) => { // 设置'error'事件回调
@@ -1750,7 +1656,7 @@ audioRecorder.prepare(); // prepare不设置参数,触发'error'
| numberOfChannels | number | 否 | 音频采集声道数,默认值为2。 |
| format | [AudioOutputFormat](#audiooutputformat) | 否 | 音量输出封装格式,默认设置为MPEG_4。 |
| location8+ | [Location](#location8) | 否 | 音频采集的地理位置。 |
-| uri | string | 是 | 音频输出URI。支持:
1. 文件的绝对路径:file:///data/data/ohos.xxx.xxx/cache/test.mp4![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)
2. 文件的fd路径:file://1 (fd number)
文件需要由调用者创建,并赋予适当的权限。 |
+| uri | string | 是 | 视频输出URI:fd://xx (fd number)
![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)
文件需要由调用者创建,并赋予适当的权限。 |
## AudioEncoder
@@ -1780,7 +1686,7 @@ audioRecorder.prepare(); // prepare不设置参数,触发'error'
## VideoRecorder8+
-视频录制管理类,用于录制视频媒体。在调用VideoRecorder的方法前,需要先通过[createVideoRecorderAsync()](#media.createvideorecorderasync8)构建一个[VideoRecorder](#videorecorder8)实例。
+视频录制管理类,用于录制视频媒体。在调用VideoRecorder的方法前,需要先通过[createVideoRecorder()](#media.createvideorecorder8)构建一个[VideoRecorder](#videorecorder8)实例。
视频录制demo可参考:[视频录制开发指导](../../media/video-recorder.md)
@@ -1823,7 +1729,7 @@ let videoConfig = {
audioSourceType : 1,
videoSourceType : 0,
profile : videoProfile,
- url : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.mp4', // 文件需先由调用者创建,并给予适当的权限
+ url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限
orientationHint : 0,
location : { latitude : 30, longitude : 130 },
}
@@ -1892,7 +1798,7 @@ let videoConfig = {
audioSourceType : 1,
videoSourceType : 0,
profile : videoProfile,
- url : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.mp4', // 文件需先由调用者创建,并给予适当的权限
+ url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限
orientationHint : 0,
location : { latitude : 30, longitude : 130 },
}
@@ -2347,7 +2253,7 @@ videoRecorder.on('error', (error) => { // 设置'error'事件回调
| profile | [VideoRecorderProfile](#videorecorderprofile8+) | 是 | 视频录制的profile。 |
| orientationHint | number | 否 | 录制视频的旋转角度。 |
| location | [Location](#location8) | 否 | 录制视频的地理位置。 |
-| uri | string | 是 | 视频输出URI。支持:
1. 文件的绝对路径:file:///data/data/ohos.xxx.xxx/cache/test.mp4![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)
2. 文件的fd路径:file://1 (fd number)
文件需要由调用者创建,并赋予适当的权限。 |
+| url | string | 是 | 视频输出URL:fd://xx (fd number)
![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)
文件需要由调用者创建,并赋予适当的权限。 |
## AudioSourceType8+