Skip to content

Commit 135e829

Browse files
committed
fix(TV.js): fix error handling for async play function
1 parent 190849b commit 135e829

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/scripts/objects/TV.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ export default class TV {
7777
* Pause and play the video
7878
* @public
7979
*/
80-
toggleVideo() {
81-
// Change playing state
82-
this.isPlaying = !this.isPlaying;
83-
84-
// Toggle play and pause
85-
if (this.isPlaying) {
86-
this.video.play();
87-
this.audio.start(0, this.video.currentTime);
80+
async toggleVideo() {
81+
// Try to play the video if it's paused
82+
if (!this.isPlaying) {
83+
try {
84+
await this.video.play().then(async () => {
85+
this.audio.start(0, this.video.currentTime);
86+
this.isPlaying = true;
87+
});
88+
} catch (error) {
89+
this.isPlaying = false;
90+
}
8891
} else {
92+
// Pause the video if it's playing
8993
this.video.pause();
9094
this.audio.stop();
95+
this.isPlaying = false;
9196
}
9297
}
9398

0 commit comments

Comments
 (0)