Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
ww_audio_image
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_audio_image
Commits
41d806ef
Commit
41d806ef
authored
May 15, 2025
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 音频不播放的问题
parent
08dec26f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
21 deletions
+27
-21
play.component.ts
src/app/play/play.component.ts
+27
-21
No files found.
src/app/play/play.component.ts
View file @
41d806ef
...
@@ -12,6 +12,7 @@ import {debounceTime} from 'rxjs/operators';
...
@@ -12,6 +12,7 @@ import {debounceTime} from 'rxjs/operators';
import
TWEEN
from
'
@tweenjs/tween.js
'
;
import
TWEEN
from
'
@tweenjs/tween.js
'
;
import
{
animate
,
state
,
style
,
transition
,
trigger
}
from
'
@angular/animations
'
;
import
{
animate
,
state
,
style
,
transition
,
trigger
}
from
'
@angular/animations
'
;
import
{
settings
}
from
'
cluster
'
;
...
@@ -41,8 +42,7 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
...
@@ -41,8 +42,7 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
saveKey
=
'
ww_audio_image
'
;
saveKey
=
'
ww_audio_image
'
;
isPlaying
=
false
;
audio
=
null
;
audio
=
new
Audio
();
fntSizeRect
:
any
;
fntSizeRect
:
any
;
@
ViewChild
(
'
pic
'
)
@
ViewChild
(
'
pic
'
)
domPic
:
ElementRef
;
domPic
:
ElementRef
;
...
@@ -55,6 +55,8 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
...
@@ -55,6 +55,8 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
private
changeDetectorRef
:
ChangeDetectorRef
)
{
private
changeDetectorRef
:
ChangeDetectorRef
)
{
}
}
canPlayAudio
=
false
;
ngOnInit
()
{
ngOnInit
()
{
this
.
data
=
{
this
.
data
=
{
contentObj
:
{
contentObj
:
{
...
@@ -65,19 +67,20 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
...
@@ -65,19 +67,20 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
}
}
};
};
window
[
'
courseware
'
].
onEvent
(
'
course-in-screen
'
,
()
=>
{
setTimeout
(()
=>
{
this
.
canPlayAudio
=
true
;
},
1500
);
});
// 获取数据
// 获取数据
const
getData
=
(
window
as
any
).
courseware
.
getData
;
const
getData
=
(
window
as
any
).
courseware
.
getData
;
getData
((
data
)
=>
{
getData
((
data
)
=>
{
if
(
data
&&
typeof
data
===
'
object
'
)
{
if
(
data
&&
typeof
data
===
'
object
'
)
{
this
.
data
=
data
;
this
.
data
=
data
;
}
}
this
.
audio
.
pause
();
this
.
audio
.
currentTime
=
0
;
this
.
isPlaying
=
false
;
if
(
this
.
data
.
contentObj
&&
this
.
data
.
contentObj
.
audio_id
)
{
if
(
this
.
data
.
contentObj
&&
this
.
data
.
contentObj
.
audio_id
)
{
this
.
audio
.
src
=
this
.
data
.
contentObj
.
audio_id
;
console
.
log
(
'
Setting audio source:
'
,
this
.
data
.
contentObj
.
audio_id
);
this
.
audio
.
load
();
}
}
this
.
showQuestion
=
false
;
this
.
showQuestion
=
false
;
this
.
changeDetectorRef
.
markForCheck
();
this
.
changeDetectorRef
.
markForCheck
();
...
@@ -86,17 +89,10 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
...
@@ -86,17 +89,10 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
if
(
window
[
"
air
"
])
{
if
(
window
[
"
air
"
])
{
window
[
"
air
"
].
hideAirClassLoading
(
this
.
saveKey
,
this
.
data
);
window
[
"
air
"
].
hideAirClassLoading
(
this
.
saveKey
,
this
.
data
);
}
}
},
this
.
saveKey
);
},
this
.
saveKey
);
this
.
audio
.
onended
=
()
=>
{
this
.
isPlaying
=
false
;
};
}
}
ngOnDestroy
()
{
ngOnDestroy
()
{
this
.
audio
.
pause
();
this
.
audio
=
null
;
}
}
ngOnChanges
(
data
)
{
ngOnChanges
(
data
)
{
...
@@ -125,16 +121,26 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
...
@@ -125,16 +121,26 @@ export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewIni
}
}
playAudio
(
ev
)
{
async
playAudio
(
ev
)
{
if
(
!
this
.
canPlayAudio
)
{
return
;
}
ev
.
preventDefault
();
ev
.
preventDefault
();
console
.
log
(
'
Trying to play audio...
'
,
window
[
'
air
'
].
isCourseInScreen
);
if
(
this
.
data
.
contentObj
&&
this
.
data
.
contentObj
.
audio_id
)
{
if
(
this
.
data
.
contentObj
&&
this
.
data
.
contentObj
.
audio_id
)
{
if
(
!
this
.
audio
.
paused
)
{
if
(
this
.
audio
&&
!
this
.
audio
.
paused
)
{
console
.
log
(
'
Pausing audio...
'
);
this
.
audio
.
pause
();
this
.
audio
.
pause
();
this
.
isPlaying
=
false
;
this
.
changeDetectorRef
.
markForCheck
();
}
else
{
return
;
this
.
audio
.
play
();
this
.
isPlaying
=
true
;
}
}
this
.
audio
=
new
Audio
();
this
.
audio
.
src
=
this
.
data
.
contentObj
.
audio_id
;
this
.
audio
.
play
();
this
.
changeDetectorRef
.
markForCheck
();
}
else
{
console
.
warn
(
'
No audio source available
'
);
}
}
}
}
...
...
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