Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
hello_taobao
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wildfirecode13
hello_taobao
Commits
abc1c9c8
Commit
abc1c9c8
authored
Sep 11, 2020
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
1e07b1a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
1 deletion
+95
-1
pagehuo_dong_ye.js
dist/pages/pagehuo_dong_ye/pagehuo_dong_ye.js
+12
-1
playBgMusic.js
dist/utils/playBgMusic.js
+83
-0
No files found.
dist/pages/pagehuo_dong_ye/pagehuo_dong_ye.js
View file @
abc1c9c8
...
...
@@ -3,6 +3,7 @@
import
resList
from
'../../resconfig/resList'
;
import
API
from
'../../api'
;
import
{
SHARE_CONFIG
}
from
'/tbcc-sdk/lib/constants'
;
import
playBgMusic
from
'/utils/playBgMusic'
;
const
app
=
getApp
();
const
{
tbcc
}
=
app
;
const
{
commonToast
,
getAuthUserInfo
,
navigateToOutside
}
=
tbcc
.
tb
;
...
...
@@ -66,6 +67,8 @@ Page({
this
.
getUserCredits
();
this
.
getOrderList
();
// this.screenAdapt();
this
.
addMusic
();
},
// screenAdapt(){
...
...
@@ -469,5 +472,13 @@ Page({
// console.log(SHARE_CONFIG)
return
SHARE_CONFIG
;
},
async
addMusic
(){
const
resultSrc
=
await
app
.
cloud
.
file
.
getTempFileURL
({
fileId
:
'cloud://C7A066C702682E94326284DF8A2975CC//FILA_building_loop.mp3'
});
let
musicUrl
=
null
;
if
(
resultSrc
[
0
])
musicUrl
=
resultSrc
[
0
].
url
;
playBgMusic
(
true
,
musicUrl
)
console
.
log
(
'fuck music'
)
}
});
\ No newline at end of file
dist/utils/playBgMusic.js
0 → 100644
View file @
abc1c9c8
class
AudioModel
{
// isOn = false;
constructor
(
opts
=
{})
{
const
{
src
}
=
opts
;
if
(
!
src
)
{
console
.
error
(
'请输入音频链接'
);
return
false
;
}
try
{
const
innerAudioContext
=
my
.
createInnerAudioContext
();
Object
.
keys
(
opts
).
forEach
(
item
=>
{
innerAudioContext
[
item
]
=
opts
[
item
];
});
// this.isOn = opts.autoplay;
// innerAudioContext.isOn = opts.autoplay;
return
innerAudioContext
;
}
catch
(
e
)
{
console
.
error
(
'当前版本不支持音频'
);
}
}
};
const
createAudio
=
opts
=>
{
const
audioInstance
=
new
AudioModel
(
opts
)
return
audioInstance
;
};
let
bgs
=
{
}
const
playBgMusic
=
(
isOn
,
src
)
=>
{
//待测试
for
(
let
k
in
bgs
)
{
if
(
bgs
[
k
].
isOn
)
{
bgs
[
k
].
stop
();
}
// bgs[k].isOn = false; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
const
key
=
src
;
if
(
isOn
)
{
if
(
!
bgs
[
key
])
{
bgs
[
key
]
=
createAudio
({
src
:
src
,
autoplay
:
true
,
loop
:
false
/// TODO 暂时无效?2020.08.12 目前有效,但stop后还会跑数据,导致到音频结束到时间又自动播放
});
bgs
[
key
].
onPlay
(()
=>
{
bgs
[
key
].
isOn
=
true
;
});
bgs
[
key
].
onStop
(()
=>
{
bgs
[
key
].
isOn
=
false
;
});
/// TODO监听结束,因为loop无效 2020.08.12 loop有效,这个操作是为了解决stop之后还会跑音频数据的问题
bgs
[
key
].
onEnded
(()
=>
{
if
(
bgs
[
key
].
isOn
)
{
// 判断自己记录的开关
bgs
[
key
].
play
();
// bgs[key].isOn = true;
}
});
bgs
[
key
].
play
();
// 安卓有时候autoplay好像莫得用
// console.log(src)
// bgs[key].isOn = true; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
else
{
bgs
[
key
].
play
();
// bgs[key].isOn = true; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
}
else
{
if
(
bgs
[
key
])
{
// bgs[key].pause(); /// pause 垃圾,不能用
bgs
[
key
].
stop
();
// bgs[key].isOn = false; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
}
}
export
default
playBgMusic
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment