未验证 提交 75d49fd4 编写于 作者: O openharmony_ci 提交者: Gitee

!1688 资料修改

Merge pull request !1688 from hwgaizw/226_4
......@@ -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
......@@ -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)
......
......@@ -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里面需要添加如下代码
<xcomponent id = 'Xcomponent'
if = "{{isFlush}}" // 刷新surfaceID,isFlush赋值false再赋值true为一次刷新,会主动再次加载LoadXcomponet获取新的surfaceID
type = 'surface'
onload = 'LoadXcomponet' // 默认加载接口
style = "wodth:720px;height:480px;border-color:red;border-width:5px;"> // 设置窗口宽高等属性
</xcomponent>
```
......@@ -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');
......
......@@ -34,64 +34,7 @@ createAudioPlayer(): [AudioPlayer](#audioplayer)
**示例:**
```js
var audioPlayer = media.createAudioPlayer();
```
## media.createAudioPlayerAsync<sup>8+</sup>
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.createAudioPlayerAsync<sup>8+</sup>
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.createVideoPlayer<sup>8+</sup>
......@@ -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.createAudioRecorderAsync<sup>8+</sup>
## media.createVideoRecorder<sup>8+</sup>
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.createAudioRecorderAsync<sup>8+</sup>
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.createVideoRecorderAsync<sup>8+</sup>
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.createVideoRecorderAsync<sup>8+</sup>
## media.createVideoRecorder<sup>8+</sup>
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)。<br>**支持路径示例**<br>1、本地绝对路径:file:///data/data/ohos.xxx.xxx/files/test.mp4<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)<br>2、http网络播放路径:开发中<br>3、hls网络播放路径:开发中<br>4、fd类型播放:开发中<br>**注意事项**<br>媒体素材需至少赋予读权限后,才可正常播放 |
| src | string | 是 | 是 | 音频媒体URI,支持当前主流的音频格式(mp4、aac、mp3、ogg)。<br>**支持路径示例**<br>1、fd类型播放:fd://xxx<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)<br>2、http网络播放路径:开发中<br>3、hls网络播放路径:开发中<br>**注意事项**<br>媒体素材需至少赋予读权限后,才可正常播放 |
| 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)。<br>**支持路径示例**<br>1. 本地绝对路径:file:///data/data/ohos.xxx.xxx/files/test.mp4<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)<br>**注意事项**<br>媒体素材需至少赋予读权限后,才可正常播放 |
| url | string | 是 | 是 | 视频媒体URL,支持当前主流的视频格式(mp4、mpeg-ts、webm、mkv)。<br>**支持路径示例**<br>1. fd类型播放:fd://xxx<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)<br>**注意事项**<br>媒体素材需至少赋予读权限后,才可正常播放 |
| 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。 |
| location<sup>8+</sup> | [Location](#location8) | 否 | 音频采集的地理位置。 |
| uri | string | 是 | 音频输出URI。支持:<br/>1.&nbsp;文件的绝对路径:file:///data/data/ohos.xxx.xxx/cache/test.mp4![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)<br/>2.&nbsp;文件的fd路径:file://1&nbsp;(fd&nbsp;number)<br/> 文件需要由调用者创建,并赋予适当的权限。 |
| uri | string | 是 | 视频输出URI:fd://xx&nbsp;(fd&nbsp;number)<br/>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。 |
## AudioEncoder
......@@ -1780,7 +1686,7 @@ audioRecorder.prepare(); // prepare不设置参数,触发'error'
## VideoRecorder<sup>8+</sup>
视频录制管理类,用于录制视频媒体。在调用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](#videorecorderprofile<sup>8+</sup>) | 是 | 视频录制的profile。 |
| orientationHint | number | 否 | 录制视频的旋转角度。 |
| location | [Location](#location8) | 否 | 录制视频的地理位置。 |
| uri | string | 是 | 视频输出URI。支持:<br/>1.&nbsp;文件的绝对路径:file:///data/data/ohos.xxx.xxx/cache/test.mp4![zh-cn_image_0000001164217678](figures/zh-cn_image_0000001164217678.png)<br/>2.&nbsp;文件的fd路径:file://1&nbsp;(fd&nbsp;number)<br/> 文件需要由调用者创建,并赋予适当的权限。 |
| url | string | 是 | 视频输出URL:fd://xx&nbsp;(fd&nbsp;number)<br/>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。 |
## AudioSourceType<sup>8+</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册