Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
5fa4bb96
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5fa4bb96
编写于
9月 04, 2023
作者:
F
flz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify file in master Signed-off-by: FULIZHONG<fulizhong1@huawei.com>
Signed-off-by:
N
flz
<
fulizhong1@huawei.com
>
上级
e004da84
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
192 addition
and
261 deletion
+192
-261
zh-cn/application-dev/reference/apis/js-apis-media.md
zh-cn/application-dev/reference/apis/js-apis-media.md
+192
-261
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-media.md
浏览文件 @
5fa4bb96
...
...
@@ -44,10 +44,11 @@ createAVPlayer(callback: AsyncCallback\<AVPlayer>): void
**示例:**
```
j
s
let
avPlayer
;
```
t
s
import
{
BusinessError
}
from
'
@ohos.base
'
;
media
.
createAVPlayer
((
error
,
video
)
=>
{
let
avPlayer
:
media
.
AVPlayer
;
media
.
createAVPlayer
((
error
:
BusinessError
,
video
:
media
.
AVPlayer
)
=>
{
if
(
video
!=
null
)
{
avPlayer
=
video
;
console
.
info
(
'
createAVPlayer success
'
);
...
...
@@ -81,17 +82,18 @@ createAVPlayer(): Promise\<AVPlayer>
**示例:**
```
j
s
let
avPlayer
;
```
t
s
import
{
BusinessError
}
from
'
@ohos.base
'
;
media
.
createAVPlayer
().
then
((
video
)
=>
{
let
avPlayer
:
media
.
AVPlayer
;
media
.
createAVPlayer
().
then
((
video
:
media
.
AVPlayer
)
=>
{
if
(
video
!=
null
)
{
avPlayer
=
video
;
console
.
info
(
'
createAVPlayer success
'
);
}
else
{
console
.
error
(
'
createAVPlayer fail
'
);
}
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`AVPlayer catchCallback, error message:
${
error
.
message
}
`
);
});
```
...
...
@@ -394,8 +396,8 @@ on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReas
**示例:**
```
j
s
avPlayer
.
on
(
'
stateChange
'
,
async
(
state
,
r
eason
)
=>
{
```
t
s
avPlayer
.
on
(
'
stateChange
'
,
async
(
state
:
string
,
reason
:
media
.
StateChangeR
eason
)
=>
{
switch
(
state
)
{
case
'
idle
'
:
console
.
info
(
'
state idle called
'
)
...
...
@@ -447,7 +449,7 @@ off(type: 'stateChange'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
stateChange
'
)
```
...
...
@@ -482,8 +484,8 @@ AVPlayer回调的**错误分类**<a name = error_info></a>可以分为以下几
**示例:**
```
j
s
avPlayer
.
on
(
'
error
'
,
(
error
)
=>
{
```
t
s
avPlayer
.
on
(
'
error
'
,
(
error
:
BusinessError
)
=>
{
console
.
error
(
'
error happened,and error message is :
'
+
error
.
message
)
console
.
error
(
'
error happened,and error code is :
'
+
error
.
code
)
})
...
...
@@ -505,7 +507,7 @@ off(type: 'error'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
error
'
)
```
...
...
@@ -534,8 +536,8 @@ prepare(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
avPlayer
.
prepare
((
err
)
=>
{
```
t
s
avPlayer
.
prepare
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
prepare success
'
);
}
else
{
...
...
@@ -569,10 +571,10 @@ prepare(): Promise\<void>
**示例:**
```
j
s
```
t
s
avPlayer
.
prepare
().
then
(()
=>
{
console
.
info
(
'
prepare success
'
);
},
(
err
)
=>
{
},
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
prepare filed,error message is :
'
+
err
.
message
)
})
```
...
...
@@ -601,8 +603,8 @@ play(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
avPlayer
.
play
((
err
)
=>
{
```
t
s
avPlayer
.
play
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
play success
'
);
}
else
{
...
...
@@ -635,10 +637,10 @@ play(): Promise\<void>
**示例:**
```
j
s
```
t
s
avPlayer
.
play
().
then
(()
=>
{
console
.
info
(
'
play success
'
);
},
(
err
)
=>
{
},
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
play filed,error message is :
'
+
err
.
message
)
})
```
...
...
@@ -667,8 +669,8 @@ pause(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
avPlayer
.
pause
((
err
)
=>
{
```
t
s
avPlayer
.
pause
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
pause success
'
);
}
else
{
...
...
@@ -701,10 +703,10 @@ pause(): Promise\<void>
**示例:**
```
j
s
```
t
s
avPlayer
.
pause
().
then
(()
=>
{
console
.
info
(
'
pause success
'
);
},
(
err
)
=>
{
},
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
pause filed,error message is :
'
+
err
.
message
)
})
```
...
...
@@ -733,8 +735,8 @@ stop(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
avPlayer
.
stop
((
err
)
=>
{
```
t
s
avPlayer
.
stop
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
stop success
'
);
}
else
{
...
...
@@ -767,10 +769,10 @@ stop(): Promise\<void>
**示例:**
```
j
s
```
t
s
avPlayer
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop success
'
);
},
(
err
)
=>
{
},
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
stop filed,error message is :
'
+
err
.
message
)
})
```
...
...
@@ -799,8 +801,8 @@ reset(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
avPlayer
.
reset
((
err
)
=>
{
```
t
s
avPlayer
.
reset
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
reset success
'
);
}
else
{
...
...
@@ -833,10 +835,10 @@ reset(): Promise\<void>
**示例:**
```
j
s
```
t
s
avPlayer
.
reset
().
then
(()
=>
{
console
.
info
(
'
reset success
'
);
},
(
err
)
=>
{
},
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
reset filed,error message is :
'
+
err
.
message
)
})
```
...
...
@@ -865,8 +867,8 @@ release(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
avPlayer
.
release
((
err
)
=>
{
```
t
s
avPlayer
.
release
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
reset success
'
);
}
else
{
...
...
@@ -899,10 +901,10 @@ release(): Promise\<void>
**示例:**
```
j
s
```
t
s
avPlayer
.
release
().
then
(()
=>
{
console
.
info
(
'
release success
'
);
},
(
err
)
=>
{
},
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
release filed,error message is :
'
+
err
.
message
)
})
```
...
...
@@ -931,20 +933,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
**示例:**
```
js
function
printfDescription
(
obj
)
{
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
)
=>
{
```
ts
avPlayer
.
getTrackDescription
((
error
:
BusinessError
,
arrList
:
Array
<
media
.
MediaDescription
>
)
=>
{
if
((
arrList
)
!=
null
)
{
for
(
let
i
=
0
;
i
<
arrList
.
length
;
i
++
)
{
printfDescription
(
arrList
[
i
]);
}
console
.
info
(
'
getTrackDescription success
'
);
}
else
{
console
.
log
(
`video getTrackDescription fail, error:
${
error
}
`
);
}
...
...
@@ -975,28 +967,12 @@ getTrackDescription(): Promise\<Array\<MediaDescription>>
**示例:**
```
js
let
arrayDescription
;
function
printfDescription
(
obj
)
{
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
)
=>
{
```
ts
avPlayer
.
getTrackDescription
().
then
((
arrList
:
Array
<
media
.
MediaDescription
>
)
=>
{
console
.
info
(
'
getTrackDescription success
'
);
}).
catch
((
error
:
BusinessError
)
=>
{
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>
...
...
@@ -1017,8 +993,8 @@ seek(timeMs: number, mode?:SeekMode): void
**示例:**
```
j
s
let
seekTime
=
1000
```
t
s
let
seekTime
:
number
=
1000
avPlayer
.
seek
(
seekTime
,
media
.
SeekMode
.
SEEK_PREV_SYNC
)
```
...
...
@@ -1039,7 +1015,7 @@ on(type: 'seekDone', callback: Callback\<number>): void
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
seekDone
'
,
(
seekDoneTime
:
number
)
=>
{
console
.
info
(
'
seekDone success,and seek time is:
'
+
seekDoneTime
)
})
...
...
@@ -1061,7 +1037,7 @@ off(type: 'seekDone'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
seekDone
'
)
```
...
...
@@ -1082,7 +1058,7 @@ setSpeed(speed: PlaybackSpeed): void
**示例:**
```
j
s
```
t
s
avPlayer
.
setSpeed
(
media
.
PlaybackSpeed
.
SPEED_FORWARD_2_00_X
)
```
...
...
@@ -1103,7 +1079,7 @@ on(type: 'speedDone', callback: Callback\<number>): void
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
speedDone
'
,
(
speed
:
number
)
=>
{
console
.
info
(
'
speedDone success,and speed value is:
'
+
speed
)
})
...
...
@@ -1125,7 +1101,7 @@ off(type: 'speedDone'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
speedDone
'
)
```
...
...
@@ -1145,8 +1121,8 @@ setBitrate(bitrate: number): void
**示例:**
```
j
s
let
bitrate
=
96000
```
t
s
let
bitrate
:
number
=
96000
avPlayer
.
setBitrate
(
bitrate
)
```
...
...
@@ -1167,7 +1143,7 @@ on(type: 'bitrateDone', callback: Callback\<number>): void
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
bitrateDone
'
,
(
bitrate
:
number
)
=>
{
console
.
info
(
'
bitrateDone success,and bitrate value is:
'
+
bitrate
)
})
...
...
@@ -1189,7 +1165,7 @@ off(type: 'bitrateDone'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
bitrateDone
'
)
```
...
...
@@ -1210,7 +1186,7 @@ on(type: 'availableBitrates', callback: (bitrates: Array\<number>) => void): voi
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
availableBitrates
'
,
(
bitrates
:
Array
<
number
>
)
=>
{
console
.
info
(
'
availableBitrates success,and availableBitrates length is:
'
+
bitrates
.
length
)
})
...
...
@@ -1232,7 +1208,7 @@ off(type: 'availableBitrates'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
availableBitrates
'
)
```
...
...
@@ -1252,8 +1228,8 @@ setVolume(volume: number): void
**示例:**
```
j
s
let
volume
=
1.0
```
t
s
let
volume
:
number
=
1.0
avPlayer
.
setVolume
(
volume
)
```
...
...
@@ -1274,8 +1250,8 @@ on(type: 'volumeChange', callback: Callback\<number>): void
**示例:**
```
j
s
avPlayer
.
on
(
'
volumeChange
'
,
(
vol
:
number
)
=>
{
```
t
s
avPlayer
.
on
(
'
volumeChange
'
,
(
vol
:
number
)
=>
{
console
.
info
(
'
volumeChange success,and new volume is :
'
+
vol
)
})
```
...
...
@@ -1296,7 +1272,7 @@ off(type: 'volumeChange'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
volumeChange
'
)
```
...
...
@@ -1317,7 +1293,7 @@ on(type: 'endOfStream', callback: Callback\<void>): void
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
endOfStream
'
,
()
=>
{
console
.
info
(
'
endOfStream success
'
)
})
...
...
@@ -1339,7 +1315,7 @@ off(type: 'endOfStream'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
endOfStream
'
)
```
...
...
@@ -1361,7 +1337,7 @@ on(type: 'timeUpdate', callback: Callback\<number>): void
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
timeUpdate
'
,
(
time
:
number
)
=>
{
console
.
info
(
'
timeUpdate success,and new time is :
'
+
time
)
})
...
...
@@ -1383,7 +1359,7 @@ off(type: 'timeUpdate'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
timeUpdate
'
)
```
...
...
@@ -1405,8 +1381,8 @@ on(type: 'durationUpdate', callback: Callback\<number>): void
**示例:**
```
j
s
avPlayer
.
on
(
'
durationUpdate
'
,
(
duration
)
=>
{
```
t
s
avPlayer
.
on
(
'
durationUpdate
'
,
(
duration
:
number
)
=>
{
console
.
info
(
'
durationUpdate success,new duration is :
'
+
duration
)
})
```
...
...
@@ -1427,7 +1403,7 @@ off(type: 'durationUpdate'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
durationUpdate
'
)
```
...
...
@@ -1448,7 +1424,7 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
bufferingUpdate
'
,
(
infoType
:
media
.
BufferingInfoType
,
value
:
number
)
=>
{
console
.
info
(
'
bufferingUpdate success,and infoType value is:
'
+
infoType
+
'
, value is :
'
+
value
)
})
...
...
@@ -1470,7 +1446,7 @@ off(type: 'bufferingUpdate'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
bufferingUpdate
'
)
```
...
...
@@ -1491,7 +1467,7 @@ on(type: 'startRenderFrame', callback: Callback\<void>): void
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
startRenderFrame
'
,
()
=>
{
console
.
info
(
'
startRenderFrame success
'
)
})
...
...
@@ -1513,7 +1489,7 @@ off(type: 'startRenderFrame'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
startRenderFrame
'
)
```
...
...
@@ -1534,7 +1510,7 @@ on(type: 'videoSizeChange', callback: (width: number, height: number) => void):
**示例:**
```
j
s
```
t
s
avPlayer
.
on
(
'
videoSizeChange
'
,
(
width
:
number
,
height
:
number
)
=>
{
console
.
info
(
'
videoSizeChange success,and width is:
'
+
width
+
'
, height is :
'
+
height
)
})
...
...
@@ -1556,7 +1532,7 @@ off(type: 'videoSizeChange'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
videoSizeChange
'
)
```
...
...
@@ -1577,7 +1553,7 @@ on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
avPlayer
.
on
(
'
audioInterrupt
'
,
(
info
:
audio
.
InterruptEvent
)
=>
{
...
...
@@ -1601,7 +1577,7 @@ off(type: 'audioInterrupt'): void
**示例:**
```
j
s
```
t
s
avPlayer
.
off
(
'
audioInterrupt
'
)
```
...
...
@@ -1695,18 +1671,18 @@ avPlayer.off('audioInterrupt')
**示例:**
```
j
s
```
t
s
import
media
from
'
@ohos.multimedia.media
'
function
printfItemDescription
(
obj
,
key
)
{
let
property
=
obj
[
key
];
printfItemDescription
(
obj
:
media
.
MediaDescription
,
key
:
string
)
{
let
property
:
Object
=
obj
[
key
];
console
.
info
(
'
audio key is
'
+
key
);
// 通过key值获取对应的value。key值具体可见[MediaDescriptionKey]
console
.
info
(
'
audio value is
'
+
property
);
//对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey]
}
let
audioPlayer
=
media
.
createAudioPlayer
();
a
udioPlayer
.
getTrackDescription
((
error
,
arrList
)
=>
{
a
vPlayer
.
getTrackDescription
((
error
:
BusinessError
,
arrList
:
Array
<
media
.
MediaDescription
>
)
=>
{
if
(
arrList
!=
null
)
{
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
{
console
.
log
(
`audio getTrackDescription fail, error:
${
error
}
`
);
...
...
@@ -3411,8 +3387,8 @@ createAudioPlayer(): AudioPlayer
**示例:**
```
j
s
let
audioPlayer
=
media
.
createAudioPlayer
();
```
t
s
let
audioPlayer
:
media
.
AudioPlayer
=
media
.
createAudioPlayer
();
```
## media.createVideoPlayer<sup>(deprecated)</sup><a name=createvideoplayer></a>
...
...
@@ -3434,10 +3410,11 @@ createVideoPlayer(callback: AsyncCallback\<VideoPlayer>): void
**示例:**
```
j
s
let
videoPlayer
;
```
t
s
import
{
BusinessError
}
from
'
@ohos.base
'
;
media
.
createVideoPlayer
((
error
,
video
)
=>
{
let
videoPlayer
:
media
.
VideoPlayer
;
media
.
createVideoPlayer
((
error
:
BusinessError
,
video
:
media
.
VideoPlayer
)
=>
{
if
(
video
!=
null
)
{
videoPlayer
=
video
;
console
.
info
(
'
video createVideoPlayer success
'
);
...
...
@@ -3466,17 +3443,18 @@ createVideoPlayer(): Promise\<VideoPlayer>
**示例:**
```
j
s
let
videoPlayer
;
```
t
s
import
{
BusinessError
}
from
'
@ohos.base
'
;
media
.
createVideoPlayer
().
then
((
video
)
=>
{
let
videoPlayer
:
media
.
VideoPlayer
;
media
.
createVideoPlayer
().
then
((
video
:
media
.
VideoPlayer
)
=>
{
if
(
video
!=
null
)
{
videoPlayer
=
video
;
console
.
info
(
'
video createVideoPlayer success
'
);
}
else
{
console
.
error
(
'
video createVideoPlayer fail
'
);
}
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -3501,8 +3479,8 @@ createAudioRecorder(): AudioRecorder
**示例:**
```
j
s
let
audioRecorder
:
media
.
AudioRecorder
=
media
.
createAudioRecorder
();
```
t
s
let
audioRecorder
=
media
.
createAudioRecorder
();
```
## MediaErrorCode<sup>(deprecated)</sup><a name=mediaerrorcode></a>
...
...
@@ -3558,7 +3536,7 @@ play(): void
**示例:**
```
j
s
```
t
s
audioPlayer
.
on
(
'
play
'
,
()
=>
{
//设置'play'事件回调
console
.
log
(
'
audio play success
'
);
});
...
...
@@ -3575,7 +3553,7 @@ pause(): void
**示例:**
```
j
s
```
t
s
audioPlayer
.
on
(
'
pause
'
,
()
=>
{
//设置'pause'事件回调
console
.
log
(
'
audio pause success
'
);
});
...
...
@@ -3592,7 +3570,7 @@ stop(): void
**示例:**
```
j
s
```
t
s
audioPlayer
.
on
(
'
stop
'
,
()
=>
{
//设置'stop'事件回调
console
.
log
(
'
audio stop success
'
);
});
...
...
@@ -3609,7 +3587,7 @@ reset(): void
**示例:**
```
j
s
```
t
s
audioPlayer
.
on
(
'
reset
'
,
()
=>
{
//设置'reset'事件回调
console
.
log
(
'
audio reset success
'
);
});
...
...
@@ -3632,8 +3610,8 @@ seek(timeMs: number): void
**示例:**
```
j
s
audioPlayer
.
on
(
'
timeUpdate
'
,
(
seekDoneTime
)
=>
{
//设置'timeUpdate'事件回调
```
t
s
audioPlayer
.
on
(
'
timeUpdate
'
,
(
seekDoneTime
:
number
)
=>
{
//设置'timeUpdate'事件回调
if
(
seekDoneTime
==
null
)
{
console
.
info
(
'
audio seek fail
'
);
return
;
...
...
@@ -3659,7 +3637,7 @@ setVolume(vol: number): void
**示例:**
```
j
s
```
t
s
audioPlayer
.
on
(
'
volumeChange
'
,
()
=>
{
//设置'volumeChange'事件回调
console
.
log
(
'
audio volumeChange success
'
);
});
...
...
@@ -3676,7 +3654,7 @@ release(): void
**示例:**
```
j
s
```
t
s
audioPlayer
.
release
();
audioPlayer
=
undefined
;
```
...
...
@@ -3697,20 +3675,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
**示例:**
```
js
function
printfDescription
(
obj
)
{
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
)
=>
{
```
ts
audioPlayer
.
getTrackDescription
((
error
:
BusinessError
,
arrList
:
Array
<
media
.
MediaDescription
>
)
=>
{
if
(
arrList
!=
null
)
{
for
(
let
i
=
0
;
i
<
arrList
.
length
;
i
++
)
{
printfDescription
(
arrList
[
i
]);
}
console
.
log
(
'
audio getTrackDescription success
'
);
}
else
{
console
.
log
(
`audio getTrackDescription fail, error:
${
error
}
`
);
}
...
...
@@ -3733,28 +3701,12 @@ getTrackDescription(): Promise\<Array\<MediaDescription>>
**示例:**
```
js
function
printfDescription
(
obj
)
{
for
(
let
item
in
obj
)
{
let
property
=
obj
[
item
];
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
)
=>
{
```
ts
audioPlayer
.
getTrackDescription
().
then
((
arrList
:
Array
<
media
.
MediaDescription
>
)
=>
{
console
.
log
(
'
audio getTrackDescription success
'
);
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
info
(
`audio catchCallback, error:
${
error
}
`
);
});
for
(
let
i
=
0
;
i
<
arrayDescription
.
length
;
i
++
)
{
printfDescription
(
arrayDescription
[
i
]);
}
```
### on('bufferingUpdate')<sup>8+</sup>
...
...
@@ -3774,8 +3726,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe
**示例:**
```
j
s
audioPlayer
.
on
(
'
bufferingUpdate
'
,
(
infoType
,
value
)
=>
{
```
t
s
audioPlayer
.
on
(
'
bufferingUpdate
'
,
(
infoType
:
media
.
BufferingInfoType
,
value
:
number
)
=>
{
console
.
log
(
'
audio bufferingInfo type:
'
+
infoType
);
console
.
log
(
'
audio bufferingInfo value:
'
+
value
);
});
...
...
@@ -3798,10 +3750,11 @@ on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeCh
**示例:**
```
j
s
```
t
s
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属性设置成功后,触发此回调
console
.
info
(
'
audio set source success
'
);
audioPlayer
.
play
();
//开始播放,并触发'play'事件回调
...
...
@@ -3819,7 +3772,7 @@ audioPlayer.on('reset', () => { //设置'reset'事件回调
audioPlayer
.
release
();
//释放播放实例资源
audioPlayer
=
undefined
;
});
audioPlayer
.
on
(
'
timeUpdate
'
,
(
seekDoneTime
)
=>
{
//设置'timeUpdate'事件回调
audioPlayer
.
on
(
'
timeUpdate
'
,
(
seekDoneTime
:
number
)
=>
{
//设置'timeUpdate'事件回调
if
(
seekDoneTime
==
null
)
{
console
.
info
(
'
audio seek fail
'
);
return
;
...
...
@@ -3835,7 +3788,7 @@ audioPlayer.on('finish', () => { //设置'finish'事件回调
console
.
info
(
'
audio play finish
'
);
audioPlayer
.
stop
();
//停止播放,并触发'stop'事件回调
});
audioPlayer
.
on
(
'
error
'
,
(
error
)
=>
{
//设置'error'事件回调
audioPlayer
.
on
(
'
error
'
,
(
error
:
BusinessError
)
=>
{
//设置'error'事件回调
console
.
error
(
`audio error called, error:
${
error
}
`
);
});
...
...
@@ -3847,9 +3800,9 @@ fs.open(path).then((file) => {
fdPath
=
fdPath
+
''
+
file
.
fd
;
console
.
info
(
'
open fd success fd is
'
+
fdPath
);
audioPlayer
.
src
=
fdPath
;
//设置src属性,并触发'dataLoad'事件回调
},
(
err
)
=>
{
},
(
err
:
BusinessError
)
=>
{
console
.
info
(
'
open fd failed err is
'
+
err
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
'
open fd failed err is
'
+
err
);
});
```
...
...
@@ -3871,8 +3824,8 @@ on(type: 'timeUpdate', callback: Callback\<number>): void
**示例:**
```
j
s
audioPlayer
.
on
(
'
timeUpdate
'
,
(
newTime
)
=>
{
//设置'timeUpdate'事件回调
```
t
s
audioPlayer
.
on
(
'
timeUpdate
'
,
(
newTime
:
number
)
=>
{
//设置'timeUpdate'事件回调
if
(
newTime
==
null
)
{
console
.
info
(
'
audio timeUpadate fail
'
);
return
;
...
...
@@ -3899,8 +3852,8 @@ on(type: 'error', callback: ErrorCallback): void
**示例:**
```
j
s
audioPlayer
.
on
(
'
error
'
,
(
error
)
=>
{
//设置'error'事件回调
```
t
s
audioPlayer
.
on
(
'
error
'
,
(
error
:
BusinessError
)
=>
{
//设置'error'事件回调
console
.
error
(
`audio error called, error:
${
error
}
`
);
});
audioPlayer
.
setVolume
(
3
);
//设置volume为无效值,触发'error'事件
...
...
@@ -3966,9 +3919,9 @@ setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void
**示例:**
```
j
s
let
surfaceId
=
null
;
videoPlayer
.
setDisplaySurface
(
surfaceId
,
(
err
)
=>
{
```
t
s
let
surfaceId
:
string
=
null
;
videoPlayer
.
setDisplaySurface
(
surfaceId
,
(
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
setDisplaySurface success!
'
);
}
else
{
...
...
@@ -4001,11 +3954,11 @@ setDisplaySurface(surfaceId: string): Promise\<void>
**示例:**
```
j
s
```
t
s
let
surfaceId
=
null
;
videoPlayer
.
setDisplaySurface
(
surfaceId
).
then
(()
=>
{
console
.
info
(
'
setDisplaySurface success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4026,8 +3979,8 @@ prepare(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
videoPlayer
.
prepare
((
err
)
=>
{
```
t
s
videoPlayer
.
prepare
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
prepare success!
'
);
}
else
{
...
...
@@ -4052,10 +4005,10 @@ prepare(): Promise\<void>
**示例:**
```
j
s
```
t
s
videoPlayer
.
prepare
().
then
(()
=>
{
console
.
info
(
'
prepare success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4076,8 +4029,8 @@ play(callback: AsyncCallback\<void>): void;
**示例:**
```
j
s
videoPlayer
.
play
((
err
)
=>
{
```
t
s
videoPlayer
.
play
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
play success!
'
);
}
else
{
...
...
@@ -4102,10 +4055,10 @@ play(): Promise\<void>;
**示例:**
```
j
s
```
t
s
videoPlayer
.
play
().
then
(()
=>
{
console
.
info
(
'
play success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4126,8 +4079,8 @@ pause(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
videoPlayer
.
pause
((
err
)
=>
{
```
t
s
videoPlayer
.
pause
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
pause success!
'
);
}
else
{
...
...
@@ -4152,10 +4105,10 @@ pause(): Promise\<void>
**示例:**
```
j
s
```
t
s
videoPlayer
.
pause
().
then
(()
=>
{
console
.
info
(
'
pause success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4176,8 +4129,8 @@ stop(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
videoPlayer
.
stop
((
err
)
=>
{
```
t
s
videoPlayer
.
stop
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
stop success!
'
);
}
else
{
...
...
@@ -4202,10 +4155,10 @@ stop(): Promise\<void>
**示例:**
```
j
s
```
t
s
videoPlayer
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4226,8 +4179,8 @@ reset(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
videoPlayer
.
reset
((
err
)
=>
{
```
t
s
videoPlayer
.
reset
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
reset success!
'
);
}
else
{
...
...
@@ -4252,10 +4205,10 @@ reset(): Promise\<void>
**示例:**
```
j
s
```
t
s
videoPlayer
.
reset
().
then
(()
=>
{
console
.
info
(
'
reset success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4277,9 +4230,9 @@ seek(timeMs: number, callback: AsyncCallback\<number>): void
**示例:**
```
j
s
let
seekTime
=
5000
;
videoPlayer
.
seek
(
seekTime
,
(
err
,
result
)
=>
{
```
t
s
let
seekTime
:
number
=
5000
;
videoPlayer
.
seek
(
seekTime
,
(
err
:
BusinessError
,
result
:
number
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
seek success!
'
);
}
else
{
...
...
@@ -4306,10 +4259,10 @@ seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void
**示例:**
```
j
s
```
t
s
import
media
from
'
@ohos.multimedia.media
'
let
seekTime
=
5000
;
videoPlayer
.
seek
(
seekTime
,
media
.
SeekMode
.
SEEK_NEXT_SYNC
,
(
err
,
result
)
=>
{
let
seekTime
:
number
=
5000
;
videoPlayer
.
seek
(
seekTime
,
media
.
SeekMode
.
SEEK_NEXT_SYNC
,
(
err
:
BusinessError
,
result
:
number
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
seek success!
'
);
}
else
{
...
...
@@ -4341,18 +4294,18 @@ seek(timeMs: number, mode?:SeekMode): Promise\<number>
**示例:**
```
j
s
```
t
s
import
media
from
'
@ohos.multimedia.media
'
let
seekTime
=
5000
;
videoPlayer
.
seek
(
seekTime
).
then
((
seekDoneTime
)
=>
{
// seekDoneTime表示seek完成后的时间点
let
seekTime
:
number
=
5000
;
videoPlayer
.
seek
(
seekTime
).
then
((
seekDoneTime
:
number
)
=>
{
// seekDoneTime表示seek完成后的时间点
console
.
info
(
'
seek success
'
);
}).
catch
((
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
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4374,9 +4327,9 @@ setVolume(vol: number, callback: AsyncCallback\<void>): void
**示例:**
```
j
s
let
vol
=
0.5
;
videoPlayer
.
setVolume
(
vol
,
(
err
,
result
)
=>
{
```
t
s
let
vol
:
number
=
0.5
;
videoPlayer
.
setVolume
(
vol
,
(
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
setVolume success!
'
);
}
else
{
...
...
@@ -4407,11 +4360,11 @@ setVolume(vol: number): Promise\<void>
**示例:**
```
j
s
let
vol
=
0.5
;
```
t
s
let
vol
:
number
=
0.5
;
videoPlayer
.
setVolume
(
vol
).
then
(()
=>
{
console
.
info
(
'
setVolume success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4432,8 +4385,8 @@ release(callback: AsyncCallback\<void>): void
**示例:**
```
j
s
videoPlayer
.
release
((
err
)
=>
{
```
t
s
videoPlayer
.
release
((
err
:
BusinessError
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
release success!
'
);
}
else
{
...
...
@@ -4458,10 +4411,10 @@ release(): Promise\<void>
**示例:**
```
j
s
```
t
s
videoPlayer
.
release
().
then
(()
=>
{
console
.
info
(
'
release success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4482,20 +4435,10 @@ getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
**示例:**
```
js
function
printfDescription
(
obj
)
{
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
)
=>
{
```
ts
videoPlayer
.
getTrackDescription
((
error
:
BusinessError
,
arrList
:
Array
<
media
.
MediaDescription
>
)
=>
{
if
((
arrList
)
!=
null
)
{
for
(
let
i
=
0
;
i
<
arrList
.
length
;
i
++
)
{
printfDescription
(
arrList
[
i
]);
}
console
.
info
(
'
video getTrackDescription success
'
);
}
else
{
console
.
log
(
`video getTrackDescription fail, error:
${
error
}
`
);
}
...
...
@@ -4518,28 +4461,16 @@ getTrackDescription(): Promise\<Array\<MediaDescription>>
**示例:**
```
js
function
printfDescription
(
obj
)
{
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
)
=>
{
```
ts
videoPlayer
.
getTrackDescription
().
then
((
arrList
:
Array
<
media
.
MediaDescription
>
)
=>
{
if
(
arrList
!=
null
)
{
arrayDescription
=
arrList
;
console
.
info
(
'
video getTrackDescription success
'
)
;
}
else
{
console
.
log
(
'
video getTrackDescription fail
'
);
}
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
}
`
);
});
for
(
let
i
=
0
;
i
<
arrayDescription
.
length
;
i
++
)
{
printfDescription
(
arrayDescription
[
i
]);
}
```
### setSpeed<sup>8+</sup>
...
...
@@ -4559,11 +4490,11 @@ setSpeed(speed:number, callback: AsyncCallback\<number>): void
**示例:**
```
j
s
```
t
s
import
media
from
'
@ohos.multimedia.media
'
let
speed
=
media
.
PlaybackSpeed
.
SPEED_FORWARD_2_00_X
;
videoPlayer
.
setSpeed
(
speed
,
(
err
,
result
)
=>
{
videoPlayer
.
setSpeed
(
speed
,
(
err
:
BusinessError
,
result
:
number
)
=>
{
if
(
err
==
null
)
{
console
.
info
(
'
setSpeed success!
'
);
}
else
{
...
...
@@ -4594,13 +4525,13 @@ setSpeed(speed:number): Promise\<number>
**示例:**
```
j
s
```
t
s
import
media
from
'
@ohos.multimedia.media
'
let
speed
=
media
.
PlaybackSpeed
.
SPEED_FORWARD_2_00_X
;
videoPlayer
.
setSpeed
(
speed
).
then
(()
=>
{
videoPlayer
.
setSpeed
(
speed
).
then
((
result
:
number
)
=>
{
console
.
info
(
'
setSpeed success
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`video catchCallback, error:
${
error
}
`
);
});
```
...
...
@@ -4622,7 +4553,7 @@ on(type: 'playbackCompleted', callback: Callback\<void>): void
**示例:**
```
j
s
```
t
s
videoPlayer
.
on
(
'
playbackCompleted
'
,
()
=>
{
console
.
info
(
'
playbackCompleted success!
'
);
});
...
...
@@ -4645,8 +4576,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe
**示例:**
```
j
s
videoPlayer
.
on
(
'
bufferingUpdate
'
,
(
infoType
,
value
)
=>
{
```
t
s
videoPlayer
.
on
(
'
bufferingUpdate
'
,
(
infoType
:
media
.
BufferingInfoType
,
value
:
number
)
=>
{
console
.
log
(
'
video bufferingInfo type:
'
+
infoType
);
console
.
log
(
'
video bufferingInfo value:
'
+
value
);
});
...
...
@@ -4669,7 +4600,7 @@ on(type: 'startRenderFrame', callback: Callback\<void>): void
**示例:**
```
j
s
```
t
s
videoPlayer
.
on
(
'
startRenderFrame
'
,
()
=>
{
console
.
info
(
'
startRenderFrame success!
'
);
});
...
...
@@ -4692,8 +4623,8 @@ on(type: 'videoSizeChanged', callback: (width: number, height: number) => void):
**示例:**
```
j
s
videoPlayer
.
on
(
'
videoSizeChanged
'
,
(
width
,
height
)
=>
{
```
t
s
videoPlayer
.
on
(
'
videoSizeChanged
'
,
(
width
:
number
,
height
:
number
)
=>
{
console
.
log
(
'
video width is:
'
+
width
);
console
.
log
(
'
video height is:
'
+
height
);
});
...
...
@@ -4716,8 +4647,8 @@ on(type: 'error', callback: ErrorCallback): void
**示例:**
```
j
s
videoPlayer
.
on
(
'
error
'
,
(
error
)
=>
{
// 设置'error'事件回调
```
t
s
videoPlayer
.
on
(
'
error
'
,
(
error
:
BusinessError
)
=>
{
// 设置'error'事件回调
console
.
error
(
`video error called, error:
${
error
}
`
);
});
videoPlayer
.
url
=
'
fd://error
'
;
//设置错误的播放地址,触发'error'事件
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录