用c++获取音频文件的信息 达到异步播放的效果(1)
2016-12-27 23:17
357 查看
这几个月加班都懵逼了 好久没有写博客了
这几天要做一个可即时打断的语音端 要想有暂停 续播这样的功能 我用的mciSendString 异步播放来实现打断的效果
其中想要获取音频文件的播放时长 找了好久才找到可以用的 哎 真是恼火 各种需求
连续加班三个月 哎 希望明年有个好去处 不过还好 至少遇到个好师傅
#include "parsePlayTime.h"
#import <Shell32.dll>
parsePlayTime::parsePlayTime()
{
//时长字符串中对应下标其代表的秒数
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::IShellDispatchPtr ptrShell;
ptrShell.CreateInstance(__uuidof(Shell32::Shell));
_variant_t var((short)Shell32::ssfRECENT);
//解析目录
Shell32::FolderPtr ptrFolder = ptrShell->NameSpace(dirName.c_str());
if (ptrFolder == NULL)
{
return -1;
}
//解析文件
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();
//由于精度只能到秒 少于1S的都按1S算
timeLength > 0 ? timeLength : 1;
//最后要换算成毫秒
timeLength *= 1000;
return timeLength;
}
拿到的时长是字符串 又因为我们的音频文件最多几分钟 所以就随便写了个转换的代码
主要是拿播放时长的代码
代码也是借鉴了网上一位大神的 码完代码 找不到网站了 如果侵犯了您的权益 请联系我删除 先说声抱歉。
刚入门的小菜鸡 请各位多多指教
这几天要做一个可即时打断的语音端 要想有暂停 续播这样的功能 我用的mciSendString 异步播放来实现打断的效果
其中想要获取音频文件的播放时长 找了好久才找到可以用的 哎 真是恼火 各种需求
连续加班三个月 哎 希望明年有个好去处 不过还好 至少遇到个好师傅
#include "parsePlayTime.h"
#import <Shell32.dll>
parsePlayTime::parsePlayTime()
{
//时长字符串中对应下标其代表的秒数
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::IShellDispatchPtr ptrShell;
ptrShell.CreateInstance(__uuidof(Shell32::Shell));
_variant_t var((short)Shell32::ssfRECENT);
//解析目录
Shell32::FolderPtr ptrFolder = ptrShell->NameSpace(dirName.c_str());
if (ptrFolder == NULL)
{
return -1;
}
//解析文件
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();
//由于精度只能到秒 少于1S的都按1S算
timeLength > 0 ? timeLength : 1;
//最后要换算成毫秒
timeLength *= 1000;
return timeLength;
}
拿到的时长是字符串 又因为我们的音频文件最多几分钟 所以就随便写了个转换的代码
主要是拿播放时长的代码
代码也是借鉴了网上一位大神的 码完代码 找不到网站了 如果侵犯了您的权益 请联系我删除 先说声抱歉。
刚入门的小菜鸡 请各位多多指教
相关文章推荐
- 用c++获取音频文件的信息 达到异步播放的效果(2)
- 用java获取mp3文件播放时长和tag信息
- C++获取文件大小等信息
- IOS开发——获取本地音频文件(属性/信息)
- 【Android开发经验】如何获取媒体库中所有音频文件信息,并在文件增删后及时更新媒体库(转)
- 【C#获取音频文件的播放时间】
- 用java获取mp3文件播放时长和tag信息
- IOS MPMoviePlayerViewController 获取当前音频文件播放时间点
- 实现php获取mp3文件元信息如播放时间歌曲作者等
- C#获取音频文件(MP3等)播放时间长度的几种方式
- 【Android开发经验】如何获取媒体库中所有音频文件信息,并在文件增删后及时更新媒体库
- C#获取 Flv视频文件播放时间长度等信息
- C++获取文件夹和文件信息
- 音频文件播放时间的获取
- C++获取flv视频文件的播放时间
- 最近想做一个音乐播放器,苦于不知道怎么获取音频文件的tag信息,查了很多资料,终于稍微有点眉目
- 获取音频文件的ID3信息,歌手,专辑,专辑图片等信息
- 如何从mp3,wma等音频文件中获取歌曲信息
- ajax实现异步请求,不跳转页面的情况下,达到检验用户名等信息是否效果的功能!
- 利用MediaPlayer 获取一个音频或者视频文件的播放时长