Search code examples
javascriptangulargoogle-chromevideo-streamingclappr

How can I reproduce the error "The play() request was interrupted because video-only background media was paused to save power"?


Introduction

As part of my project I have a player that receives a video stream. I wanted it to autoplay and autostop when the stream starts and end so I introduced a check to see if the stream is active and start and/or stop the player in each case.

This is a corporative site that sometimes gets as high as 3000 users seeing the stream at once and we tested it with 15000 simultaneous users.

Most users use this feature with no problem. Yet for a fraction of the users the stream incorrectly stops as finished at some point of the transmission.

This is an Angular FE, using Clappr player. AFAI can tell this happens in Windows and in Chrome.

The problem

Studing one of the cases, I found this in the console:

Uncaught (in promise) DOMException: The play() request was interrupted because 
video-only background media was paused to save power. 
https://developer.chrome.com/blog/play-request-was-interrupted/

This is a Windows machine with Chrome. The real url present in the error is a shortened one. I substituted by the full url because SO didn't allow the shortened url to be posted. So I went to Chrome configurations and found the Performance options: Memory Saver and Energy Saver. I thought I founded the solution. It was obvious: one of these configurations would probably stop the stream after the users changed tabs and left the stream in the background.

But that's when my bigger problems started. First I tried to find the exact option that would do this. After much trial and error I found that Memory Saver wouldn't do this as after it runs, it reloads the page when returning to it. In my case the page stays loaded with the error message.

Battery saving didn't stop the video. It removed smooth scroll, probably other things but didn't stopped the video AFAI could experience. Even after long hours.

I turned all energy saving options I could find in Windows and couldn't make it stop the video.

Adding to all this, the URL presented in the error message (https://developer.chrome.com/blog/play-request-was-interrupted/) has the solution for 2 AFAIU unrelated errors:

Uncaught (in promise) DOMException: The play() request was interrupted 
by a call to pause().

and

Uncaught (in promise) DOMException: The play() request was interrupted 
by a new load request.

Which are caused by a play attempt after a pause due to a non-reachable stream. In my case the pause was done to save power (although I couldn't reproduce it with all power saving options on). I couldn't find any reference for the specific error I'm getting anywhere not even in the source code for Chromium or Clappr.

The question

So for now I need a way to realiably reproduce the error that shows that error message. Then the question is: What really causes that specific error message ?

My application isn't saving power by itself. But I couldn't find any power saving options that generated that error message.

After I find a way to realiably reproduce the problem I will need to find a way to avoid video from stopping. So a plus in the answer to this question would be a way to do this.

Some useful info

I could only find these 2 options (memory and energy saver modes) in a specific version of Chrome and in Windows only: 111.0.5563.148 (Official Version) 64 bits

There isn't any Chromium version that has this number. Similarly numbered Chromium versions in Linux don't have these 2 options. Also most Chrome/Chromium versions only have memory saving options and newer ones none of them. I'm mentioning Chromium because Google doesn't allow the download of old Chrome versions due to security reasons and we have to use Chromium when this is needed. Fortunately I have a windows copy that has the exact same version of the browser where I found the problem. Although I mainly have discarded these options as the cause, I'm saying this so that someone that has a different view knows I can test this.

Finally the stream I used for the tests doesn't have audio in order to replicate the best conditions possible for generating the error. Remeber that the error message said "request was interrupted because video-only background media was paused to save power".


Solution

  • OK this one will not seem real. After one week trying all sorts of configurations, chromium versions and settings I have found how the error can be reproduced:

    Make sure the player IS NOT MUTTED

    After 1 minute that you change the tab to the background the error should occur. It doesn't matter if the energy and battery saving are on or off. Just unmute the player.