question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Not preventing device sleep

See original GitHub issue

Checklist

  • Verified whether your issue exists in the latest version Mux Element(s) release: npm install @mux/[element_name] or yarn @mux/[element_name].
    • (NOTE: If the issue is not occurring in the latest version, we may not resolve it.)
  • Confirmed that this issue hasn’t already been filed.

Which Mux Elements/Packages has a bug?

  • mux-player

Which browser(s) are you using?

  • Chrome
  • Edge (“Edgeium”)
  • Safari
  • Chrome Android

Which operating system(s) are you using?

macOS, Windows, Android

How are you using Mux Elements?

<script> tag

Describe the bug

Whenever a video is playing, it should prevent the device from going to sleep. This should be the default behavior of most browsers with the default HTML video element, so I’m not sure what is changing in Mux Player that disables this. Based on my tests, Media Chrome does not have this problem, it is isolated to Mux Player. It doesn’t happen on every device, but on those that it does, it happens consistently.

Steps To Reproduce

  1. Set device sleep or lock delay to something short for easier testing.
  2. Start playing a Mux Player video and wait the amount of time for the sleep or lock to potentially activate.

Link to example: https://tmi.mux.com/sessions/opening-remarks (tested this behavior on Mux hosted videos to make sure it wasn’t just on our website, it occurs on the TMI videos as well as in the Mux dashboard)

The current behavior

Device falls asleep when video is playing

The expected behavior

Device stays awake as long as video is playing

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
MrSethTcommented, Aug 16, 2022

Here’s the workaround I am using in the meantime for this. (Sorry if this isn’t how sharing of this should be done. If there’s a better place for it, point me to it.)

wakeLock = null;

startWakeLock = function () {
    document.addEventListener('visibilitychange', () => {
        if (wakeLock !== null && document.visibilityState === 'visible') {
            requestWakeLock();
        }
    })
    requestWakeLock();
};

requestWakeLock = async function () {
    // Create a reference for the Wake Lock.
    if (navigator.wakeLock) {// create an async function to request a wake lock
        try {
            wakeLock = await navigator.wakeLock.request('screen');
            console.log('requestWakeLock');
        } catch (err) {
            console.log(err.name);
        }
    }
};

releaseWakeLock = function () {
    if (wakeLock)
        wakeLock.release()
            .then(() => {
                console.log('releaseWakeLock');
                wakeLock = null;
            })
};

//get the mux-player
popupVideo = document.getElementById("vidPopup");
//add event listeners 
popupVideo.addEventListener("play", function () {
    startWakeLock();
});
popupVideo.addEventListener("pause", function () {
    releaseWakeLock();
});
1reaction
luwescommented, Jul 28, 2022

I filed a Chrome bug https://bugs.chromium.org/p/chromium/issues/detail?id=1348320

Confirmed it’s not an issue on Safari and Firefox.

On Edge it is an issue as well probably because the underlying Chromium.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unsolvable Windows 11 sleep prevention bug
Unsolvable Windows 11 sleep prevention bug When trying to enter sleep mode in Windows 11, the procedure does not work.
Read more >
General - Known issues/bugs that prevent deep sleep
Does anyone know if poor signal strength prevents deep sleep or causes the phone to take longer into deep sleep? Could it be...
Read more >
How to Fix Windows 10 Sleep Mode Issues - MakeUseOf
Go to the manufacturer's website and check for any compatibility issues. If there aren't any, unplug the device and check to see if...
Read more >
How do I prevent a device from going into sleep mode?
I want my app to decide whether sleep mode should be enabled by checking how many bluetooth peripherals are connected. For bluetooth I...
Read more >
IINA 1.3.0 BUG: Error Cannot prevent display sleep! #3842
Restore settings and reinstall software did not fix it. After restarting the computer, the problem can be solved, but after a period of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found