Get Length of WAV File

Ray Turner
Ray Turner used Ask the Experts™
on
How can you get the length of a WAV file (seconds or milliseconds) using Visual Basic 2015 and WIN API?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Commented:
Hook up the below C++ function in your CV.
First make sure that below function get u the result I.e. length of wav file and then make DLL of it and import in your vb
DWORD GetSoundLength(LPSTR strFileName)

{

  CWaveFile* pWav;

  DWORD dwLen = 0;

  DWORD dwSize;

  WAVEFORMATEX* wfx;

 

  pWav = new CWaveFile();

  if (SUCCEEDED(pWav->Open(strFileName, NULL, WAVEFILE_READ)))

  {

    wfx = pWav->GetFormat();

    dwSize = pWav->GetSize();

    dwLen = (DWORD) (1000 * dwSize / wfx->nAvgBytesPerSec);

    pWav->Close();

  }

  if (pWav) delete pWav;

  return dwLen;

}
Ray TurnerSenior Consultant

Author

Commented:
Can you provide a Visual Basic version of this?  I'm a little rusty with C++ :)
Ray TurnerSenior Consultant

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial