Skip to content

Commit

Permalink
Merge pull request #740 from robtpaton/better-autoplay-behaviour
Browse files Browse the repository at this point in the history
Prevent errors other than autoplay errors from muting video
  • Loading branch information
AlexxIT authored Sep 8, 2024
2 parents 11f83d0 + d0cd114 commit 2aef88b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions custom_components/webrtc/www/video-rtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ export class VideoRTC extends HTMLElement {
* https://developer.chrome.com/blog/autoplay/
*/
play() {
this.video.play().catch(() => {
if (!this.video.muted) {
this.video.play().catch((firstError) => {
console.warn(firstError);
const isAutoplayError = firstError.name == "NotAllowedError";

if (!this.video.muted && isAutoplayError) {
this.video.muted = true;
this.video.play().catch(er => {
console.warn(er);
this.video.play().catch(secondError => {
console.warn(secondError);
});
}
});
Expand Down

0 comments on commit 2aef88b

Please sign in to comment.