Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
ww_listen-choose
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
ww_listen-choose
Commits
c2b2cd35
Commit
c2b2cd35
authored
Oct 31, 2025
by
Jeff nan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat
parent
32c48e14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
3 deletions
+47
-3
play.component.ts
src/app/play/play.component.ts
+47
-3
No files found.
src/app/play/play.component.ts
View file @
c2b2cd35
...
...
@@ -40,6 +40,8 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges {
wrongAudio
=
new
Audio
();
_lc_text
=
''
;
_data
=
[];
hasUnlockedAudio
=
false
;
sfxActive
=
new
Set
<
HTMLAudioElement
>
();
constructor
(
private
appRef
:
ApplicationRef
,
public
changeDetectorRef
:
ChangeDetectorRef
)
{
...
...
@@ -123,13 +125,55 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges {
this
.
refresh
();
}
handleTap
(
ev
,
item
)
{
async
ensureAudioUnlocked
():
Promise
<
void
>
{
if
(
this
.
hasUnlockedAudio
)
{
return
;
}
try
{
this
.
rightAudio
.
muted
=
true
;
this
.
rightAudio
.
currentTime
=
0
;
await
this
.
rightAudio
.
play
();
this
.
rightAudio
.
pause
();
this
.
rightAudio
.
muted
=
false
;
this
.
rightAudio
.
currentTime
=
0
;
this
.
hasUnlockedAudio
=
true
;
}
catch
(
e
)
{
// 忽略,后续播放时再尝试
}
}
async
playSfx
(
base
:
HTMLAudioElement
):
Promise
<
void
>
{
const
clip
=
base
.
cloneNode
(
true
)
as
HTMLAudioElement
;
clip
.
preload
=
'
auto
'
;
clip
.
currentTime
=
0
;
this
.
sfxActive
.
add
(
clip
);
const
cleanup
=
()
=>
{
this
.
sfxActive
.
delete
(
clip
);
clip
.
src
=
''
;
};
clip
.
addEventListener
(
'
ended
'
,
cleanup
,
{
once
:
true
});
clip
.
addEventListener
(
'
error
'
,
cleanup
,
{
once
:
true
});
try
{
await
clip
.
play
();
}
catch
(
err
)
{
if
((
err
as
any
)?.
name
===
'
NotAllowedError
'
&&
!
this
.
hasUnlockedAudio
)
{
await
this
.
ensureAudioUnlocked
();
try
{
await
clip
.
play
();
return
;
}
catch
(
_
)
{}
}
cleanup
();
}
}
async
handleTap
(
ev
,
item
)
{
if
(
item
.
is_right
)
{
item
.
state
=
'
right
'
;
new
Audio
(
this
.
rightAudio
.
src
+
'
?v=
'
+
new
Date
().
getTime
()).
play
(
);
await
this
.
playSfx
(
this
.
rightAudio
);
}
else
{
item
.
state
=
'
wrong
'
;
new
Audio
(
this
.
wrongAudio
.
src
+
'
?v=
'
+
new
Date
().
getTime
()).
play
(
);
await
this
.
playSfx
(
this
.
wrongAudio
);
setTimeout
(()
=>
{
item
.
state
=
''
;
},
1500
);
...
...
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