提交 5fa4bb96 编写于 作者: F flz

modify file in master Signed-off-by: FULIZHONG<fulizhong1@huawei.com>

Signed-off-by: Nflz <fulizhong1@huawei.com>
上级 e004da84
...@@ -44,10 +44,11 @@ createAVPlayer(callback: AsyncCallback\<AVPlayer>): void ...@@ -44,10 +44,11 @@ createAVPlayer(callback: AsyncCallback\<AVPlayer>): void
**示例:** **示例:**
```js ```ts
let avPlayer; import { BusinessError } from '@ohos.base';
media.createAVPlayer((error, video) => { let avPlayer: media.AVPlayer;
media.createAVPlayer((error: BusinessError, video: media.AVPlayer) => {
if (video != null) { if (video != null) {
avPlayer = video; avPlayer = video;
console.info('createAVPlayer success'); console.info('createAVPlayer success');
...@@ -81,17 +82,18 @@ createAVPlayer(): Promise\<AVPlayer> ...@@ -81,17 +82,18 @@ createAVPlayer(): Promise\<AVPlayer>
**示例:** **示例:**
```js ```ts
let avPlayer; import { BusinessError } from '@ohos.base';
media.createAVPlayer().then((video) => { let avPlayer: media.AVPlayer;
media.createAVPlayer().then((video: media.AVPlayer) => {
if (video != null) { if (video != null) {
avPlayer = video; avPlayer = video;
console.info('createAVPlayer success'); console.info('createAVPlayer success');
} else { } else {
console.error('createAVPlayer fail'); console.error('createAVPlayer fail');
} }
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`AVPlayer catchCallback, error message:${error.message}`); console.error(`AVPlayer catchCallback, error message:${error.message}`);
}); });
``` ```
...@@ -394,8 +396,8 @@ on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReas ...@@ -394,8 +396,8 @@ on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReas
**示例:** **示例:**
```js ```ts
avPlayer.on('stateChange', async (state, reason) => { avPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => {
switch (state) { switch (state) {
case 'idle': case 'idle':
console.info('state idle called') console.info('state idle called')
...@@ -447,7 +449,7 @@ off(type: 'stateChange'): void ...@@ -447,7 +449,7 @@ off(type: 'stateChange'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('stateChange') avPlayer.off('stateChange')
``` ```
...@@ -482,8 +484,8 @@ AVPlayer回调的**错误分类**<a name = error_info></a>可以分为以下几 ...@@ -482,8 +484,8 @@ AVPlayer回调的**错误分类**<a name = error_info></a>可以分为以下几
**示例:** **示例:**
```js ```ts
avPlayer.on('error', (error) => { avPlayer.on('error', (error: BusinessError) => {
console.error('error happened,and error message is :' + error.message) console.error('error happened,and error message is :' + error.message)
console.error('error happened,and error code is :' + error.code) console.error('error happened,and error code is :' + error.code)
}) })
...@@ -505,7 +507,7 @@ off(type: 'error'): void ...@@ -505,7 +507,7 @@ off(type: 'error'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('error') avPlayer.off('error')
``` ```
...@@ -534,8 +536,8 @@ prepare(callback: AsyncCallback\<void>): void ...@@ -534,8 +536,8 @@ prepare(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.prepare((err) => { avPlayer.prepare((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('prepare success'); console.info('prepare success');
} else { } else {
...@@ -569,10 +571,10 @@ prepare(): Promise\<void> ...@@ -569,10 +571,10 @@ prepare(): Promise\<void>
**示例:** **示例:**
```js ```ts
avPlayer.prepare().then(() => { avPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}, (err) => { }, (err: BusinessError) => {
console.error('prepare filed,error message is :' + err.message) console.error('prepare filed,error message is :' + err.message)
}) })
``` ```
...@@ -601,8 +603,8 @@ play(callback: AsyncCallback\<void>): void ...@@ -601,8 +603,8 @@ play(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.play((err) => { avPlayer.play((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('play success'); console.info('play success');
} else { } else {
...@@ -635,10 +637,10 @@ play(): Promise\<void> ...@@ -635,10 +637,10 @@ play(): Promise\<void>
**示例:** **示例:**
```js ```ts
avPlayer.play().then(() => { avPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}, (err) => { }, (err: BusinessError) => {
console.error('play filed,error message is :' + err.message) console.error('play filed,error message is :' + err.message)
}) })
``` ```
...@@ -667,8 +669,8 @@ pause(callback: AsyncCallback\<void>): void ...@@ -667,8 +669,8 @@ pause(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.pause((err) => { avPlayer.pause((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('pause success'); console.info('pause success');
} else { } else {
...@@ -701,10 +703,10 @@ pause(): Promise\<void> ...@@ -701,10 +703,10 @@ pause(): Promise\<void>
**示例:** **示例:**
```js ```ts
avPlayer.pause().then(() => { avPlayer.pause().then(() => {
console.info('pause success'); console.info('pause success');
}, (err) => { }, (err: BusinessError) => {
console.error('pause filed,error message is :' + err.message) console.error('pause filed,error message is :' + err.message)
}) })
``` ```
...@@ -733,8 +735,8 @@ stop(callback: AsyncCallback\<void>): void ...@@ -733,8 +735,8 @@ stop(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.stop((err) => { avPlayer.stop((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('stop success'); console.info('stop success');
} else { } else {
...@@ -767,10 +769,10 @@ stop(): Promise\<void> ...@@ -767,10 +769,10 @@ stop(): Promise\<void>
**示例:** **示例:**
```js ```ts
avPlayer.stop().then(() => { avPlayer.stop().then(() => {
console.info('stop success'); console.info('stop success');
}, (err) => { }, (err: BusinessError) => {
console.error('stop filed,error message is :' + err.message) console.error('stop filed,error message is :' + err.message)
}) })
``` ```
...@@ -799,8 +801,8 @@ reset(callback: AsyncCallback\<void>): void ...@@ -799,8 +801,8 @@ reset(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.reset((err) => { avPlayer.reset((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('reset success'); console.info('reset success');
} else { } else {
...@@ -833,10 +835,10 @@ reset(): Promise\<void> ...@@ -833,10 +835,10 @@ reset(): Promise\<void>
**示例:** **示例:**
```js ```ts
avPlayer.reset().then(() => { avPlayer.reset().then(() => {
console.info('reset success'); console.info('reset success');
}, (err) => { }, (err: BusinessError) => {
console.error('reset filed,error message is :' + err.message) console.error('reset filed,error message is :' + err.message)
}) })
``` ```
...@@ -865,8 +867,8 @@ release(callback: AsyncCallback\<void>): void ...@@ -865,8 +867,8 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.release((err) => { avPlayer.release((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('reset success'); console.info('reset success');
} else { } else {
...@@ -899,10 +901,10 @@ release(): Promise\<void> ...@@ -899,10 +901,10 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```ts
avPlayer.release().then(() => { avPlayer.release().then(() => {
console.info('release success'); console.info('release success');
}, (err) => { }, (err: BusinessError) => {
console.error('release filed,error message is :' + err.message) console.error('release filed,error message is :' + err.message)
}) })
``` ```
...@@ -931,20 +933,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void ...@@ -931,20 +933,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
**示例:** **示例:**
```js ```ts
function printfDescription(obj) { avPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
for (let item in obj) {
let property = obj[item];
console.info('audio key is ' + item);
console.info('audio value is ' + property);
}
}
avPlayer.getTrackDescription((error, arrList) => {
if ((arrList) != null) { if ((arrList) != null) {
for (let i = 0; i < arrList.length; i++) { console.info('getTrackDescription success');
printfDescription(arrList[i]);
}
} else { } else {
console.log(`video getTrackDescription fail, error:${error}`); console.log(`video getTrackDescription fail, error:${error}`);
} }
...@@ -975,28 +967,12 @@ getTrackDescription(): Promise\<Array\<MediaDescription>> ...@@ -975,28 +967,12 @@ getTrackDescription(): Promise\<Array\<MediaDescription>>
**示例:** **示例:**
```js ```ts
let arrayDescription; avPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => {
console.info('getTrackDescription success');
function printfDescription(obj) { }).catch((error: BusinessError) => {
for (let item in obj) {
let property = obj[item];
console.info('audio key is ' + item);
console.info('audio value is ' + property);
}
}
avPlayer.getTrackDescription().then((arrList) => {
if (arrList != null) {
arrayDescription = arrList;
} else {
console.log('video getTrackDescription fail');
}
}).catch((error) => {
console.info(`video catchCallback, error:${error}`); console.info(`video catchCallback, error:${error}`);
}); });
for (let i = 0; i < arrayDescription.length; i++) {
printfDescription(arrayDescription[i]);
}
``` ```
### seek<sup>9+</sup><a name=avplayer_seek></a> ### seek<sup>9+</sup><a name=avplayer_seek></a>
...@@ -1017,8 +993,8 @@ seek(timeMs: number, mode?:SeekMode): void ...@@ -1017,8 +993,8 @@ seek(timeMs: number, mode?:SeekMode): void
**示例:** **示例:**
```js ```ts
let seekTime = 1000 let seekTime: number = 1000
avPlayer.seek(seekTime, media.SeekMode.SEEK_PREV_SYNC) avPlayer.seek(seekTime, media.SeekMode.SEEK_PREV_SYNC)
``` ```
...@@ -1039,7 +1015,7 @@ on(type: 'seekDone', callback: Callback\<number>): void ...@@ -1039,7 +1015,7 @@ on(type: 'seekDone', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('seekDone', (seekDoneTime:number) => { avPlayer.on('seekDone', (seekDoneTime:number) => {
console.info('seekDone success,and seek time is:' + seekDoneTime) console.info('seekDone success,and seek time is:' + seekDoneTime)
}) })
...@@ -1061,7 +1037,7 @@ off(type: 'seekDone'): void ...@@ -1061,7 +1037,7 @@ off(type: 'seekDone'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('seekDone') avPlayer.off('seekDone')
``` ```
...@@ -1082,7 +1058,7 @@ setSpeed(speed: PlaybackSpeed): void ...@@ -1082,7 +1058,7 @@ setSpeed(speed: PlaybackSpeed): void
**示例:** **示例:**
```js ```ts
avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X) avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X)
``` ```
...@@ -1103,7 +1079,7 @@ on(type: 'speedDone', callback: Callback\<number>): void ...@@ -1103,7 +1079,7 @@ on(type: 'speedDone', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('speedDone', (speed:number) => { avPlayer.on('speedDone', (speed:number) => {
console.info('speedDone success,and speed value is:' + speed) console.info('speedDone success,and speed value is:' + speed)
}) })
...@@ -1125,7 +1101,7 @@ off(type: 'speedDone'): void ...@@ -1125,7 +1101,7 @@ off(type: 'speedDone'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('speedDone') avPlayer.off('speedDone')
``` ```
...@@ -1145,8 +1121,8 @@ setBitrate(bitrate: number): void ...@@ -1145,8 +1121,8 @@ setBitrate(bitrate: number): void
**示例:** **示例:**
```js ```ts
let bitrate = 96000 let bitrate: number = 96000
avPlayer.setBitrate(bitrate) avPlayer.setBitrate(bitrate)
``` ```
...@@ -1167,7 +1143,7 @@ on(type: 'bitrateDone', callback: Callback\<number>): void ...@@ -1167,7 +1143,7 @@ on(type: 'bitrateDone', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('bitrateDone', (bitrate:number) => { avPlayer.on('bitrateDone', (bitrate:number) => {
console.info('bitrateDone success,and bitrate value is:' + bitrate) console.info('bitrateDone success,and bitrate value is:' + bitrate)
}) })
...@@ -1189,7 +1165,7 @@ off(type: 'bitrateDone'): void ...@@ -1189,7 +1165,7 @@ off(type: 'bitrateDone'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('bitrateDone') avPlayer.off('bitrateDone')
``` ```
...@@ -1210,7 +1186,7 @@ on(type: 'availableBitrates', callback: (bitrates: Array\<number>) => void): voi ...@@ -1210,7 +1186,7 @@ on(type: 'availableBitrates', callback: (bitrates: Array\<number>) => void): voi
**示例:** **示例:**
```js ```ts
avPlayer.on('availableBitrates', (bitrates: Array<number>) => { avPlayer.on('availableBitrates', (bitrates: Array<number>) => {
console.info('availableBitrates success,and availableBitrates length is:' + bitrates.length) console.info('availableBitrates success,and availableBitrates length is:' + bitrates.length)
}) })
...@@ -1232,7 +1208,7 @@ off(type: 'availableBitrates'): void ...@@ -1232,7 +1208,7 @@ off(type: 'availableBitrates'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('availableBitrates') avPlayer.off('availableBitrates')
``` ```
...@@ -1252,8 +1228,8 @@ setVolume(volume: number): void ...@@ -1252,8 +1228,8 @@ setVolume(volume: number): void
**示例:** **示例:**
```js ```ts
let volume = 1.0 let volume: number = 1.0
avPlayer.setVolume(volume) avPlayer.setVolume(volume)
``` ```
...@@ -1274,8 +1250,8 @@ on(type: 'volumeChange', callback: Callback\<number>): void ...@@ -1274,8 +1250,8 @@ on(type: 'volumeChange', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('volumeChange', (vol:number) => { avPlayer.on('volumeChange', (vol: number) => {
console.info('volumeChange success,and new volume is :' + vol) console.info('volumeChange success,and new volume is :' + vol)
}) })
``` ```
...@@ -1296,7 +1272,7 @@ off(type: 'volumeChange'): void ...@@ -1296,7 +1272,7 @@ off(type: 'volumeChange'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('volumeChange') avPlayer.off('volumeChange')
``` ```
...@@ -1317,7 +1293,7 @@ on(type: 'endOfStream', callback: Callback\<void>): void ...@@ -1317,7 +1293,7 @@ on(type: 'endOfStream', callback: Callback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('endOfStream', () => { avPlayer.on('endOfStream', () => {
console.info('endOfStream success') console.info('endOfStream success')
}) })
...@@ -1339,7 +1315,7 @@ off(type: 'endOfStream'): void ...@@ -1339,7 +1315,7 @@ off(type: 'endOfStream'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('endOfStream') avPlayer.off('endOfStream')
``` ```
...@@ -1361,7 +1337,7 @@ on(type: 'timeUpdate', callback: Callback\<number>): void ...@@ -1361,7 +1337,7 @@ on(type: 'timeUpdate', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('timeUpdate', (time:number) => { avPlayer.on('timeUpdate', (time:number) => {
console.info('timeUpdate success,and new time is :' + time) console.info('timeUpdate success,and new time is :' + time)
}) })
...@@ -1383,7 +1359,7 @@ off(type: 'timeUpdate'): void ...@@ -1383,7 +1359,7 @@ off(type: 'timeUpdate'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('timeUpdate') avPlayer.off('timeUpdate')
``` ```
...@@ -1405,8 +1381,8 @@ on(type: 'durationUpdate', callback: Callback\<number>): void ...@@ -1405,8 +1381,8 @@ on(type: 'durationUpdate', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('durationUpdate', (duration) => { avPlayer.on('durationUpdate', (duration: number) => {
console.info('durationUpdate success,new duration is :' + duration) console.info('durationUpdate success,new duration is :' + duration)
}) })
``` ```
...@@ -1427,7 +1403,7 @@ off(type: 'durationUpdate'): void ...@@ -1427,7 +1403,7 @@ off(type: 'durationUpdate'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('durationUpdate') avPlayer.off('durationUpdate')
``` ```
...@@ -1448,7 +1424,7 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe ...@@ -1448,7 +1424,7 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe
**示例:** **示例:**
```js ```ts
avPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => { avPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => {
console.info('bufferingUpdate success,and infoType value is:' + infoType + ', value is :' + value) console.info('bufferingUpdate success,and infoType value is:' + infoType + ', value is :' + value)
}) })
...@@ -1470,7 +1446,7 @@ off(type: 'bufferingUpdate'): void ...@@ -1470,7 +1446,7 @@ off(type: 'bufferingUpdate'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('bufferingUpdate') avPlayer.off('bufferingUpdate')
``` ```
...@@ -1491,7 +1467,7 @@ on(type: 'startRenderFrame', callback: Callback\<void>): void ...@@ -1491,7 +1467,7 @@ on(type: 'startRenderFrame', callback: Callback\<void>): void
**示例:** **示例:**
```js ```ts
avPlayer.on('startRenderFrame', () => { avPlayer.on('startRenderFrame', () => {
console.info('startRenderFrame success') console.info('startRenderFrame success')
}) })
...@@ -1513,7 +1489,7 @@ off(type: 'startRenderFrame'): void ...@@ -1513,7 +1489,7 @@ off(type: 'startRenderFrame'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('startRenderFrame') avPlayer.off('startRenderFrame')
``` ```
...@@ -1534,7 +1510,7 @@ on(type: 'videoSizeChange', callback: (width: number, height: number) => void): ...@@ -1534,7 +1510,7 @@ on(type: 'videoSizeChange', callback: (width: number, height: number) => void):
**示例:** **示例:**
```js ```ts
avPlayer.on('videoSizeChange', (width: number, height: number) => { avPlayer.on('videoSizeChange', (width: number, height: number) => {
console.info('videoSizeChange success,and width is:' + width + ', height is :' + height) console.info('videoSizeChange success,and width is:' + width + ', height is :' + height)
}) })
...@@ -1556,7 +1532,7 @@ off(type: 'videoSizeChange'): void ...@@ -1556,7 +1532,7 @@ off(type: 'videoSizeChange'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('videoSizeChange') avPlayer.off('videoSizeChange')
``` ```
...@@ -1577,7 +1553,7 @@ on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void ...@@ -1577,7 +1553,7 @@ on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void
**示例:** **示例:**
```js ```ts
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
avPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => { avPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => {
...@@ -1601,7 +1577,7 @@ off(type: 'audioInterrupt'): void ...@@ -1601,7 +1577,7 @@ off(type: 'audioInterrupt'): void
**示例:** **示例:**
```js ```ts
avPlayer.off('audioInterrupt') avPlayer.off('audioInterrupt')
``` ```
...@@ -1695,18 +1671,18 @@ avPlayer.off('audioInterrupt') ...@@ -1695,18 +1671,18 @@ avPlayer.off('audioInterrupt')
**示例:** **示例:**
```js ```ts
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
function printfItemDescription(obj, key) { printfItemDescription(obj: media.MediaDescription, key: string) {
let property = obj[key]; let property: Object = obj[key];
console.info('audio key is ' + key); // 通过key值获取对应的value。key值具体可见[MediaDescriptionKey] console.info('audio key is ' + key); // 通过key值获取对应的value。key值具体可见[MediaDescriptionKey]
console.info('audio value is ' + property); //对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey] console.info('audio value is ' + property); //对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey]
} }
let audioPlayer = media.createAudioPlayer();
audioPlayer.getTrackDescription((error, arrList) => { avPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
if (arrList != null) { if (arrList != null) {
for (let i = 0; i < arrList.length; i++) { for (let i = 0; i < arrList.length; i++) {
printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); //打印出每条轨道MD_KEY_TRACK_TYPE的值 this.printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); //打印出每条轨道MD_KEY_TRACK_TYPE的值
} }
} else { } else {
console.log(`audio getTrackDescription fail, error:${error}`); console.log(`audio getTrackDescription fail, error:${error}`);
...@@ -3411,8 +3387,8 @@ createAudioPlayer(): AudioPlayer ...@@ -3411,8 +3387,8 @@ createAudioPlayer(): AudioPlayer
**示例:** **示例:**
```js ```ts
let audioPlayer = media.createAudioPlayer(); let audioPlayer: media.AudioPlayer = media.createAudioPlayer();
``` ```
## media.createVideoPlayer<sup>(deprecated)</sup><a name=createvideoplayer></a> ## media.createVideoPlayer<sup>(deprecated)</sup><a name=createvideoplayer></a>
...@@ -3434,10 +3410,11 @@ createVideoPlayer(callback: AsyncCallback\<VideoPlayer>): void ...@@ -3434,10 +3410,11 @@ createVideoPlayer(callback: AsyncCallback\<VideoPlayer>): void
**示例:** **示例:**
```js ```ts
let videoPlayer; import { BusinessError } from '@ohos.base';
media.createVideoPlayer((error, video) => { let videoPlayer: media.VideoPlayer;
media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
if (video != null) { if (video != null) {
videoPlayer = video; videoPlayer = video;
console.info('video createVideoPlayer success'); console.info('video createVideoPlayer success');
...@@ -3466,17 +3443,18 @@ createVideoPlayer(): Promise\<VideoPlayer> ...@@ -3466,17 +3443,18 @@ createVideoPlayer(): Promise\<VideoPlayer>
**示例:** **示例:**
```js ```ts
let videoPlayer; import { BusinessError } from '@ohos.base';
media.createVideoPlayer().then((video) => { let videoPlayer: media.VideoPlayer;
media.createVideoPlayer().then((video: media.VideoPlayer) => {
if (video != null) { if (video != null) {
videoPlayer = video; videoPlayer = video;
console.info('video createVideoPlayer success'); console.info('video createVideoPlayer success');
} else { } else {
console.error('video createVideoPlayer fail'); console.error('video createVideoPlayer fail');
} }
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -3501,8 +3479,8 @@ createAudioRecorder(): AudioRecorder ...@@ -3501,8 +3479,8 @@ createAudioRecorder(): AudioRecorder
**示例:** **示例:**
```js ```ts
let audioRecorder: media.AudioRecorder = media.createAudioRecorder(); let audioRecorder = media.createAudioRecorder();
``` ```
## MediaErrorCode<sup>(deprecated)</sup><a name=mediaerrorcode></a> ## MediaErrorCode<sup>(deprecated)</sup><a name=mediaerrorcode></a>
...@@ -3558,7 +3536,7 @@ play(): void ...@@ -3558,7 +3536,7 @@ play(): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('play', () => { //设置'play'事件回调 audioPlayer.on('play', () => { //设置'play'事件回调
console.log('audio play success'); console.log('audio play success');
}); });
...@@ -3575,7 +3553,7 @@ pause(): void ...@@ -3575,7 +3553,7 @@ pause(): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('pause', () => { //设置'pause'事件回调 audioPlayer.on('pause', () => { //设置'pause'事件回调
console.log('audio pause success'); console.log('audio pause success');
}); });
...@@ -3592,7 +3570,7 @@ stop(): void ...@@ -3592,7 +3570,7 @@ stop(): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('stop', () => { //设置'stop'事件回调 audioPlayer.on('stop', () => { //设置'stop'事件回调
console.log('audio stop success'); console.log('audio stop success');
}); });
...@@ -3609,7 +3587,7 @@ reset(): void ...@@ -3609,7 +3587,7 @@ reset(): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('reset', () => { //设置'reset'事件回调 audioPlayer.on('reset', () => { //设置'reset'事件回调
console.log('audio reset success'); console.log('audio reset success');
}); });
...@@ -3632,8 +3610,8 @@ seek(timeMs: number): void ...@@ -3632,8 +3610,8 @@ seek(timeMs: number): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (seekDoneTime: number) => { //设置'timeUpdate'事件回调
if (seekDoneTime == null) { if (seekDoneTime == null) {
console.info('audio seek fail'); console.info('audio seek fail');
return; return;
...@@ -3659,7 +3637,7 @@ setVolume(vol: number): void ...@@ -3659,7 +3637,7 @@ setVolume(vol: number): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调
console.log('audio volumeChange success'); console.log('audio volumeChange success');
}); });
...@@ -3676,7 +3654,7 @@ release(): void ...@@ -3676,7 +3654,7 @@ release(): void
**示例:** **示例:**
```js ```ts
audioPlayer.release(); audioPlayer.release();
audioPlayer = undefined; audioPlayer = undefined;
``` ```
...@@ -3697,20 +3675,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void ...@@ -3697,20 +3675,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
**示例:** **示例:**
```js ```ts
function printfDescription(obj) { audioPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
for (let item in obj) {
let property = obj[item];
console.info('audio key is ' + item);
console.info('audio value is ' + property);
}
}
audioPlayer.getTrackDescription((error, arrList) => {
if (arrList != null) { if (arrList != null) {
for (let i = 0; i < arrList.length; i++) { console.log('audio getTrackDescription success');
printfDescription(arrList[i]);
}
} else { } else {
console.log(`audio getTrackDescription fail, error:${error}`); console.log(`audio getTrackDescription fail, error:${error}`);
} }
...@@ -3733,28 +3701,12 @@ getTrackDescription(): Promise\<Array\<MediaDescription>> ...@@ -3733,28 +3701,12 @@ getTrackDescription(): Promise\<Array\<MediaDescription>>
**示例:** **示例:**
```js ```ts
function printfDescription(obj) { audioPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => {
for (let item in obj) { console.log('audio getTrackDescription success');
let property = obj[item]; }).catch((error: BusinessError) => {
console.info('audio key is ' + item);
console.info('audio value is ' + property);
}
}
let arrayDescription = null
audioPlayer.getTrackDescription().then((arrList) => {
if (arrList != null) {
arrayDescription = arrList;
} else {
console.log('audio getTrackDescription fail');
}
}).catch((error) => {
console.info(`audio catchCallback, error:${error}`); console.info(`audio catchCallback, error:${error}`);
}); });
for (let i = 0; i < arrayDescription.length; i++) {
printfDescription(arrayDescription[i]);
}
``` ```
### on('bufferingUpdate')<sup>8+</sup> ### on('bufferingUpdate')<sup>8+</sup>
...@@ -3774,8 +3726,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe ...@@ -3774,8 +3726,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe
**示例:** **示例:**
```js ```ts
audioPlayer.on('bufferingUpdate', (infoType, value) => { audioPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => {
console.log('audio bufferingInfo type: ' + infoType); console.log('audio bufferingInfo type: ' + infoType);
console.log('audio bufferingInfo value: ' + value); console.log('audio bufferingInfo value: ' + value);
}); });
...@@ -3798,10 +3750,11 @@ on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeCh ...@@ -3798,10 +3750,11 @@ on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeCh
**示例:** **示例:**
```js ```ts
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
import { BusinessError } from '@ohos.base';
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 let audioPlayer: media.AudioPlayer = media.createAudioPlayer(); //创建一个音频播放实例
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
console.info('audio set source success'); console.info('audio set source success');
audioPlayer.play(); //开始播放,并触发'play'事件回调 audioPlayer.play(); //开始播放,并触发'play'事件回调
...@@ -3819,7 +3772,7 @@ audioPlayer.on('reset', () => { //设置'reset'事件回调 ...@@ -3819,7 +3772,7 @@ audioPlayer.on('reset', () => { //设置'reset'事件回调
audioPlayer.release(); //释放播放实例资源 audioPlayer.release(); //释放播放实例资源
audioPlayer = undefined; audioPlayer = undefined;
}); });
audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (seekDoneTime: number) => { //设置'timeUpdate'事件回调
if (seekDoneTime == null) { if (seekDoneTime == null) {
console.info('audio seek fail'); console.info('audio seek fail');
return; return;
...@@ -3835,7 +3788,7 @@ audioPlayer.on('finish', () => { //设置'finish'事件回调 ...@@ -3835,7 +3788,7 @@ audioPlayer.on('finish', () => { //设置'finish'事件回调
console.info('audio play finish'); console.info('audio play finish');
audioPlayer.stop(); //停止播放,并触发'stop'事件回调 audioPlayer.stop(); //停止播放,并触发'stop'事件回调
}); });
audioPlayer.on('error', (error) => { //设置'error'事件回调 audioPlayer.on('error', (error: BusinessError) => { //设置'error'事件回调
console.error(`audio error called, error: ${error}`); console.error(`audio error called, error: ${error}`);
}); });
...@@ -3847,9 +3800,9 @@ fs.open(path).then((file) => { ...@@ -3847,9 +3800,9 @@ fs.open(path).then((file) => {
fdPath = fdPath + '' + file.fd; fdPath = fdPath + '' + file.fd;
console.info('open fd success fd is' + fdPath); console.info('open fd success fd is' + fdPath);
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
}, (err) => { }, (err: BusinessError) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}).catch((err) => { }).catch((err: BusinessError) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}); });
``` ```
...@@ -3871,8 +3824,8 @@ on(type: 'timeUpdate', callback: Callback\<number>): void ...@@ -3871,8 +3824,8 @@ on(type: 'timeUpdate', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('timeUpdate', (newTime) => { //设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (newTime: number) => { //设置'timeUpdate'事件回调
if (newTime == null) { if (newTime == null) {
console.info('audio timeUpadate fail'); console.info('audio timeUpadate fail');
return; return;
...@@ -3899,8 +3852,8 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -3899,8 +3852,8 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
audioPlayer.on('error', (error) => { //设置'error'事件回调 audioPlayer.on('error', (error: BusinessError) => { //设置'error'事件回调
console.error(`audio error called, error: ${error}`); console.error(`audio error called, error: ${error}`);
}); });
audioPlayer.setVolume(3); //设置volume为无效值,触发'error'事件 audioPlayer.setVolume(3); //设置volume为无效值,触发'error'事件
...@@ -3966,9 +3919,9 @@ setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void ...@@ -3966,9 +3919,9 @@ setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
let surfaceId = null; let surfaceId: string = null;
videoPlayer.setDisplaySurface(surfaceId, (err) => { videoPlayer.setDisplaySurface(surfaceId, (err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('setDisplaySurface success!'); console.info('setDisplaySurface success!');
} else { } else {
...@@ -4001,11 +3954,11 @@ setDisplaySurface(surfaceId: string): Promise\<void> ...@@ -4001,11 +3954,11 @@ setDisplaySurface(surfaceId: string): Promise\<void>
**示例:** **示例:**
```js ```ts
let surfaceId = null; let surfaceId = null;
videoPlayer.setDisplaySurface(surfaceId).then(() => { videoPlayer.setDisplaySurface(surfaceId).then(() => {
console.info('setDisplaySurface success'); console.info('setDisplaySurface success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4026,8 +3979,8 @@ prepare(callback: AsyncCallback\<void>): void ...@@ -4026,8 +3979,8 @@ prepare(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
videoPlayer.prepare((err) => { videoPlayer.prepare((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('prepare success!'); console.info('prepare success!');
} else { } else {
...@@ -4052,10 +4005,10 @@ prepare(): Promise\<void> ...@@ -4052,10 +4005,10 @@ prepare(): Promise\<void>
**示例:** **示例:**
```js ```ts
videoPlayer.prepare().then(() => { videoPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4076,8 +4029,8 @@ play(callback: AsyncCallback\<void>): void; ...@@ -4076,8 +4029,8 @@ play(callback: AsyncCallback\<void>): void;
**示例:** **示例:**
```js ```ts
videoPlayer.play((err) => { videoPlayer.play((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('play success!'); console.info('play success!');
} else { } else {
...@@ -4102,10 +4055,10 @@ play(): Promise\<void>; ...@@ -4102,10 +4055,10 @@ play(): Promise\<void>;
**示例:** **示例:**
```js ```ts
videoPlayer.play().then(() => { videoPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4126,8 +4079,8 @@ pause(callback: AsyncCallback\<void>): void ...@@ -4126,8 +4079,8 @@ pause(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
videoPlayer.pause((err) => { videoPlayer.pause((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('pause success!'); console.info('pause success!');
} else { } else {
...@@ -4152,10 +4105,10 @@ pause(): Promise\<void> ...@@ -4152,10 +4105,10 @@ pause(): Promise\<void>
**示例:** **示例:**
```js ```ts
videoPlayer.pause().then(() => { videoPlayer.pause().then(() => {
console.info('pause success'); console.info('pause success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4176,8 +4129,8 @@ stop(callback: AsyncCallback\<void>): void ...@@ -4176,8 +4129,8 @@ stop(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
videoPlayer.stop((err) => { videoPlayer.stop((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('stop success!'); console.info('stop success!');
} else { } else {
...@@ -4202,10 +4155,10 @@ stop(): Promise\<void> ...@@ -4202,10 +4155,10 @@ stop(): Promise\<void>
**示例:** **示例:**
```js ```ts
videoPlayer.stop().then(() => { videoPlayer.stop().then(() => {
console.info('stop success'); console.info('stop success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4226,8 +4179,8 @@ reset(callback: AsyncCallback\<void>): void ...@@ -4226,8 +4179,8 @@ reset(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
videoPlayer.reset((err) => { videoPlayer.reset((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('reset success!'); console.info('reset success!');
} else { } else {
...@@ -4252,10 +4205,10 @@ reset(): Promise\<void> ...@@ -4252,10 +4205,10 @@ reset(): Promise\<void>
**示例:** **示例:**
```js ```ts
videoPlayer.reset().then(() => { videoPlayer.reset().then(() => {
console.info('reset success'); console.info('reset success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4277,9 +4230,9 @@ seek(timeMs: number, callback: AsyncCallback\<number>): void ...@@ -4277,9 +4230,9 @@ seek(timeMs: number, callback: AsyncCallback\<number>): void
**示例:** **示例:**
```js ```ts
let seekTime = 5000; let seekTime: number = 5000;
videoPlayer.seek(seekTime, (err, result) => { videoPlayer.seek(seekTime, (err: BusinessError, result: number) => {
if (err == null) { if (err == null) {
console.info('seek success!'); console.info('seek success!');
} else { } else {
...@@ -4306,10 +4259,10 @@ seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void ...@@ -4306,10 +4259,10 @@ seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void
**示例:** **示例:**
```js ```ts
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
let seekTime = 5000; let seekTime: number = 5000;
videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err, result) => { videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err: BusinessError, result: number) => {
if (err == null) { if (err == null) {
console.info('seek success!'); console.info('seek success!');
} else { } else {
...@@ -4341,18 +4294,18 @@ seek(timeMs: number, mode?:SeekMode): Promise\<number> ...@@ -4341,18 +4294,18 @@ seek(timeMs: number, mode?:SeekMode): Promise\<number>
**示例:** **示例:**
```js ```ts
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
let seekTime = 5000; let seekTime: number = 5000;
videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime表示seek完成后的时间点 videoPlayer.seek(seekTime).then((seekDoneTime: number) => { // seekDoneTime表示seek完成后的时间点
console.info('seek success'); console.info('seek success');
}).catch((error) => { }).catch((error) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => { videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime: number) => {
console.info('seek success'); console.info('seek success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4374,9 +4327,9 @@ setVolume(vol: number, callback: AsyncCallback\<void>): void ...@@ -4374,9 +4327,9 @@ setVolume(vol: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
let vol = 0.5; let vol: number = 0.5;
videoPlayer.setVolume(vol, (err, result) => { videoPlayer.setVolume(vol, (err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('setVolume success!'); console.info('setVolume success!');
} else { } else {
...@@ -4407,11 +4360,11 @@ setVolume(vol: number): Promise\<void> ...@@ -4407,11 +4360,11 @@ setVolume(vol: number): Promise\<void>
**示例:** **示例:**
```js ```ts
let vol = 0.5; let vol: number = 0.5;
videoPlayer.setVolume(vol).then(() => { videoPlayer.setVolume(vol).then(() => {
console.info('setVolume success'); console.info('setVolume success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4432,8 +4385,8 @@ release(callback: AsyncCallback\<void>): void ...@@ -4432,8 +4385,8 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
videoPlayer.release((err) => { videoPlayer.release((err: BusinessError) => {
if (err == null) { if (err == null) {
console.info('release success!'); console.info('release success!');
} else { } else {
...@@ -4458,10 +4411,10 @@ release(): Promise\<void> ...@@ -4458,10 +4411,10 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```ts
videoPlayer.release().then(() => { videoPlayer.release().then(() => {
console.info('release success'); console.info('release success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4482,20 +4435,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void ...@@ -4482,20 +4435,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
**示例:** **示例:**
```js ```ts
function printfDescription(obj) { videoPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
for (let item in obj) {
let property = obj[item];
console.info('video key is ' + item);
console.info('video value is ' + property);
}
}
videoPlayer.getTrackDescription((error, arrList) => {
if ((arrList) != null) { if ((arrList) != null) {
for (let i = 0; i < arrList.length; i++) { console.info('video getTrackDescription success');
printfDescription(arrList[i]);
}
} else { } else {
console.log(`video getTrackDescription fail, error:${error}`); console.log(`video getTrackDescription fail, error:${error}`);
} }
...@@ -4518,28 +4461,16 @@ getTrackDescription(): Promise\<Array\<MediaDescription>> ...@@ -4518,28 +4461,16 @@ getTrackDescription(): Promise\<Array\<MediaDescription>>
**示例:** **示例:**
```js ```ts
function printfDescription(obj) { videoPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => {
for (let item in obj) {
let property = obj[item];
console.info('video key is ' + item);
console.info('video value is ' + property);
}
}
let arrayDescription;
videoPlayer.getTrackDescription().then((arrList) => {
if (arrList != null) { if (arrList != null) {
arrayDescription = arrList; console.info('video getTrackDescription success');
} else { } else {
console.log('video getTrackDescription fail'); console.log('video getTrackDescription fail');
} }
}).catch((error) => { }).catch((error: BusinessError) => {
console.info(`video catchCallback, error:${error}`); console.info(`video catchCallback, error:${error}`);
}); });
for (let i = 0; i < arrayDescription.length; i++) {
printfDescription(arrayDescription[i]);
}
``` ```
### setSpeed<sup>8+</sup> ### setSpeed<sup>8+</sup>
...@@ -4559,11 +4490,11 @@ setSpeed(speed:number, callback: AsyncCallback\<number>): void ...@@ -4559,11 +4490,11 @@ setSpeed(speed:number, callback: AsyncCallback\<number>): void
**示例:** **示例:**
```js ```ts
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;
videoPlayer.setSpeed(speed, (err, result) => { videoPlayer.setSpeed(speed, (err: BusinessError, result: number) => {
if (err == null) { if (err == null) {
console.info('setSpeed success!'); console.info('setSpeed success!');
} else { } else {
...@@ -4594,13 +4525,13 @@ setSpeed(speed:number): Promise\<number> ...@@ -4594,13 +4525,13 @@ setSpeed(speed:number): Promise\<number>
**示例:** **示例:**
```js ```ts
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;
videoPlayer.setSpeed(speed).then(() => { videoPlayer.setSpeed(speed).then((result: number) => {
console.info('setSpeed success'); console.info('setSpeed success');
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`video catchCallback, error:${error}`); console.error(`video catchCallback, error:${error}`);
}); });
``` ```
...@@ -4622,7 +4553,7 @@ on(type: 'playbackCompleted', callback: Callback\<void>): void ...@@ -4622,7 +4553,7 @@ on(type: 'playbackCompleted', callback: Callback\<void>): void
**示例:** **示例:**
```js ```ts
videoPlayer.on('playbackCompleted', () => { videoPlayer.on('playbackCompleted', () => {
console.info('playbackCompleted success!'); console.info('playbackCompleted success!');
}); });
...@@ -4645,8 +4576,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe ...@@ -4645,8 +4576,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe
**示例:** **示例:**
```js ```ts
videoPlayer.on('bufferingUpdate', (infoType, value) => { videoPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => {
console.log('video bufferingInfo type: ' + infoType); console.log('video bufferingInfo type: ' + infoType);
console.log('video bufferingInfo value: ' + value); console.log('video bufferingInfo value: ' + value);
}); });
...@@ -4669,7 +4600,7 @@ on(type: 'startRenderFrame', callback: Callback\<void>): void ...@@ -4669,7 +4600,7 @@ on(type: 'startRenderFrame', callback: Callback\<void>): void
**示例:** **示例:**
```js ```ts
videoPlayer.on('startRenderFrame', () => { videoPlayer.on('startRenderFrame', () => {
console.info('startRenderFrame success!'); console.info('startRenderFrame success!');
}); });
...@@ -4692,8 +4623,8 @@ on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): ...@@ -4692,8 +4623,8 @@ on(type: 'videoSizeChanged', callback: (width: number, height: number) => void):
**示例:** **示例:**
```js ```ts
videoPlayer.on('videoSizeChanged', (width, height) => { videoPlayer.on('videoSizeChanged', (width: number, height: number) => {
console.log('video width is: ' + width); console.log('video width is: ' + width);
console.log('video height is: ' + height); console.log('video height is: ' + height);
}); });
...@@ -4716,8 +4647,8 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -4716,8 +4647,8 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
videoPlayer.on('error', (error) => { // 设置'error'事件回调 videoPlayer.on('error', (error: BusinessError) => { // 设置'error'事件回调
console.error(`video error called, error: ${error}`); console.error(`video error called, error: ${error}`);
}); });
videoPlayer.url = 'fd://error'; //设置错误的播放地址,触发'error'事件 videoPlayer.url = 'fd://error'; //设置错误的播放地址,触发'error'事件
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册