mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fix audio playing on iOS (#16298)
This commit is contained in:
parent
e793675c47
commit
8a50bb058d
@ -30,8 +30,6 @@ export class TTSTryDialog extends LitElement {
|
||||
string
|
||||
>;
|
||||
|
||||
private _audio?: HTMLAudioElement;
|
||||
|
||||
public showDialog(params: TTSTryDialogParams) {
|
||||
this._params = params;
|
||||
this._valid = Boolean(this._defaultMessage);
|
||||
@ -39,14 +37,6 @@ export class TTSTryDialog extends LitElement {
|
||||
|
||||
public closeDialog() {
|
||||
this._params = undefined;
|
||||
if (this._audio) {
|
||||
this._audio.pause();
|
||||
this._audio.removeEventListener("ended", this._audioEnded);
|
||||
this._audio.removeEventListener("canplaythrough", this._audioCanPlay);
|
||||
this._audio.removeEventListener("playing", this._audioPlaying);
|
||||
this._audio.removeEventListener("error", this._audioError);
|
||||
this._audio = undefined;
|
||||
}
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
}
|
||||
|
||||
@ -140,13 +130,9 @@ export class TTSTryDialog extends LitElement {
|
||||
|
||||
this._loadingExample = true;
|
||||
|
||||
if (!this._audio) {
|
||||
this._audio = new Audio();
|
||||
this._audio.addEventListener("ended", this._audioEnded);
|
||||
this._audio.addEventListener("canplaythrough", this._audioCanPlay);
|
||||
this._audio.addEventListener("playing", this._audioPlaying);
|
||||
this._audio.addEventListener("error", this._audioError);
|
||||
}
|
||||
const audio = new Audio();
|
||||
audio.play();
|
||||
|
||||
let url;
|
||||
try {
|
||||
const result = await convertTextToSpeech(this.hass, {
|
||||
@ -164,27 +150,17 @@ export class TTSTryDialog extends LitElement {
|
||||
});
|
||||
return;
|
||||
}
|
||||
this._audio.src = url;
|
||||
audio.src = url;
|
||||
audio.addEventListener("canplaythrough", () => audio.play());
|
||||
audio.addEventListener("playing", () => {
|
||||
this._loadingExample = false;
|
||||
});
|
||||
audio.addEventListener("error", () => {
|
||||
showAlertDialog(this, { title: "Error playing audio." });
|
||||
this._loadingExample = false;
|
||||
});
|
||||
}
|
||||
|
||||
private _audioCanPlay = () => {
|
||||
this._audio?.play();
|
||||
};
|
||||
|
||||
private _audioPlaying = () => {
|
||||
this._loadingExample = false;
|
||||
};
|
||||
|
||||
private _audioError = () => {
|
||||
showAlertDialog(this, { title: "Error playing audio." });
|
||||
this._loadingExample = false;
|
||||
this._audio?.removeAttribute("src");
|
||||
};
|
||||
|
||||
private _audioEnded = () => {
|
||||
this._audio?.removeAttribute("src");
|
||||
};
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
ha-dialog {
|
||||
|
Loading…
x
Reference in New Issue
Block a user