0

I'm a newbie C# coder and as part of my learning process I would like to build a desktop Windows app. The app basically detects if a certain app (web browser, iTunes, VLC, etc) is currently playing audio. If another running app starts playing audio at the same time, the app I wish to make would automatically temporarily turn down the audio volume from one of the apps. When the aduio from the second app stops playing audio, the audio would then return to its original level.

EG:

  • I'm playing music in iTunes

  • I start watching a YouTube video in Chrome

  • iTunes reduces its volume level (the music keeps playing at lower volume)

  • I finish watching the YouTube video

  • iTunes returns to its original volume level

 

I'm not sure if this app if possible to build as it may require deep OS integration. I've searched for ".net detect audio" but have found nothing. It may be beyond the limits of .net.

The app would also require .net to be able to adjust the audio level on an app by app basis as well as detecting it!

This is my first question on Stack Overflow. I've had this idea for several years now and have only recently started learning to code. I would love to produce this app as a portfolio piece, as well as release it as freeware online!

Thank you in advance.

Grand
  • 175
  • 1
  • 12

1 Answers1

1

There's a project on github names CScore

You can apply the code as follows :

   using System;
   using CSCore.CoreAudioAPI;

  namespace AudioDetector
{
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(IsAudioPlaying(GetDefaultRenderDevice()));
        Console.ReadLine();
    }

    public static MMDevice GetDefaultRenderDevice()
    {
        using (var enumerator = new MMDeviceEnumerator())
        {
            return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
        }
    }

    public static bool IsAudioPlaying(MMDevice device)
    {
        using (var meter = AudioMeterInformation.FromDevice(device))
        {
            return meter.PeakValue > 0;
        }
    }
}
}

This will notify u whenever an audio is playing,

Sourece

Software Dev
  • 5,368
  • 5
  • 22
  • 45