Skip to content

Problem "Property 'then' does not exist on type 'void'." with HTMLAudioElement #7374

@leehung-net

Description

@leehung-net

Hi all,
I use HTMLAudioElement to play audio. But when I 'npm start' or 'ng build ..', there is a problem. "Property 'then' does not exist on type 'void'."
Please help me.
Code below (https://googlechrome.github.io/samples/play-return-promise/):
playAudio(src: any) {
let audio: HTMLAudioElement = this.player.nativeElement;
audio.src = src;
// audio.load();
if (this.isPlay === false) {
var playPromise = audio.play();
if (playPromise !== undefined) {
playPromise.then(function () {
// Automatic playback started!
}).catch(function (error) {
// Automatic playback failed.
// Show a UI element to let the user manually start playback.
});
}
this.isPlay = true;
audio.onended = function () {
this.isPlay = false;
}.bind(this);
} else {
audio.pause();
this.isPlay = false;
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions