Here's how to use the code provided by Simon Murier.
Run the code below:
Add-Type -TypeDefinition @' using System; using System.Runtime.InteropServices; namespace Foo { public class Bar { public static bool IsWindowsPlayingSound() { IMMDeviceEnumerator enumerator = (IMMDeviceEnumerator)(new MMDeviceEnumerator()); IMMDevice speakers = enumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia); IAudioMeterInformation meter = (IAudioMeterInformation)speakers.Activate(typeof(IAudioMeterInformation).GUID, 0, IntPtr.Zero); float value = meter.GetPeakValue(); // this is a bit tricky. 0 is the official "no sound" value // but for example, if you open a video and plays/stops with it (w/o killing the app/window/stream), // the value will not be zero, but something really small (around 1E-09) // so, depending on your context, it is up to you to decide // if you want to test for 0 or for a small value return value > 1E-08; } [ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] private class MMDeviceEnumerator { } private enum EDataFlow { eRender, eCapture, eAll, } private enum ERole { eConsole, eMultimedia, eCommunications, } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("A95664D2-9614-4F35-A746-DE8DB63617E6")] private interface IMMDeviceEnumerator { void NotNeeded(); IMMDevice GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role); // the rest is not defined/needed } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("D666063F-1587-4E43-81F1-B948E807363F")] private interface IMMDevice { [return: MarshalAs(UnmanagedType.IUnknown)] object Activate([MarshalAs(UnmanagedType.LPStruct)] Guid iid, int dwClsCtx, IntPtr pActivationParams); // the rest is not defined/needed } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064")] private interface IAudioMeterInformation { float GetPeakValue(); // the rest is not defined/needed } } } '@
I replaced all var types, as this apparently fixes a problem with code that doesn't compile on PowerShell version 2.
After loading, you can check the status as follows:
[Foo.Bar]::IsWindowsPlayingSound() True or False
I tested this work with Windows 10 1703 on PowerShell 5.1
But there are reservations:
this is a bit tricky. 0 is the official "no sound" value but for example, if you open a video and plays/stops with it (w/o killing the app/window/stream), the value will not be zero, but something really small (around 1E-09) so, depending on your context, it is up to you to decide if you want to test for 0 or for a small value
So, if you change return value > 1E-08 to return value > 0 , you will get the truth when the video is paused.