Use c++ to obtain the information of the audio file to achieve the effect of asynchronous playback (1)

I've been working overtime for a few months and I haven't written a blog for a long time.

In the past few days, I want to make a voice terminal that can be interrupted instantly. If I want to have the function of pausing and resuming playback, I use mciSendString to play asynchronously to achieve the effect of interruption.

Among them, I have been looking for the playback time of the audio file for a long time before I can find it. It's really annoying.

Working overtime for three consecutive months, I hope to have a good place next year, but fortunately at least I met a good teacher

#include "parsePlayTime.h"
#import <Shell32.dll> 
parsePlayTime :: parsePlayTime ()
{
//The number of seconds represented by the corresponding subscript in the duration string
timeIndex[3] = 600;
timeIndex[4] = 60;
timeIndex[6] = 10;
timeIndex [7] = 1;
}

parsePlayTime :: ~ parsePlayTime ()
{
}

int parsePlayTime::parseVoicePlayTime(std::string filePath)
{

std::string fileName, dirName;
dirName = filePath.substr(0, filePath.find_last_of('\\') + 1).c_str();
fileName = filePath.substr(filePath.find_last_of('\\') + 1);
CoInitialize(NULL);
clock_t time;
Shell32 :: ShellDispatchPtr ptrShell;
ptrShell.CreateInstance(__uuidof(Shell32::Shell));
_variant_t var((short)Shell32::ssfRECENT);

//parse directory
Shell32::FolderPtr ptrFolder = ptrShell->NameSpace(dirName.c_str());

if (ptrFolder == NULL)

{

return -1;

}
//analyse file

Shell32::FolderItemPtr ptrItem = ptrFolder->ParseName(fileName.c_str());

if (ptrItem == NULL)
{
return -1;
}

std::string timeValue = ptrFolder->GetDetailsOf(_variant_t((IDispatch *)ptrItem), 27);
int timeLength = 0;
for (int i = timeValue.size() - 1; i >= 0; i--)
{
if (timeValue[i] >= '0' && timeValue[i] <= '9')
{
timeLength += (timeValue[i] - '0') * timeIndex[i];
}

}
ptrItem.Release();
ptrFolder.Release();
ptrShell.Release();
CoUninitialize();
//Because the precision can only reach the second less than 1S, it is calculated as 1S
timeLength > 0 ? timeLength : 1;
// Finally, convert to milliseconds
timeLength *= 1000;
return timeLength;

}

The length of time I got is a string, and because our audio file is at most a few minutes, we just wrote a code to convert it. 

Mainly to take the code of the playback time

The code is also borrowed from a great god on the Internet. After the code is finished, the website cannot be found. If you violate your rights, please contact me to delete it and say sorry. 

Newbies, please give me some advice

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325564700&siteId=291194637