Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I don't have any strong enough knowledge to build this kind of app, console-based. As far as I have info about how to build this kind of console-based app, it requires Windows Audio Internal API, if i am not mistaken, it's WASAPI. But since I don't have that knowledge at all, please help me to do this kind of app

What I have tried:

I was trying to do it with some AI tools, like chatgpt 3 and google gemini(google bard). But I couldn't figure out how to do it, though it gives some code snippets to build that kind of console-based app.

Here's what it's generated for me:

#include <windows.h>
#include <mmsystem.h>
#include <iostream>

bool isAudioPlaying() {
  HWAVEOUT hWaveOut;
  MMTIME mmTime;

  // Open a non-existent wave output device to get system information
  if (waveOutOpen(&hWaveOut, WAVE_MAPPER, NULL, (DWORD_PTR) NULL, 0, CALLBACK_NULL)) {
    std::cerr << "Error opening wave output device." << std::endl;
    return false;
  }

  // Check playback position
  mmTime.wType = TIME_PLAY;
  if (waveOutGetPosition(hWaveOut, &mmTime, sizeof(mmTime))) {
    std::cerr << "Error getting playback position." << std::endl;
    waveOutClose(hWaveOut);
    return false;
  }

  // Close the non-existent device
  waveOutClose(hWaveOut);

  // Playback position > 0 indicates some audio is playing
  return (mmTime.wTime > 0);
}

int main() {
  if (isAudioPlaying()) {
    std::cout << "It does." << std::endl;
  } else {
    std::cout << "It doesn't." << std::endl;
  }

  return 0;
}


But it's not generating code for a specific audio file
Posted
Comments
jeron1 13-Mar-24 12:00pm    
maybe something in this thread might be useful?
https://stackoverflow.com/questions/12991034/monitoring-an-audio-file-to-check-when-its-opened-by-another-program
Andre Oosthuizen 13-Mar-24 12:03pm    
You will have to try this on your own in order to understand the code, nobody is going to write a sample app for you. a Quick search will direct you in the right direction -

using c console application, How to check if a specific audio file is being played - Google Search[^]

1 solution

This code is obsolete since win2000 because every process has its own wave mapper. The code seems to try if the wave mapper (win95) is already in use - not a specific audio file. To try if a specific file is in use you should open the file exclusive (read/write/denyshare). The file may be in use if you cant do that. But this must not be a evidence for playing the file as audio (maybe edit etc.).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900