1

I am developing on a UWP app which need to listen playback/audio state change. such as: can know when other app start/stop to play a audio.

On Windows, I see there is an API "Windows.Media.Audio.AudioStateMonitor", but it only listen sound level change of app's own audio play. https://learn.microsoft.com/en-us/uwp/api/windows.media.audio.audiostatemonitor?view=winrt-22621

On Android, there is an API that fully meet my requirement. AudioManager#registerAudioPlaybackCallback()

I want to query, is there any API on Windows that can listen playback/audio state change of whole Windows system. Like Android's AudioManager#registerAudioPlaybackCallback()

Damon Pan
  • 23
  • 5

1 Answers1

0

UWP runs in a sandbox and has no permission to access other app. UWP does not have related API support for this.

It is possible to use the Windows Core Audio API IAudioMeterInformation::GetPeakValue to query whether the sound is playing.

Since UWP cannot directly use Win32 API, you need to write a project that uses Win32 API first, then package this project with the UWP project and realize the communication between the two project.

You can use IAudioMeterInformation this code in WPF, then use Windows Application Packaging Project to package WPF and UWP project. You can refer to this blog: UWP with Desktop Extension.

Junjie Zhu - MSFT
  • 2,086
  • 1
  • 2
  • 6
  • Thank Junjie. Actually, I don't want to access other app. But I want to receive the state change when system is start to play audio, so I can stop my music play. Only query whether sound is playing is not enough, you know it is not possible to infinitely loop query the system sound play. I need to get the audio state change notification. – Damon Pan Feb 10 '23 at 01:25
  • UWP doesn't have such audio state change notification. `IAudioMeterInformation` can achieve similar function, so you need to use Win32 API to query whether the sound is playing. – Junjie Zhu - MSFT Feb 10 '23 at 06:43
  • Thanks from your comments. Is there any Win32 APIs, support to query current playing sound type? Such as: music, communication call (such as: teams call) ... – Damon Pan Feb 13 '23 at 06:42
  • According to my search, win32 seems to have no related APIs. – Junjie Zhu - MSFT Feb 14 '23 at 08:12