How do I prevent Display from turning off when playing audio? POWERCFG


  1. Posts : 4
    Windows 10
       #1

    How do I prevent Display from turning off when playing audio? POWERCFG


    I recently installed the iHeart Radio app on my Windows 10 PC. After 10 minutes my PC Display turned off. Seems the app doesn't keep the PC Display from turning off. In my power settings, I have my display set to turn off after 10 minutes and computer to sleep to never. How can I use POWERCFG to prevent my display from turning off when the iHeart app is playing? Actually, it would be nice that it doesn't turn off when ANY audio is playing. Thanks for any help...
      My Computer


  2. Posts : 2,075
    Windows 10 Pro
       #2

    In power settings, just set monitor to never turn off.
      My Computer


  3. Posts : 5,452
    windows 10 Pro ver 21H2 build 19044.1348
       #3

    Kusaywa said:
    In my power settings, I have my display set to turn off after 10 minutes and computer to sleep to never. How can I use POWERCFG to prevent my display from turning off when the iHeart app is playing?
    Since you have set to turn off display after 10 minutes, it will do so no matter what program you are running at the time.
    You cannot make "exceptions" on specific programs. It can't be done.
      My Computer


  4. Posts : 4
    Windows 10
    Thread Starter
       #4

    Not so... As you can see by the below, when playing music in Windows Media Player the following occurs preventing the PC display from turning off. The question would be is how/if you can apply this to any program you want or when any audio is playing.

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.
    C:\windows\system32>powercfg -requests
    DISPLAY:
    [PROCESS] \Device\HarddiskVolume2\Program Files\Windows Media Player\wmplayer.ex
    e
    SYSTEM:
    [DRIVER] Conexant HD Audio (HDAUDIO\FUNC_01&VEN_14F1&DEV_50A1&SUBSYS_10280585&RE
    V_1001\4&372b2508&0&0201)
    An audio stream is currently in use.
    [DRIVER] \FileSystem\srvnet
    An active remote client has recently sent requests to this machine.
    [PROCESS] \Device\HarddiskVolume2\Program Files\Windows Media Player\wmplayer.ex
    e
    AWAYMODE:
    None.

    C:\windows\system32>
      My Computer


  5. Posts : 2,915
    Windows 10 Pro for the Bro
       #5

    Kusaywa

    Yes, you're right. I have set my display to turn off after 3 minutes of inactivity, yet I watch YouTube videos that last about 10 minutes without letting the Display turn off. I never move the mouse. Hence you are correct.

    I want you to look in the settings of iHeart Radio app on your computer and see if there's some option that you can fix that with. That option 'may' exist, yet I'm not sure. If you cannot find that option, then you should contact that app's developers/submit bug or such to tell them that when you play music on there, your computer becomes 'inactive' and causes your screen settings to turn off the monitor. Say you always want the monitor to stay on when you have that app running/avoid the monitor from going into "screen saver" mode.

      My Computer


  6. Posts : 4
    Windows 10
    Thread Starter
       #6

    The only thing I found was iHeart has a built-in sleep timer but setting it to say 1 hour doesn't change the situation. My PC is hooked up to my TV which I think is compounding the problem. I haven't tested it but I believe if I had a monitor and separate speakers plugged into the PC, you could still hear the music playing even if the display turns off. I think because it's a TV, once the display goes off, so does the audio. I will have to run the powercfg -requests while iHeart is running. I'm willing to bet I get the same result as the example in my previous post except for the "DISPLAY:" portion. I will post my results.
      My Computer


  7. Posts : 3
    Windows 10
       #7

    Here's a powershell script to workaround this problem (works in Win10 & Win11). I run this as a high privilege scheduled task since powercfg needs admin privileges.
    Code:
    powershell.exe -WindowStyle Hidden -executionpolicy remotesigned -File C:\MyPath\audioawake.ps1
    When there is an audio stream in use it creates a display power request preventing the screen/TV from turning off. If you use hdmi eARC or the optical digital audio out of a TV or any setup where audio depends on the display then you won't lose sound when only audio is playing. The line below containing "NVIDIA High Definition Audio" needs to be tweaked to whatever your audio driver is (e.g. "Conexant HD Audio" in post #4 above). Careful the square brackets are wildcards in powershell and must be preceded by a backtick or the script won't work.

    Windows must have a way to do this natively but I don't know it...
    Code:
    # ---------------------------------------------------
    # Script: C:\Users\stefstr\Documents\GitHub\PowerShell\Examples\SuspendPowerPlan.ps1
    # Version: 0.1
    # Author: Stefan Stranger
    # Date: 07/05/2014 15:01:57
    # Description: Helper Function to Suspend Power Plan when running PowerShell scripts
    # Comments:
    # Disclamer: This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
    # ---------------------------------------------------
    
    
    <#
    .Synopsis
       Function to suspend your current Power Plan settings when running a PowerShell script.
    .DESCRIPTION
       Function to suspend your current Power Plan settings when running a PowerShell script.
       Scenario: When downloading files using Robocopy from PowerShell you don't want your
       laptop to go into sleep mode.
    .EXAMPLE
       Suspend-PowerPlan -script c:\scripts\mylongrunningscript.ps1
       Run mylongrunningscript with sleep idle timeout prevented
    .EXAMPLE
       Suspend-Powerplan -script c:\scripts\mylongrunningscript.ps1 -option Display -Verbose
       Run mylongrunningscript with Display idle timeout prevented and verbose messages
    .LINK
      http://www.microsofttranslator.com/bv.aspx?from=ru&to=en&a=http%3A%2F%2Fsocial.technet.microsoft.com%2FForums%2Fen-US%2F1f4754cb-37bf-4e1d-a59f-ec0f1aaf9d1c%2Fsetthreadexecutionstate-powershell%3FThread%3A1f4754cb-37bf-4e1d-a59f-ec0f1aaf9d1c%3DMicrosoft.Forums.Data.Models.Discussion%26ThreadViewModel%3A1f4754cb-37bf-4e1d-a59f-ec0f1aaf9d1c%3DMicrosoft.Forums.CachedViewModels.ThreadPageViewModel%26forum%3Dscrlangru
    #>
    function Suspend-Powerplan
    {
        [CmdletBinding()]
        [Alias()]
        [OutputType([int])]
        Param
        (
            # Param1 help description
            [Parameter(Mandatory=$true,
                       Position=0)]
            $script,
            [ValidateSet("Away","Display","System")]
            [string]$option
             
        )
    
        $code=@' 
    [DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
      public static extern void SetThreadExecutionState(uint esFlags);
    '@
    
        $ste = Add-Type -memberDefinition $code -name System -namespace Win32 -passThru 
        $ES_CONTINUOUS = [uint32]"0x80000000" #Requests that the other EXECUTION_STATE flags set remain in effect until SetThreadExecutionState is called again with the ES_CONTINUOUS flag set and one of the other EXECUTION_STATE flags cleared.
        $ES_AWAYMODE_REQUIRED = [uint32]"0x00000040" #Requests Away Mode to be enabled.
        $ES_DISPLAY_REQUIRED = [uint32]"0x00000002" #Requests display availability (display idle timeout is prevented).
        $ES_SYSTEM_REQUIRED = [uint32]"0x00000001" #Requests system availability (sleep idle timeout is prevented).
    
        Switch ($option)
        {
          "Away" {$setting = $ES_AWAYMODE_REQUIRED}
          "Display" {$setting = $ES_DISPLAY_REQUIRED}
          "System" {$setting = $ES_SYSTEM_REQUIRED}
          Default {$setting = $ES_SYSTEM_REQUIRED}
    
        }
    
        Write-Verbose "Power Plan suspended with option: $option"
    
        $ste::SetThreadExecutionState($ES_CONTINUOUS -bor $setting)
    
        #do something
        Write-Verbose "Executing $script"
    
        &$script
    
        Write-Verbose "Power Plan suspension ended"
        $ste::SetThreadExecutionState($ES_CONTINUOUS)
    }
    
    function isAudioPlaying
    {
       $allRequests= powercfg -requests
       #Write-Host allRequests = $allRequests
    
       #Find if list contains Firefox non-display power request
       For($i=0; $i -lt $allRequests.Length; $i++)
       {
          $line = $allRequests[$i]
          #Write-Host i = $i line = $line
          if($line.ToLower() -like '`[DRIVER`] NVIDIA High Definition Audio *')
          {
             $i++
             $line = $allRequests[$i]
             #Write-Host i = $i line = $line
             if($line.ToLower() -like "An audio stream is currently in use.*")
             {
                #Write-Host "Audio driver has a system power request!!"
                return $true
             }
          }        
       }
    
       return $false
    }
    
    $gracePeriodSeconds = 0
    #Write-Host gracePeriodSeconds = $gracePeriodSeconds
    $checkEverySeconds = 60
    
    while ($true)
    {
       $FFaudio = isAudioPlaying
       #Write-Host FFaudio = $FFaudio
       if ($FFaudio)
       {
          #Write-Host FFaudio is happening
          Suspend-Powerplan { do { Start-Sleep -Seconds $checkEverySeconds; $FFaudio = isAudioPlaying ; } while( $FFaudio) ; Start-Sleep -Seconds $gracePeriodSeconds } -option Display
       }
       Start-Sleep -Seconds $checkEverySeconds;
    }
    
    # __main__
    if ($MyInvocation.InvocationName -ne '.') {
    #    Suspend-Powerplan {Read-Host 'press enter to terminate'}
    #    Suspend-Powerplan {Start-Sleep -Seconds 1} -option Away -Verbose
    #    Suspend-Powerplan {Read-Host 'press enter to terminate'}
    }
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:19.
Find Us




Windows 10 Forums