Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_68066342
uni-app
提交
bd7d9cd3
U
uni-app
项目概览
m0_68066342
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
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,发现更多精彩内容 >>
提交
bd7d9cd3
编写于
4月 07, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复App端无法获取音频暂停状态的问题
上级
26516432
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
28 deletion
+28
-28
src/platforms/app-plus/service/api/context/audio.js
src/platforms/app-plus/service/api/context/audio.js
+2
-2
src/platforms/app-plus/service/api/context/background-audio.js
...latforms/app-plus/service/api/context/background-audio.js
+26
-26
未找到文件。
src/platforms/app-plus/service/api/context/audio.js
浏览文件 @
bd7d9cd3
...
@@ -122,7 +122,7 @@ export function getAudioState ({
...
@@ -122,7 +122,7 @@ export function getAudioState ({
errMsg
:
'
getAudioState:ok
'
,
errMsg
:
'
getAudioState:ok
'
,
duration
:
1
e3
*
(
audio
.
getDuration
()
||
0
),
duration
:
1
e3
*
(
audio
.
getDuration
()
||
0
),
currentTime
:
audio
.
isStopped
?
0
:
1
e3
*
audio
.
getPosition
(),
currentTime
:
audio
.
isStopped
?
0
:
1
e3
*
audio
.
getPosition
(),
paused
:
audio
.
isPaused
,
paused
:
audio
.
isPaused
()
,
src
,
src
,
volume
,
volume
,
startTime
:
1
e3
*
startTime
,
startTime
:
1
e3
*
startTime
,
...
@@ -138,7 +138,7 @@ export function operateAudio ({
...
@@ -138,7 +138,7 @@ export function operateAudio ({
const
audio
=
audios
[
audioId
]
const
audio
=
audios
[
audioId
]
const
operationTypes
=
[
'
play
'
,
'
pause
'
,
'
stop
'
]
const
operationTypes
=
[
'
play
'
,
'
pause
'
,
'
stop
'
]
if
(
operationTypes
.
indexOf
(
operationType
)
>=
0
)
{
if
(
operationTypes
.
indexOf
(
operationType
)
>=
0
)
{
audio
[
operationType
===
operationTypes
[
0
]
&&
audio
.
isPaused
?
'
resume
'
:
operationType
]()
audio
[
operationType
===
operationTypes
[
0
]
&&
audio
.
isPaused
()
?
'
resume
'
:
operationType
]()
}
else
if
(
operationType
===
'
seek
'
)
{
}
else
if
(
operationType
===
'
seek
'
)
{
audio
.
seekTo
(
currentTime
/
1
e3
)
audio
.
seekTo
(
currentTime
/
1
e3
)
}
}
...
...
src/platforms/app-plus/service/api/context/background-audio.js
浏览文件 @
bd7d9cd3
...
@@ -6,9 +6,9 @@ import {
...
@@ -6,9 +6,9 @@ import {
publish
publish
}
from
'
../../bridge
'
}
from
'
../../bridge
'
let
audio
let
audio
let
timeUpdateTimer
=
null
let
timeUpdateTimer
=
null
const
TIME_UPDATE
=
250
const
TIME_UPDATE
=
250
const
publishBackgroundAudioStateChange
=
(
state
,
res
=
{})
=>
publish
(
'
onBackgroundAudioStateChange
'
,
Object
.
assign
({
const
publishBackgroundAudioStateChange
=
(
state
,
res
=
{})
=>
publish
(
'
onBackgroundAudioStateChange
'
,
Object
.
assign
({
...
@@ -31,15 +31,15 @@ function initMusic () {
...
@@ -31,15 +31,15 @@ function initMusic () {
audio
.
addEventListener
(
event
,
()
=>
{
audio
.
addEventListener
(
event
,
()
=>
{
// 添加 isStopped 属性是为了解决 安卓设备停止播放后获取播放进度不正确的问题
// 添加 isStopped 属性是为了解决 安卓设备停止播放后获取播放进度不正确的问题
if
(
event
===
'
play
'
)
{
if
(
event
===
'
play
'
)
{
audio
.
isStopped
=
false
audio
.
isStopped
=
false
startTimeUpdateTimer
()
startTimeUpdateTimer
()
}
else
if
(
event
===
'
stop
'
)
{
}
else
if
(
event
===
'
stop
'
)
{
audio
.
isStopped
=
true
audio
.
isStopped
=
true
}
}
if
(
event
===
'
pause
'
||
event
===
'
ended
'
||
event
===
'
stop
'
)
{
if
(
event
===
'
pause
'
||
event
===
'
ended
'
||
event
===
'
stop
'
)
{
stopTimeUpdateTimer
()
stopTimeUpdateTimer
()
}
}
const
eventName
=
`onMusic
${
event
[
0
].
toUpperCase
()
+
event
.
substr
(
1
)}
`
const
eventName
=
`onMusic
${
event
[
0
].
toUpperCase
()
+
event
.
substr
(
1
)}
`
publish
(
eventName
,
{
publish
(
eventName
,
{
...
@@ -51,13 +51,13 @@ function initMusic () {
...
@@ -51,13 +51,13 @@ function initMusic () {
})
})
})
})
})
})
audio
.
addEventListener
(
'
waiting
'
,
()
=>
{
audio
.
addEventListener
(
'
waiting
'
,
()
=>
{
stopTimeUpdateTimer
()
stopTimeUpdateTimer
()
publishBackgroundAudioStateChange
(
'
waiting
'
,
{
publishBackgroundAudioStateChange
(
'
waiting
'
,
{
dataUrl
:
audio
.
src
dataUrl
:
audio
.
src
})
})
})
})
audio
.
addEventListener
(
'
error
'
,
err
=>
{
audio
.
addEventListener
(
'
error
'
,
err
=>
{
stopTimeUpdateTimer
()
stopTimeUpdateTimer
()
publish
(
'
onMusicError
'
,
{
publish
(
'
onMusicError
'
,
{
dataUrl
:
audio
.
src
,
dataUrl
:
audio
.
src
,
...
@@ -71,20 +71,20 @@ function initMusic () {
...
@@ -71,20 +71,20 @@ function initMusic () {
})
})
audio
.
addEventListener
(
'
prev
'
,
()
=>
publish
(
'
onBackgroundAudioPrev
'
))
audio
.
addEventListener
(
'
prev
'
,
()
=>
publish
(
'
onBackgroundAudioPrev
'
))
audio
.
addEventListener
(
'
next
'
,
()
=>
publish
(
'
onBackgroundAudioNext
'
))
audio
.
addEventListener
(
'
next
'
,
()
=>
publish
(
'
onBackgroundAudioNext
'
))
}
}
function
startTimeUpdateTimer
()
{
stopTimeUpdateTimer
()
timeUpdateTimer
=
setInterval
(()
=>
{
publishBackgroundAudioStateChange
(
'
timeUpdate
'
,
{})
},
TIME_UPDATE
)
}
function
stopTimeUpdateTimer
()
{
function
startTimeUpdateTimer
()
{
if
(
timeUpdateTimer
!==
null
)
{
stopTimeUpdateTimer
()
clearInterval
(
timeUpdateTimer
)
timeUpdateTimer
=
setInterval
(()
=>
{
}
publishBackgroundAudioStateChange
(
'
timeUpdate
'
,
{})
}
},
TIME_UPDATE
)
}
function
stopTimeUpdateTimer
()
{
if
(
timeUpdateTimer
!==
null
)
{
clearInterval
(
timeUpdateTimer
)
}
}
function
setMusicState
(
args
)
{
function
setMusicState
(
args
)
{
initMusic
()
initMusic
()
...
@@ -113,7 +113,7 @@ export function getMusicPlayerState () {
...
@@ -113,7 +113,7 @@ export function getMusicPlayerState () {
dataUrl
:
audio
.
src
,
dataUrl
:
audio
.
src
,
duration
:
audio
.
getDuration
()
||
0
,
duration
:
audio
.
getDuration
()
||
0
,
currentPosition
:
audio
.
getPosition
(),
currentPosition
:
audio
.
getPosition
(),
status
:
audio
.
isPaused
?
0
:
1
,
status
:
audio
.
isPaused
()
?
0
:
1
,
downloadPercent
:
Math
.
round
(
100
*
audio
.
getBuffered
()
/
audio
.
getDuration
()),
downloadPercent
:
Math
.
round
(
100
*
audio
.
getBuffered
()
/
audio
.
getDuration
()),
errMsg
:
`getMusicPlayerState:ok`
errMsg
:
`getMusicPlayerState:ok`
}
}
...
@@ -189,7 +189,7 @@ export function getBackgroundAudioState () {
...
@@ -189,7 +189,7 @@ export function getBackgroundAudioState () {
let
newData
=
{
let
newData
=
{
duration
:
audio
.
getDuration
()
||
0
,
duration
:
audio
.
getDuration
()
||
0
,
currentTime
:
audio
.
isStopped
?
0
:
audio
.
getPosition
(),
currentTime
:
audio
.
isStopped
?
0
:
audio
.
getPosition
(),
paused
:
audio
.
isPaused
,
paused
:
audio
.
isPaused
()
,
src
:
audio
.
src
,
src
:
audio
.
src
,
buffered
:
audio
.
getBuffered
(),
buffered
:
audio
.
getBuffered
(),
title
:
audio
.
title
,
title
:
audio
.
title
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录