Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzb_79
uni-app
提交
b741971a
U
uni-app
项目概览
lzb_79
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b741971a
编写于
4月 20, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(h5): createInnerAudioContext、hideKeyboard
上级
59c30bfc
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
549 addition
and
22 deletion
+549
-22
packages/uni-api/src/index.ts
packages/uni-api/src/index.ts
+4
-0
packages/uni-api/src/protocols/context/context.ts
packages/uni-api/src/protocols/context/context.ts
+3
-0
packages/uni-api/src/protocols/keyboard/keyboard.ts
packages/uni-api/src/protocols/keyboard/keyboard.ts
+2
-0
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+183
-22
packages/uni-h5/src/service/api/context/createInnerAudioContext.ts
...uni-h5/src/service/api/context/createInnerAudioContext.ts
+336
-0
packages/uni-h5/src/service/api/index.ts
packages/uni-h5/src/service/api/index.ts
+4
-0
packages/uni-h5/src/service/api/keyboard/keyboard.ts
packages/uni-h5/src/service/api/keyboard/keyboard.ts
+17
-0
未找到文件。
packages/uni-api/src/index.ts
浏览文件 @
b741971a
...
...
@@ -11,6 +11,8 @@ export * from './service/ui/tabBar'
// protocols
export
*
from
'
./protocols/base/canIUse
'
export
*
from
'
./protocols/context/context
'
export
*
from
'
./protocols/device/makePhoneCall
'
export
*
from
'
./protocols/device/setClipboardData
'
export
*
from
'
./protocols/device/accelerometer
'
...
...
@@ -22,6 +24,8 @@ export * from './protocols/storage/storage'
export
*
from
'
./protocols/file/getFileInfo
'
export
*
from
'
./protocols/file/openDocument
'
export
*
from
'
./protocols/keyboard/keyboard
'
export
*
from
'
./protocols/location/chooseLocation
'
export
*
from
'
./protocols/location/getLocation
'
export
*
from
'
./protocols/location/openLocation
'
...
...
packages/uni-api/src/protocols/context/context.ts
浏览文件 @
b741971a
...
...
@@ -30,3 +30,6 @@ export const CreateCanvasContextProtocol: ProtocolOptions<String | Object>[] = [
type
:
Object
,
},
]
export
const
API_CREATE_INNER_AUDIO_CONTEXT
=
'
createInnerAudioContext
'
export
type
API_TYPE_CREATEE_INNER_AUDIO_CONTEXT
=
typeof
uni
.
createInnerAudioContext
packages/uni-api/src/protocols/keyboard/keyboard.ts
0 → 100644
浏览文件 @
b741971a
export
const
API_HIDE_KEYBOARD
=
'
hideKeyboard
'
export
type
API_TYPE_HIDE_KEYBOARD
=
typeof
uni
.
hideKeyboard
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
b741971a
...
...
@@ -604,7 +604,7 @@ var safeAreaInsets = {
onChange
,
offChange
};
var
out
=
safeAreaInsets
;
var
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
=
safeAreaInsets
;
function
getWindowOffset
()
{
const
style
=
document
.
documentElement
.
style
;
const
top
=
parseInt
(
style
.
getPropertyValue
(
"
--window-top
"
));
...
...
@@ -612,10 +612,10 @@ function getWindowOffset() {
const
left
=
parseInt
(
style
.
getPropertyValue
(
"
--window-left
"
));
const
right
=
parseInt
(
style
.
getPropertyValue
(
"
--window-right
"
));
return
{
top
:
top
?
top
+
out
.
top
:
0
,
bottom
:
bottom
?
bottom
+
out
.
bottom
:
0
,
left
:
left
?
left
+
out
.
left
:
0
,
right
:
right
?
right
+
out
.
right
:
0
top
:
top
?
top
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
:
0
,
bottom
:
bottom
?
bottom
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
:
0
,
left
:
left
?
left
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
left
:
0
,
right
:
right
?
right
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
:
0
};
}
function
findUniTarget
(
$event
,
$el
)
{
...
...
@@ -1101,7 +1101,7 @@ function normalizePageMeta(pageMeta) {
let
offset
=
rpx2px
(
refreshOptions
.
offset
);
const
{
type
}
=
navigationBar
;
if
(
type
!==
"
transparent
"
&&
type
!==
"
none
"
)
{
offset
+=
NAVBAR_HEIGHT
+
out
.
top
;
offset
+=
NAVBAR_HEIGHT
+
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
;
}
refreshOptions
.
height
=
rpx2px
(
refreshOptions
.
height
);
refreshOptions
.
range
=
rpx2px
(
refreshOptions
.
range
);
...
...
@@ -1640,7 +1640,7 @@ var subscriber = {
}
}
};
function
hideKeyboard
()
{
function
hideKeyboard
$1
()
{
document
.
activeElement
.
blur
();
}
function
iosHideKeyboard
()
{
...
...
@@ -1680,7 +1680,7 @@ var keyboard = {
initKeyboard
(
el
)
{
el
.
addEventListener
(
"
focus
"
,
()
=>
{
this
.
hideKeyboardTemp
=
function
()
{
hideKeyboard
();
hideKeyboard
$1
();
};
UniViewJSBridge
.
subscribe
(
"
hideKeyboard
"
,
this
.
hideKeyboardTemp
);
document
.
addEventListener
(
"
click
"
,
iosHideKeyboard
,
false
);
...
...
@@ -4309,6 +4309,7 @@ const promiseInterceptor = {
}
};
const
API_CREATE_VIDEO_CONTEXT
=
"
createVideoContext
"
;
const
API_CREATE_INNER_AUDIO_CONTEXT
=
"
createInnerAudioContext
"
;
const
RATES
=
[
0.5
,
0.8
,
1
,
1.25
,
1.5
,
2
];
class
VideoContext
{
constructor
(
id2
,
vm
)
{
...
...
@@ -4508,6 +4509,7 @@ const OpenDocumentProtocol = {
},
fileType
:
String
};
const
API_HIDE_KEYBOARD
=
"
hideKeyboard
"
;
const
API_GET_LOCATION
=
"
getLocation
"
;
const
coordTypes
=
[
"
WGS84
"
,
"
GCJ02
"
];
const
GetLocationOptions
=
{
...
...
@@ -10663,6 +10665,156 @@ const canIUse = defineSyncApi(API_CAN_I_USE, (schema) => {
}
return
true
;
},
CanIUseProtocol
);
const
innerAudioContextEventNames
=
[
"
onCanplay
"
,
"
onPlay
"
,
"
onPause
"
,
"
onStop
"
,
"
onEnded
"
,
"
onTimeUpdate
"
,
"
onError
"
,
"
onWaiting
"
,
"
onSeeking
"
,
"
onSeeked
"
];
const
innerAudioContextOffEventNames
=
[
"
offCanplay
"
,
"
offPlay
"
,
"
offPause
"
,
"
offStop
"
,
"
offEnded
"
,
"
offTimeUpdate
"
,
"
offError
"
,
"
offWaiting
"
,
"
offSeeking
"
,
"
offSeeked
"
];
const
propertys
=
[
"
src
"
,
"
autoplay
"
,
"
loop
"
,
"
duration
"
,
"
currentTime
"
,
"
paused
"
,
"
volume
"
];
class
InnerAudioContext
{
constructor
()
{
this
.
_src
=
""
;
var
audio
=
this
.
_audio
=
new
Audio
();
this
.
_stoping
=
false
;
propertys
.
forEach
((
property
)
=>
{
Object
.
defineProperty
(
this
,
property
,
{
set
:
property
===
"
src
"
?
(
src
)
=>
{
audio
.
src
=
getRealPath
(
src
);
this
.
_src
=
src
;
return
src
;
}
:
(
val
)
=>
{
audio
.
setAttribute
(
property
,
val
);
return
val
;
},
get
:
property
===
"
src
"
?
()
=>
{
return
this
.
_src
;
}
:
()
=>
{
return
audio
[
property
];
}
});
});
this
.
startTime
=
0
;
Object
.
defineProperty
(
this
,
"
obeyMuteSwitch
"
,
{
set
:
()
=>
false
,
get
:
()
=>
false
});
Object
.
defineProperty
(
this
,
"
buffered
"
,
{
set
:
()
=>
false
,
get
()
{
var
buffered
=
audio
.
buffered
;
if
(
buffered
.
length
)
{
return
buffered
.
end
(
buffered
.
length
-
1
);
}
else
{
return
0
;
}
}
});
this
.
_events
=
{};
innerAudioContextEventNames
.
forEach
((
eventName
)
=>
{
this
.
_events
[
eventName
]
=
[];
});
audio
.
addEventListener
(
"
loadedmetadata
"
,
()
=>
{
var
startTime
=
Number
(
this
.
startTime
)
||
0
;
if
(
startTime
>
0
)
{
audio
.
currentTime
=
startTime
;
}
});
var
eventNames
=
[
"
canplay
"
,
"
play
"
,
"
pause
"
,
"
ended
"
,
"
timeUpdate
"
,
"
error
"
,
"
waiting
"
,
"
seeking
"
,
"
seeked
"
];
var
stopEventNames
=
[
"
canplay
"
,
"
pause
"
,
"
seeking
"
,
"
seeked
"
,
"
timeUpdate
"
];
eventNames
.
forEach
((
eventName
)
=>
{
audio
.
addEventListener
(
eventName
.
toLowerCase
(),
()
=>
{
if
(
this
.
_stoping
&&
stopEventNames
.
indexOf
(
eventName
)
>=
0
)
{
return
;
}
const
EventName
=
`on
${
eventName
.
substr
(
0
,
1
).
toUpperCase
()}${
eventName
.
substr
(
1
)}
`
;
this
.
_events
[
EventName
].
forEach
((
callback
)
=>
{
callback
();
});
},
false
);
});
}
play
()
{
this
.
_stoping
=
false
;
this
.
_audio
.
play
();
}
pause
()
{
this
.
_audio
.
pause
();
}
stop
()
{
this
.
_stoping
=
true
;
this
.
_audio
.
pause
();
this
.
_audio
.
currentTime
=
0
;
this
.
_events
.
onStop
.
forEach
((
callback
)
=>
{
callback
();
});
}
seek
(
position
)
{
this
.
_stoping
=
false
;
position
=
Number
(
position
);
if
(
typeof
position
===
"
number
"
&&
!
isNaN
(
position
))
{
this
.
_audio
.
currentTime
=
position
;
}
}
destroy
()
{
this
.
stop
();
}
}
innerAudioContextEventNames
.
forEach
((
eventName
)
=>
{
InnerAudioContext
.
prototype
[
eventName
]
=
function
(
callback
)
{
if
(
typeof
callback
===
"
function
"
)
{
this
.
_events
[
eventName
].
push
(
callback
);
}
};
});
innerAudioContextOffEventNames
.
forEach
((
eventName
)
=>
{
InnerAudioContext
.
prototype
[
eventName
]
=
function
(
callback
)
{
var
handle
=
this
.
_events
[
eventName
.
replace
(
"
off
"
,
"
on
"
)];
var
index2
=
handle
.
indexOf
(
callback
);
if
(
index2
>=
0
)
{
handle
.
splice
(
index2
,
1
);
}
};
});
const
createInnerAudioContext
=
defineSyncApi
(
API_CREATE_INNER_AUDIO_CONTEXT
,
()
=>
{
return
new
InnerAudioContext
();
});
const
makePhoneCall
=
defineAsyncApi
(
API_MAKE_PHONE_CALL
,
({
phoneNumber
},
{
resolve
})
=>
{
window
.
location
.
href
=
`tel:
${
phoneNumber
}
`
;
return
resolve
();
...
...
@@ -10676,7 +10828,7 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
const
windowWidth
=
getWindowWidth
(
screenWidth
);
let
windowHeight
=
window
.
innerHeight
;
const
language
=
navigator
.
language
;
const
statusBarHeight
=
out
.
top
;
const
statusBarHeight
=
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
;
let
osname
;
let
osversion
;
let
model
;
...
...
@@ -10789,12 +10941,12 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
const
system
=
`
${
osname
}
${
osversion
}
`
;
const
platform
=
osname
.
toLocaleLowerCase
();
const
safeArea
=
{
left
:
out
.
left
,
right
:
windowWidth
-
out
.
right
,
top
:
out
.
top
,
bottom
:
windowHeight
-
out
.
bottom
,
width
:
windowWidth
-
out
.
left
-
out
.
right
,
height
:
windowHeight
-
out
.
top
-
out
.
bottom
left
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
left
,
right
:
windowWidth
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
,
top
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
,
bottom
:
windowHeight
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
,
width
:
windowWidth
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out
.
left
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
,
height
:
windowHeight
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out
.
top
-
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
};
const
{
top
:
windowTop
,
bottom
:
windowBottom
}
=
getWindowOffset
();
windowHeight
-=
windowTop
;
...
...
@@ -10814,10 +10966,10 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
model
,
safeArea
,
safeAreaInsets
:
{
top
:
out
.
top
,
right
:
out
.
right
,
bottom
:
out
.
bottom
,
left
:
out
.
left
top
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
top
,
right
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
right
,
bottom
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
bottom
,
left
:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out
.
left
}
};
});
...
...
@@ -11180,6 +11332,13 @@ const openDocument = defineAsyncApi(API_OPEN_DOCUMENT, ({filePath}, {resolve}) =
window
.
open
(
filePath
);
return
resolve
();
},
OpenDocumentProtocol
,
OpenDocumentOptions
);
const
hideKeyboard
=
defineAsyncApi
(
API_HIDE_KEYBOARD
,
(
args
,
{
resolve
,
reject
})
=>
{
const
activeElement
=
document
.
activeElement
;
if
(
activeElement
&&
(
activeElement
.
tagName
===
"
TEXTAREA
"
||
activeElement
.
tagName
===
"
INPUT
"
))
{
activeElement
.
blur
();
resolve
();
}
});
function
getServiceAddress
()
{
return
window
.
location
.
protocol
+
"
//
"
+
window
.
location
.
host
;
}
...
...
@@ -11828,14 +11987,14 @@ ${e2};at socketTask.on${capitalize(name)} callback function
}
});
});
const
propertys
=
[
const
propertys
2
=
[
"
CLOSED
"
,
"
CLOSING
"
,
"
CONNECTING
"
,
"
OPEN
"
,
"
readyState
"
];
propertys
.
forEach
((
property
)
=>
{
propertys
2
.
forEach
((
property
)
=>
{
Object
.
defineProperty
(
this
,
property
,
{
get
()
{
return
webSocket
[
property
];
...
...
@@ -12306,6 +12465,7 @@ var api = /* @__PURE__ */ Object.freeze({
cssConstant
,
cssBackdropFilter
,
canIUse
,
createInnerAudioContext
,
makePhoneCall
,
getSystemInfo
,
getSystemInfoSync
,
...
...
@@ -12334,6 +12494,7 @@ var api = /* @__PURE__ */ Object.freeze({
getStorageInfo
,
getFileInfo
,
openDocument
,
hideKeyboard
,
getImageInfo
,
getVideoInfo
,
chooseFile
,
...
...
@@ -13404,4 +13565,4 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
]);
}
_sfc_main
.
render
=
_sfc_render
;
export
{
_sfc_main$1
as
AsyncErrorComponent
,
_sfc_main
as
AsyncLoadingComponent
,
_sfc_main$l
as
Audio
,
index$5
as
Button
,
_sfc_main$k
as
Canvas
,
_sfc_main$j
as
Checkbox
,
_sfc_main$i
as
CheckboxGroup
,
_sfc_main$h
as
Editor
,
index$6
as
Form
,
index$4
as
Icon
,
index$3
as
Image
,
_sfc_main$g
as
Input
,
_sfc_main$f
as
Label
,
LayoutComponent
,
_sfc_main$e
as
MovableView
,
_sfc_main$d
as
Navigator
,
index
as
PageComponent
,
_sfc_main$c
as
Progress
,
_sfc_main$b
as
Radio
,
_sfc_main$a
as
RadioGroup
,
ResizeSensor
,
_sfc_main$9
as
RichText
,
_sfc_main$8
as
ScrollView
,
_sfc_main$7
as
Slider
,
_sfc_main$6
as
SwiperItem
,
_sfc_main$5
as
Switch
,
index$2
as
Text
,
_sfc_main$4
as
Textarea
,
UniServiceJSBridge$1
as
UniServiceJSBridge
,
UniViewJSBridge$1
as
UniViewJSBridge
,
_sfc_main$3
as
Video
,
index$1
as
View
,
addInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
canIUse
,
chooseFile
,
chooseImage
,
chooseVideo
,
clearStorage
,
clearStorageSync
,
closeSocket
,
connectSocket
,
createIn
tersectionObserver
,
createSelectorQuery
,
createVideoContext
,
cssBackdropFilter
,
cssConstant
,
cssEnv
,
cssVar
,
downloadFile
,
getApp$1
as
getApp
,
getCurrentPages$1
as
getCurrentPages
,
getFileInfo
,
getImageInfo
,
getLocation
,
getNetworkType
,
getStorage
,
getStorageInfo
,
getStorageInfoSync
,
getStorageSync
,
getSystemInfo
,
getSystemInfoSync
,
getVideoInfo
,
hideLoading
,
hideNavigationBarLoading
,
hideTabBar
,
hideTabBarRedDot
,
hideToast
,
makePhoneCall
,
navigateBack
,
navigateTo
,
offAccelerometerChange
,
offCompassChange
,
offNetworkStatusChange
,
onAccelerometerChange
,
onCompassChange
,
onNetworkStatusChange
,
onSocketClose
,
onSocketError
,
onSocketMessage
,
onSocketOpen
,
onTabBarMidButtonTap
,
openDocument
,
index$7
as
plugin
,
promiseInterceptor
,
reLaunch
,
redirectTo
,
removeInterceptor
,
removeStorage
,
removeStorageSync
,
removeTabBarBadge
,
request
,
sendSocketMessage
,
setNavigationBarColor
,
setNavigationBarTitle
,
setStorage
,
setStorageSync
,
setTabBarBadge
,
setTabBarItem
,
setTabBarStyle
,
setupApp
,
setupPage
,
showActionSheet
,
showLoading
,
showModal
,
showNavigationBarLoading
,
showTabBar
,
showTabBarRedDot
,
showToast
,
startAccelerometer
,
startCompass
,
stopAccelerometer
,
stopCompass
,
switchTab
,
uni$1
as
uni
,
uploadFile
,
upx2px
,
useCustomEvent
,
usePageRoute
,
useSubscribe
,
vibrateLong
,
vibrateShort
};
export
{
_sfc_main$1
as
AsyncErrorComponent
,
_sfc_main
as
AsyncLoadingComponent
,
_sfc_main$l
as
Audio
,
index$5
as
Button
,
_sfc_main$k
as
Canvas
,
_sfc_main$j
as
Checkbox
,
_sfc_main$i
as
CheckboxGroup
,
_sfc_main$h
as
Editor
,
index$6
as
Form
,
index$4
as
Icon
,
index$3
as
Image
,
_sfc_main$g
as
Input
,
_sfc_main$f
as
Label
,
LayoutComponent
,
_sfc_main$e
as
MovableView
,
_sfc_main$d
as
Navigator
,
index
as
PageComponent
,
_sfc_main$c
as
Progress
,
_sfc_main$b
as
Radio
,
_sfc_main$a
as
RadioGroup
,
ResizeSensor
,
_sfc_main$9
as
RichText
,
_sfc_main$8
as
ScrollView
,
_sfc_main$7
as
Slider
,
_sfc_main$6
as
SwiperItem
,
_sfc_main$5
as
Switch
,
index$2
as
Text
,
_sfc_main$4
as
Textarea
,
UniServiceJSBridge$1
as
UniServiceJSBridge
,
UniViewJSBridge$1
as
UniViewJSBridge
,
_sfc_main$3
as
Video
,
index$1
as
View
,
addInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
canIUse
,
chooseFile
,
chooseImage
,
chooseVideo
,
clearStorage
,
clearStorageSync
,
closeSocket
,
connectSocket
,
createIn
nerAudioContext
,
createIntersectionObserver
,
createSelectorQuery
,
createVideoContext
,
cssBackdropFilter
,
cssConstant
,
cssEnv
,
cssVar
,
downloadFile
,
getApp$1
as
getApp
,
getCurrentPages$1
as
getCurrentPages
,
getFileInfo
,
getImageInfo
,
getLocation
,
getNetworkType
,
getStorage
,
getStorageInfo
,
getStorageInfoSync
,
getStorageSync
,
getSystemInfo
,
getSystemInfoSync
,
getVideoInfo
,
hideKeyboard
,
hideLoading
,
hideNavigationBarLoading
,
hideTabBar
,
hideTabBarRedDot
,
hideToast
,
makePhoneCall
,
navigateBack
,
navigateTo
,
offAccelerometerChange
,
offCompassChange
,
offNetworkStatusChange
,
onAccelerometerChange
,
onCompassChange
,
onNetworkStatusChange
,
onSocketClose
,
onSocketError
,
onSocketMessage
,
onSocketOpen
,
onTabBarMidButtonTap
,
openDocument
,
index$7
as
plugin
,
promiseInterceptor
,
reLaunch
,
redirectTo
,
removeInterceptor
,
removeStorage
,
removeStorageSync
,
removeTabBarBadge
,
request
,
sendSocketMessage
,
setNavigationBarColor
,
setNavigationBarTitle
,
setStorage
,
setStorageSync
,
setTabBarBadge
,
setTabBarItem
,
setTabBarStyle
,
setupApp
,
setupPage
,
showActionSheet
,
showLoading
,
showModal
,
showNavigationBarLoading
,
showTabBar
,
showTabBarRedDot
,
showToast
,
startAccelerometer
,
startCompass
,
stopAccelerometer
,
stopCompass
,
switchTab
,
uni$1
as
uni
,
uploadFile
,
upx2px
,
useCustomEvent
,
usePageRoute
,
useSubscribe
,
vibrateLong
,
vibrateShort
};
packages/uni-h5/src/service/api/context/createInnerAudioContext.ts
0 → 100644
浏览文件 @
b741971a
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
import
{
API_CREATE_INNER_AUDIO_CONTEXT
,
defineSyncApi
,
}
from
'
@dcloudio/uni-api
'
import
type
{
API_TYPE_CREATEE_INNER_AUDIO_CONTEXT
}
from
'
@dcloudio/uni-api
'
//#region types
type
InnerAudioContextEvent
=
|
'
onCanplay
'
|
'
onPlay
'
|
'
onPause
'
|
'
onStop
'
|
'
onEnded
'
|
'
onTimeUpdate
'
|
'
onError
'
|
'
onWaiting
'
|
'
onSeeking
'
|
'
onSeeked
'
type
InnerAudioContextOff
=
|
'
offCanplay
'
|
'
offPlay
'
|
'
offPause
'
|
'
offStop
'
|
'
offEnded
'
|
'
offTimeUpdate
'
|
'
offError
'
|
'
offWaiting
'
|
'
offSeeking
'
|
'
offSeeked
'
type
Property
=
|
'
src
'
|
'
autoplay
'
|
'
loop
'
|
'
duration
'
|
'
currentTime
'
|
'
paused
'
|
'
volume
'
type
InnerAudioProperty
=
keyof
Pick
<
HTMLMediaElement
,
Property
>
type
VoidFunction
=
(
callback
:
(
result
:
any
)
=>
void
)
=>
void
//#endregion
/**
* 可以批量设置的监听事件
*/
const
innerAudioContextEventNames
:
InnerAudioContextEvent
[]
=
[
'
onCanplay
'
,
'
onPlay
'
,
'
onPause
'
,
'
onStop
'
,
'
onEnded
'
,
'
onTimeUpdate
'
,
'
onError
'
,
'
onWaiting
'
,
'
onSeeking
'
,
'
onSeeked
'
,
]
const
innerAudioContextOffEventNames
:
InnerAudioContextOff
[]
=
[
'
offCanplay
'
,
'
offPlay
'
,
'
offPause
'
,
'
offStop
'
,
'
offEnded
'
,
'
offTimeUpdate
'
,
'
offError
'
,
'
offWaiting
'
,
'
offSeeking
'
,
'
offSeeked
'
,
]
// 和audio对象同名同效果的属性
const
propertys
:
InnerAudioProperty
[]
=
[
'
src
'
,
'
autoplay
'
,
'
loop
'
,
'
duration
'
,
'
currentTime
'
,
'
paused
'
,
'
volume
'
,
]
/**
* 音频上下文对象
*/
class
InnerAudioContext
implements
UniApp
.
InnerAudioContext
{
/**
* 当前音频的长度(单位:s),只有在当前有合法的 src 时返回
*/
duration
!
:
number
/**
* 当前音频的播放位置(单位:s),只有在当前有合法的 src 时返回
*/
currentTime
!
:
number
/**
* 当前是是否暂停或停止状态,true 表示暂停或停止,false 表示正在播放
*/
paused
!
:
boolean
/**
* 音频的数据链接,用于直接播放。
*/
src
!
:
string
/**
* 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲
*/
buffered
!
:
number
/**
* 是否自动开始播放,默认 false
*/
autoplay
!
:
boolean
/**
* 是否循环播放,默认 false
*/
loop
!
:
boolean
/**
* 是否遵循系统静音开关,当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音,默认值 true
*/
obeyMuteSwitch
!
:
boolean
/**
* 音量。范围 0~1。
*/
volume
!
:
number
/**
* 原始音频对象
*/
_audio
:
HTMLAudioElement
/**
* 是否暂停中
*/
_stoping
:
boolean
/**
* 开始时间
*/
startTime
:
number
/**
* 事件监听
*/
_events
:
Partial
<
Record
<
InnerAudioContextEvent
,
Array
<
Function
>>>
/**
* 音频地址
*/
_src
:
string
=
''
/**
* 音频上下文初始化
*/
constructor
()
{
var
audio
=
(
this
.
_audio
=
new
Audio
())
this
.
_stoping
=
false
propertys
.
forEach
((
property
)
=>
{
Object
.
defineProperty
(
this
,
property
,
{
set
:
property
===
'
src
'
?
(
src
)
=>
{
audio
.
src
=
getRealPath
(
src
)
this
.
_src
=
src
return
src
}
:
(
val
)
=>
{
// audio[property] = val
audio
.
setAttribute
(
property
,
val
)
return
val
},
get
:
property
===
'
src
'
?
()
=>
{
return
this
.
_src
}
:
()
=>
{
return
audio
[
property
]
},
})
})
this
.
startTime
=
0
Object
.
defineProperty
(
this
,
'
obeyMuteSwitch
'
,
{
set
:
()
=>
false
,
get
:
()
=>
false
,
})
Object
.
defineProperty
(
this
,
'
buffered
'
,
{
set
:
()
=>
false
,
get
()
{
var
buffered
=
audio
.
buffered
if
(
buffered
.
length
)
{
return
buffered
.
end
(
buffered
.
length
-
1
)
}
else
{
return
0
}
},
})
// 初始化事件监听列表
this
.
_events
=
{}
innerAudioContextEventNames
.
forEach
((
eventName
)
=>
{
this
.
_events
[
eventName
]
=
[]
})
audio
.
addEventListener
(
'
loadedmetadata
'
,
()
=>
{
var
startTime
=
Number
(
this
.
startTime
)
||
0
if
(
startTime
>
0
)
{
audio
.
currentTime
=
startTime
}
})
// 和audio对象同名同效果的事件
var
eventNames
=
[
'
canplay
'
,
'
play
'
,
'
pause
'
,
'
ended
'
,
'
timeUpdate
'
,
'
error
'
,
'
waiting
'
,
'
seeking
'
,
'
seeked
'
,
]
var
stopEventNames
=
[
'
canplay
'
,
'
pause
'
,
'
seeking
'
,
'
seeked
'
,
'
timeUpdate
'
]
eventNames
.
forEach
((
eventName
)
=>
{
audio
.
addEventListener
(
eventName
.
toLowerCase
(),
()
=>
{
// stop事件过滤
if
(
this
.
_stoping
&&
stopEventNames
.
indexOf
(
eventName
)
>=
0
)
{
return
}
const
EventName
=
`on
${
eventName
.
substr
(
0
,
1
)
.
toUpperCase
()}${
eventName
.
substr
(
1
)}
`
as
InnerAudioContextEvent
this
.
_events
[
EventName
]
!
.
forEach
((
callback
)
=>
{
callback
()
})
},
false
)
})
}
/**
* 播放
*/
play
()
{
this
.
_stoping
=
false
this
.
_audio
.
play
()
}
/**
* 暂停
*/
pause
()
{
this
.
_audio
.
pause
()
}
/**
* 停止
*/
stop
()
{
this
.
_stoping
=
true
this
.
_audio
.
pause
()
this
.
_audio
.
currentTime
=
0
this
.
_events
.
onStop
!
.
forEach
((
callback
)
=>
{
callback
()
})
}
/**
* 跳转到
* @param {number} position
*/
seek
(
position
:
number
)
{
this
.
_stoping
=
false
position
=
Number
(
position
)
if
(
typeof
position
===
'
number
'
&&
!
isNaN
(
position
))
{
this
.
_audio
.
currentTime
=
position
}
}
/**
* 销毁
*/
destroy
()
{
this
.
stop
()
}
'
onCanplay
'
:
VoidFunction
'
onPlay
'
:
VoidFunction
'
onPause
'
:
VoidFunction
'
onStop
'
:
VoidFunction
'
onEnded
'
:
VoidFunction
'
onTimeUpdate
'
:
VoidFunction
'
onError
'
:
VoidFunction
'
onWaiting
'
:
VoidFunction
'
onSeeking
'
:
VoidFunction
'
onSeeked
'
:
VoidFunction
'
offCanplay
'
:
VoidFunction
'
offPlay
'
:
VoidFunction
'
offPause
'
:
VoidFunction
'
offStop
'
:
VoidFunction
'
offEnded
'
:
VoidFunction
'
offTimeUpdate
'
:
VoidFunction
'
offError
'
:
VoidFunction
'
offWaiting
'
:
VoidFunction
'
offSeeking
'
:
VoidFunction
'
offSeeked
'
:
VoidFunction
}
// 批量设置音频上下文事件监听方法
innerAudioContextEventNames
.
forEach
((
eventName
)
=>
{
InnerAudioContext
.
prototype
[
eventName
]
=
function
(
callback
:
Function
)
{
if
(
typeof
callback
===
'
function
'
)
{
this
.
_events
[
eventName
]
!
.
push
(
callback
)
}
}
})
// 批量设置音频上下文事件取消监听方法
innerAudioContextOffEventNames
.
forEach
((
eventName
)
=>
{
InnerAudioContext
.
prototype
[
eventName
]
=
function
(
callback
:
Function
)
{
var
handle
=
this
.
_events
[
eventName
.
replace
(
'
off
'
,
'
on
'
)
as
InnerAudioContextEvent
]
var
index
=
handle
!
.
indexOf
(
callback
)
if
(
index
>=
0
)
{
handle
!
.
splice
(
index
,
1
)
}
}
})
/**
* 创建音频上下文
*/
export
const
createInnerAudioContext
=
defineSyncApi
<
API_TYPE_CREATEE_INNER_AUDIO_CONTEXT
>
(
API_CREATE_INNER_AUDIO_CONTEXT
,
()
=>
{
return
new
InnerAudioContext
()
}
)
packages/uni-h5/src/service/api/index.ts
浏览文件 @
b741971a
export
*
from
'
./base/canIUse
'
export
*
from
'
./context/createInnerAudioContext
'
export
*
from
'
./device/makePhoneCall
'
export
*
from
'
./device/getSystemInfo
'
export
*
from
'
./device/getSystemInfoSync
'
...
...
@@ -13,6 +15,8 @@ export * from './storage/storage'
export
*
from
'
./file/getFileInfo
'
export
*
from
'
./file/openDocument
'
export
*
from
'
./keyboard/keyboard
'
export
*
from
'
./media/getImageInfo
'
export
*
from
'
./media/getVideoInfo
'
export
*
from
'
./media/chooseFile
'
...
...
packages/uni-h5/src/service/api/keyboard/keyboard.ts
0 → 100644
浏览文件 @
b741971a
import
{
API_HIDE_KEYBOARD
,
defineAsyncApi
}
from
'
@dcloudio/uni-api
'
import
type
{
API_TYPE_HIDE_KEYBOARD
}
from
'
@dcloudio/uni-api
'
export
const
hideKeyboard
=
defineAsyncApi
<
API_TYPE_HIDE_KEYBOARD
>
(
API_HIDE_KEYBOARD
,
(
args
,
{
resolve
,
reject
})
=>
{
const
activeElement
=
document
.
activeElement
as
HTMLInputElement
if
(
activeElement
&&
(
activeElement
.
tagName
===
'
TEXTAREA
'
||
activeElement
.
tagName
===
'
INPUT
'
)
)
{
activeElement
.
blur
()
resolve
()
}
}
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录