我对htmlmediaelement的pape()函数有问题。我试图暂停我的音频,但什么也没有发生。play()每次都很好地工作:
export class personalCard {
j = 0;
playAudio(){
let aud = new Audio ('../../assets/aud/Magdalena_Su_ß.opus');
this.j= this.j + 1;
if(this.j % 2 == 0){
aud.pause();
console.log('Pause');
}
else if(this.j % 2 != 0){
aud.play();
console.log('Play');
}
}
}
html:
<button id="volume" (click)="playAudio()"></button>
我也可以在控制台上看到日志"暂停",但是aud.pause();永远无法工作。我不使用任何框架进行音频。有人可以帮助我解决问题吗?
非常感谢sam
,用于访问pape(),mute()或load()变量,必须在类中声明aud,以进行全局访问。
解决方案:
export class personalCard {
j = 0;
aud = new Audio ('../../assets/aud/Magdalena_Su_ß.opus');
playAudio(){
this.j= this.j + 1;
if(this.j % 2 == 0){
aud.pause();
console.log('Pause');
}
else if(this.j % 2 != 0){
aud.play();
console.log('Play');
}
}
}