jellyfin / jellyfin-media-player

Jellyfin Desktop Client
GNU General Public License v2.0
3.21k stars 319 forks source link

Playing Music doesn't prevent windows 10 from going to sleep #85

Open Swizzler121 opened 3 years ago

Swizzler121 commented 3 years ago

Describe the bug When playing music from the jellyfin media player, the system will still go to sleep. Most modern windows programs that play media send a keep-awake signal to the system to prevent this from happening. I don't know if this happens with video, as I've only used jellyfin media player for music so far (I use the tv app for movies and shows)

To Reproduce Steps to reproduce the behavior:

  1. Play music
  2. Wait until your system would normally go to sleep due to inactivity
  3. Observe if it goes to sleep and the music stops playing

Expected behavior The media player would tell the system to not go to sleep as media is playing

Desktop (please complete the following information):

Additional context I was hoping this problem was fixed in 1.6.0 as I saw OS media controls were added, but unfortunately it's still happening.

iwalton3 commented 3 years ago

The application should suppress the lock screen for video. It is not configured to do so for music playback.

Swizzler121 commented 3 years ago

The application should suppress the lock screen for video. It is not configured to do so for music playback.

It'd be nice to have it as an option to suppress for music too, even if it's off by default.

Swizzler121 commented 3 years ago

Any update on this? I'm tired of having my Jellyfin Media Player crash because it went to sleep and killed the network connection in the middle of playing a song. what would it take for me to add this as a plugin or something?

TheFeelTrain commented 3 years ago

For now I would just use the web version for music. When it comes to video Jellyfin Media Player uses MPV, so it supports things like HEVC without transcoding. But for music there's not really any advantage. It's exactly the same.

Swizzler121 commented 3 years ago

I use Jellyfin Media Player because the cruddy laptop I'm normally listening on gets bogged down when I open too many media streams and will crash, doesn't do it with the app as it's much leaner than a browser.

I don't feel like i'm asking for the world here, just asking for the option for the app to treat audio the same way it treats video.

TheFeelTrain commented 3 years ago

I should make it clear I'm not a developer I was just giving a suggestion that might work in the meantime.

Also it uses QtWebEngine which under the hood is Chromium, so it literally is just running in a browser. Just from a quick look it's literally using the same amount of cpu/memory as Brave (which is also Chromium) does with one tab open.

spartanv7 commented 1 year ago

I'm a little late, but I second this.

For starters though, what you're describing here is more of a "Feature Request" than a "Bug". When playing Jellyfin with video, the system is prevented from hibernating, going to sleep and turning the screen off (all 3 of these are different things within Windows).

You can start a video stream in Jellyfin, then open a command prompt and use: powercfg -requests to see what requests are being made to prevent certain behaviors in Windows.

For video this is what I see: DISPLAY: [PROCESS] \Device\HarddiskVolume3\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe

SYSTEM: [DRIVER] NVIDIA High Definition Audio (HDAUDIO\FUNC_01&VEN_10DE&DEV_0082&SUBSYS_38426393&REV_1001\5&17af9987&0&0001) An audio stream is currently in use. [PROCESS] \Device\HarddiskVolume3\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe

AWAYMODE: None.

EXECUTION: None.

PERFBOOST: None.

ACTIVELOCKSCREEN: None.

However, for audio it's different: DISPLAY: None.

SYSTEM: [DRIVER] NVIDIA High Definition Audio (HDAUDIO\FUNC_01&VEN_10DE&DEV_0082&SUBSYS_38426393&REV_1001\5&17af9987&0&0001) An audio stream is currently in use.

AWAYMODE: None.

EXECUTION: None.

PERFBOOST: None.

ACTIVELOCKSCREEN: None.

NOTE: You can also open Jellyfin in the web browser and run this same check of the powercfg requests and you'll notice that for audio streams, there is no directive to prevent hibernation/sleep/screen timeout (at least not in Brave which is what I tested it with), but there is for video.

I am a developer, albeit not for Jellyfin nor for Windows Applications (.NET/C#), but based on my Googling around about the problem, the issue here is that during an audio stream the Media Player app isn't setting any execution or display request to prevent that behavior.

On one hand, this behavior makes sense on mobile devices in particular. You wouldn't want the screen left on, draining the battery while playing audio and while some people on desktop/HTPC's might want the screen to remain on during audio playback, not everybody is going to want that and most people are used to the existing behavior of the app.

What makes the most sense to me is to have opt-in toggle options in the "Settings > Playback" group of the Media Player application. This should be possible by having the application utilize SetThreadExecutionState (see: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate). However, I'm not sure how soon that could get done as I'm sure the devs of Jellyfin have more pressing bugs to worry about.

I would think the quickest way to get this resolved would be attempting to write a plugin that does this, which I will look into in my free time. In the meantime, I would perhaps open a "Feature Request" for this functionality and perhaps it's something they would want to implement. I know Spotify users have been begging for a feature like this since at least 2015...