mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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
|
string
|
||||||
>;
|
>;
|
||||||
|
|
||||||
private _audio?: HTMLAudioElement;
|
|
||||||
|
|
||||||
public showDialog(params: TTSTryDialogParams) {
|
public showDialog(params: TTSTryDialogParams) {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this._valid = Boolean(this._defaultMessage);
|
this._valid = Boolean(this._defaultMessage);
|
||||||
@ -39,14 +37,6 @@ export class TTSTryDialog extends LitElement {
|
|||||||
|
|
||||||
public closeDialog() {
|
public closeDialog() {
|
||||||
this._params = undefined;
|
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 });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,13 +130,9 @@ export class TTSTryDialog extends LitElement {
|
|||||||
|
|
||||||
this._loadingExample = true;
|
this._loadingExample = true;
|
||||||
|
|
||||||
if (!this._audio) {
|
const audio = new Audio();
|
||||||
this._audio = new Audio();
|
audio.play();
|
||||||
this._audio.addEventListener("ended", this._audioEnded);
|
|
||||||
this._audio.addEventListener("canplaythrough", this._audioCanPlay);
|
|
||||||
this._audio.addEventListener("playing", this._audioPlaying);
|
|
||||||
this._audio.addEventListener("error", this._audioError);
|
|
||||||
}
|
|
||||||
let url;
|
let url;
|
||||||
try {
|
try {
|
||||||
const result = await convertTextToSpeech(this.hass, {
|
const result = await convertTextToSpeech(this.hass, {
|
||||||
@ -164,27 +150,17 @@ export class TTSTryDialog extends LitElement {
|
|||||||
});
|
});
|
||||||
return;
|
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 {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
ha-dialog {
|
ha-dialog {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user