Hi @Rahmatulloh , Welcome to Microsoft Q&A,
Use the NAudio library to get the volume of the current system audio playback device. If the volume is greater than zero, it can be determined that audio is playing.
Use the Windows API to get all running processes in the system and check the audio output of these processes.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using NAudio.CoreAudioApi;
class Program
{
static void Main(string[] args)
{
var deviceEnumerator = new MMDeviceEnumerator();
var defaultDevice = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
// Get the audio meter information
var audioMeterInformation = defaultDevice.AudioMeterInformation;
// Check if the audio level is greater than 0 (indicating that audio is playing)
if (audioMeterInformation.MasterPeakValue > 0)
{
Console.WriteLine("Audio is playing.");
}
else
{
Console.WriteLine("No audio is playing.");
}
// Optionally, you can list all processes and check their names
var processes = Process.GetProcesses();
foreach (var process in processes)
{
Console.WriteLine($"Process: {process.ProcessName} (ID: {process.Id})");
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.