| timeMs | number | Yes | Position to seek to, in ms. The value range is [0, [duration](#avplayer_duration)].|
| mode | [SeekMode](#seekmode8) | No | Seek mode based on the video I frame. **Set this parameter only for video playback.**|
| mode | [SeekMode](#seekmode8) | No | Seek mode based on the video I frame. The default value is **SEEK_PREV_SYNC**. **Set this parameter only for video playback.**|
**Example**
...
...
@@ -1042,7 +1042,7 @@ Subscribes to the event to check whether the seek operation takes effect.
```js
avPlayer.on('seekDone',(seekDoneTime:number)=>{
console.info('seekDone success,and seek time is:'+seekDoneTime)
console.info('seekDone success,and seek time is:'+seekDoneTime)
})
```
...
...
@@ -1105,7 +1105,7 @@ Subscribes to the event to check whether the playback speed is successfully set.
```js
avPlayer.on('speedDone',(speed:number)=>{
console.info('speedDone success,and speed value is:'+speed)
console.info('speedDone success,and speed value is:'+speed)
})
```
...
...
@@ -1169,7 +1169,7 @@ Subscribes to the event to check whether the bit rate is successfully set.
```js
avPlayer.on('bitrateDone',(bitrate:number)=>{
console.info('bitrateDone success,and bitrate value is:'+bitrate)
console.info('bitrateDone success,and bitrate value is:'+bitrate)
})
```
...
...
@@ -1212,7 +1212,7 @@ Subscribes to available bit rates of HLS streams. This event is reported only af
console.info('audioInterrupt success,and InterruptEvent info is:'+info)
console.info('audioInterrupt success,and InterruptEvent info is:'+info)
})
```
...
...
@@ -1680,19 +1680,19 @@ Defines media information in key-value mode.
```js
importmediafrom'@ohos.multimedia.media'
functionprintfItemDescription(obj,key){
letproperty=obj[key];
console.info('audio key is '+key);// Specify a key. For details about the keys, see [MediaDescriptionKey].
console.info('audio value is '+property);// Obtain the value of the key. The value can be any type. For details about the types, see [MediaDescriptionKey].
letproperty=obj[key];
console.info('audio key is '+key);// Specify a key. For details about the keys, see [MediaDescriptionKey].
console.info('audio value is '+property);// Obtain the value of the key. The value can be any type. For details about the types, see [MediaDescriptionKey].
url:'fd://',// Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45.
rotation:0,// The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
url:'fd://',// Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45.
rotation:0,// The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
location:{latitude:30,longitude:130}
}
avRecorder.prepare(AVRecorderConfig,(err)=>{
if(err==null){
console.info('prepare success');
}else{
console.info('prepare failed and error is '+err.message);
}
if(err==null){
console.info('prepare success');
}else{
console.error('prepare failed and error is '+err.message);
}
})
```
...
...
@@ -1818,30 +1818,30 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
// Configure the parameters based on those supported by the hardware device.
url:'fd://',// Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45.
rotation:0,// The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
url:'fd://',// Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45.
rotation:0,// The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
location:{latitude:30,longitude:130}
}
avRecorder.prepare(AVRecorderConfig).then(()=>{
console.info('prepare success');
console.info('prepare success');
}).catch((err)=>{
console.info('prepare failed and catch error is '+err.message);
console.error('prepare failed and catch error is '+err.message);
});
```
...
...
@@ -1880,12 +1880,12 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
letsurfaceID=null;// The surfaceID is transferred to the camera API to create a videoOutput instance.
avRecorder.getInputSurface((err,surfaceId)=>{
if(err==null){
console.info('getInputSurface success');
surfaceID=surfaceId;
}else{
console.info('getInputSurface failed and error is '+err.message);
}
if(err==null){
console.info('getInputSurface success');
surfaceID=surfaceId;
}else{
console.error('getInputSurface failed and error is '+err.message);
}
});
```
...
...
@@ -1924,10 +1924,10 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
letsurfaceID=null;// The surfaceID is transferred to the camera API to create a videoOutput instance.
avRecorder.getInputSurface().then((surfaceId)=>{
console.info('getInputSurface success');
surfaceID=surfaceId;
console.info('getInputSurface success');
surfaceID=surfaceId;
}).catch((err)=>{
console.info('getInputSurface failed and catch error is '+err.message);
console.error('getInputSurface failed and catch error is '+err.message);
});
```
...
...
@@ -1961,11 +1961,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.start((err)=>{
if(err==null){
console.info('start AVRecorder success');
}else{
console.info('start AVRecorder failed and error is '+err.message);
}
if(err==null){
console.info('start AVRecorder success');
}else{
console.error('start AVRecorder failed and error is '+err.message);
}
});
```
...
...
@@ -1999,9 +1999,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.start().then(()=>{
console.info('start AVRecorder success');
console.info('start AVRecorder success');
}).catch((err)=>{
console.info('start AVRecorder failed and catch error is '+err.message);
console.error('start AVRecorder failed and catch error is '+err.message);
});
```
...
...
@@ -2035,11 +2035,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.pause((err)=>{
if(err==null){
console.info('pause AVRecorder success');
}else{
console.info('pause AVRecorder failed and error is '+err.message);
}
if(err==null){
console.info('pause AVRecorder success');
}else{
console.error('pause AVRecorder failed and error is '+err.message);
}
});
```
...
...
@@ -2073,9 +2073,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.pause().then(()=>{
console.info('pause AVRecorder success');
console.info('pause AVRecorder success');
}).catch((err)=>{
console.info('pause AVRecorder failed and catch error is '+err.message);
console.error('pause AVRecorder failed and catch error is '+err.message);
});
```
...
...
@@ -2109,11 +2109,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.resume((err)=>{
if(err==null){
console.info('resume AVRecorder success');
}else{
console.info('resume AVRecorder failed and error is '+err.message);
}
if(err==null){
console.info('resume AVRecorder success');
}else{
console.error('resume AVRecorder failed and error is '+err.message);
}
});
```
...
...
@@ -2147,9 +2147,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.resume().then(()=>{
console.info('resume AVRecorder success');
console.info('resume AVRecorder success');
}).catch((err)=>{
console.info('resume AVRecorder failed and catch error is '+err.message);
console.error('resume AVRecorder failed and catch error is '+err.message);
});
```
...
...
@@ -2185,11 +2185,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.stop((err)=>{
if(err==null){
console.info('stop AVRecorder success');
}else{
console.info('stop AVRecorder failed and error is '+err.message);
}
if(err==null){
console.info('stop AVRecorder success');
}else{
console.error('stop AVRecorder failed and error is '+err.message);
}
});
```
...
...
@@ -2225,9 +2225,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.stop().then(()=>{
console.info('stop AVRecorder success');
console.info('stop AVRecorder success');
}).catch((err)=>{
console.info('stop AVRecorder failed and catch error is '+err.message);
console.error('stop AVRecorder failed and catch error is '+err.message);
});
```
...
...
@@ -2260,11 +2260,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.reset((err)=>{
if(err==null){
console.info('reset AVRecorder success');
}else{
console.info('reset AVRecorder failed and error is '+err.message);
}
if(err==null){
console.info('reset AVRecorder success');
}else{
console.error('reset AVRecorder failed and error is '+err.message);
}
});
```
...
...
@@ -2297,9 +2297,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.reset().then(()=>{
console.info('reset AVRecorder success');
console.info('reset AVRecorder success');
}).catch((err)=>{
console.info('reset AVRecorder failed and catch error is '+err.message);
console.error('reset AVRecorder failed and catch error is '+err.message);
});
```
...
...
@@ -2331,11 +2331,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.release((err)=>{
if(err==null){
console.info('release AVRecorder success');
}else{
console.info('release AVRecorder failed and error is '+err.message);
}
if(err==null){
console.info('release AVRecorder success');
}else{
console.error('release AVRecorder failed and error is '+err.message);
}
});
```
...
...
@@ -2367,9 +2367,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
avRecorder.release().then(()=>{
console.info('release AVRecorder success');
console.info('release AVRecorder success');
}).catch((err)=>{
console.info('release AVRecorder failed and catch error is '+err.message);
console.error('release AVRecorder failed and catch error is '+err.message);
});
```
...
...
@@ -2392,7 +2392,7 @@ Subscribes to AVRecorder state changes. An application can subscribe to only one
| rotation | number | No | Rotation angle of the recorded video. The value can only be 0, 90, 180, or 270. |
| location | [Location](#location) | No | Geographical location of the recorded video. |
| rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. |
| location | [Location](#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded. |
The **audioSourceType** and **videoSourceType** parameters are used to distinguish audio-only recording, video-only recording, and audio and video recording. For audio-only recording, set only **audioSourceType**. For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**.
...
...
@@ -2628,34 +2628,34 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
// Configure the parameters based on those supported by the hardware device.
letvideoProfile={
audioBitrate:48000,
audioChannels:2,
audioCodec:'audio/mp4a-latm',
audioSampleRate:48000,
fileFormat:'mp4',
videoBitrate:2000000,
videoCodec:'video/avc',
videoFrameWidth:640,
videoFrameHeight:480,
videoFrameRate:30
audioBitrate:48000,
audioChannels:2,
audioCodec:'audio/mp4a-latm',
audioSampleRate:48000,
fileFormat:'mp4',
videoBitrate:2000000,
videoCodec:'video/avc',
videoFrameWidth:640,
videoFrameHeight:480,
videoFrameRate:30
}
letvideoConfig={
audioSourceType:1,
videoSourceType:0,
profile:videoProfile,
url:'fd://xx',// The file must be created by the caller and granted with proper permissions.
orientationHint:0,
location:{latitude:30,longitude:130},
audioSourceType:1,
videoSourceType:0,
profile:videoProfile,
url:'fd://xx',// The file must be created by the caller and granted with proper permissions.
orientationHint:0,
location:{latitude:30,longitude:130},
}
// asyncallback
videoRecorder.prepare(videoConfig,(err)=>{
if(err==null){
console.info('prepare success');
}else{
console.info('prepare failed and error is '+err.message);
}
if(err==null){
console.info('prepare success');
}else{
console.error('prepare failed and error is '+err.message);
}
})
```
...
...
@@ -2699,32 +2699,32 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
```js
// Configure the parameters based on those supported by the hardware device.
letvideoProfile={
audioBitrate:48000,
audioChannels:2,
audioCodec:'audio/mp4a-latm',
audioSampleRate:48000,
fileFormat:'mp4',
videoBitrate:2000000,
videoCodec:'video/avc',
videoFrameWidth:640,
videoFrameHeight:480,
videoFrameRate:30
audioBitrate:48000,
audioChannels:2,
audioCodec:'audio/mp4a-latm',
audioSampleRate:48000,
fileFormat:'mp4',
videoBitrate:2000000,
videoCodec:'video/avc',
videoFrameWidth:640,
videoFrameHeight:480,
videoFrameRate:30
}
letvideoConfig={
audioSourceType:1,
videoSourceType:0,
profile:videoProfile,
url:'fd://xx',// The file must be created by the caller and granted with proper permissions.
orientationHint:0,
location:{latitude:30,longitude:130},
audioSourceType:1,
videoSourceType:0,
profile:videoProfile,
url:'fd://xx',// The file must be created by the caller and granted with proper permissions.
orientationHint:0,
location:{latitude:30,longitude:130},
}
// promise
videoRecorder.prepare(videoConfig).then(()=>{
console.info('prepare success');
console.info('prepare success');
}).catch((err)=>{
console.info('prepare failed and catch error is '+err.message);
console.error('prepare failed and catch error is '+err.message);
});
```
...
...
@@ -2764,12 +2764,12 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
// asyncallback
letsurfaceID=null;// Surface ID passed to the external system.
videoRecorder.getInputSurface((err,surfaceId)=>{
if(err==null){
console.info('getInputSurface success');
surfaceID=surfaceId;
}else{
console.info('getInputSurface failed and error is '+err.message);
}
if(err==null){
console.info('getInputSurface success');
surfaceID=surfaceId;
}else{
console.error('getInputSurface failed and error is '+err.message);
}
});
```
...
...
@@ -2809,10 +2809,10 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco
// promise
letsurfaceID=null;// Surface ID passed to the external system.
| rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. |
| location | [Location](#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded. |