怎样通过程序获取一个视频文件的时长? 如题,怎样通过程序获取avi,mp4,wmv,swf,flv等常见视频或flash的播放时长?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果用vb,可以通过调用mediaplayer控件来实现,代码如下(w1就是一个mediaplayer控件):Private Sub Command1_Click()w1.URL = "e:\7.avi"Do If w1.openState = 13 Then Exit DoLoopMsgBox w1.currentMedia.durationEnd Sub但在vc我也用同样思路,但控件的openState似乎总不改变,不知哪位能有好的解决办法?谢谢! 很多格式的视频文件 mediaplayer根本就不能播放的 暂时先不考虑这个问题,我最终程序只要支持我前面提到过的几种格式就可以了。我的程序的主要功能是外界告诉程序某视频文件应播放多长时间,程序进行播放。程序需要根据时段播放时长和文件播放时长(我现在所提的问题就是怎样获此数据)计算出在此时间段内视频应播放几遍(windowsmediaplayer似乎没有循环播放的功能) 。例如,外界告诉程序播放a.avi16分钟,而a.avi的播放时长为5分钟,则程序需要播放4遍(即设置windowsmediaplayer的playcount=4) MCI(媒体控制接口),记得不清了,你在网上查下。 我在vc中写了下面代码(其中m_wmp1为windowsmediaplayer控件):void CTest3Dlg::OnButton1() {m_wmp1.SetUrl("E:\\7.avi");}void CTest3Dlg::OnButton2() { double filelen; int wmpopenstatus; CString tmpstring; wmpopenstatus=m_wmp1.GetOpenState(); filelen = m_wmp1.GetCurrentMedia().GetDuration(); tmpstring.Format("%d,%f",wmpopenstatus,filelen); MessageBox(tmpstring); }运行时,先点击button1,待画面正常播放后点击button2,弹出信息为“13,243.672000”(即播放器状态为13,文件时长为243.672000)但我如将代码放到一个事件中:void CTest3Dlg::OnButton1() { CWMPMedia currentmedia; int tmp; double filelen; CString tmpstring; tmp = m_wmp1.GetOpenState(); m_wmp1.SetUrl("E:\\7.avi"); while (tmp !=13)//在此陷入死循环 { tmp = m_wmp1.GetOpenState(); } currentmedia=m_wmp1.GetCurrentMedia(); filelen=currentmedia.GetDuration(); tmpstring.Format("%f",filelen);}程序则陷入死循环,哪位高手能告诉我怎么回事?谢谢!另外,我看有人说直接用filelen = m_wmp1.newMedia("E:\\7.avi").GetDuration();不需播放即可获取时长,但我这样写后得到的filelen =0,应怎样修改?望高手告知,再次感谢! 楼主贴的vb代码应该也是有误的,应为DoIf w1.openState = 13 Then Exit DodoeventsLoop在vc中如果实现了"doevents",也可以实现上述功能void CTest3Dlg::OnButton1() { MSG msg; CWMPMedia currentmedia; int tmp=0; double filelen; CString tmpstring; m_wmp1.SetUrl("E:\\7.avi"); while (tmp !=13) { tmp = m_wmp1.GetOpenState(); while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE) ) { TranslateMessage(&msg); DispatchMessage(&msg); } } currentmedia=m_wmp1.GetCurrentMedia(); filelen=currentmedia.GetDuration(); tmpstring.Format("%f",filelen); MessageBox(tmpstring);} 时长是遍历整个视频文件,通过pts计算出来的。 如何在列表控件里设定每一列,并向每一列写入数据? 多线程访问同一个数据库,需要加锁么? 通过手机作为modem,利用RAS API函数拨号上网的问题????? 100分挑战算法!!!!! 关于自动评分系统的实现方法 vc中资源问题。 请问下面这段话怎样translate? 处理字符串以修改数据库 请教一题:如何不调用C库函数实现char *strcpy(char* strDest,const char* strSrc).来者有分! 能得到容器的窗口句柄或指针吗?(比如IE中启动了一个COM后,要得到IE客户区窗口) mfc中CArchive::operator >>序列化问题 驱动问题
Private Sub Command1_Click()
w1.URL = "e:\7.avi"
Do
If w1.openState = 13 Then Exit Do
LoopMsgBox w1.currentMedia.durationEnd Sub
但在vc我也用同样思路,但控件的openState似乎总不改变,不知哪位能有好的解决办法?谢谢!
void CTest3Dlg::OnButton1()
{
m_wmp1.SetUrl("E:\\7.avi");
}
void CTest3Dlg::OnButton2()
{
double filelen;
int wmpopenstatus;
CString tmpstring;
wmpopenstatus=m_wmp1.GetOpenState();
filelen = m_wmp1.GetCurrentMedia().GetDuration();
tmpstring.Format("%d,%f",wmpopenstatus,filelen);
MessageBox(tmpstring);
}
运行时,先点击button1,待画面正常播放后点击button2,弹出信息为“13,243.672000”(即播放器状态为13,文件时长为243.672000)
但我如将代码放到一个事件中:
void CTest3Dlg::OnButton1()
{
CWMPMedia currentmedia;
int tmp;
double filelen;
CString tmpstring;
tmp = m_wmp1.GetOpenState();
m_wmp1.SetUrl("E:\\7.avi");
while (tmp !=13)//在此陷入死循环
{
tmp = m_wmp1.GetOpenState();
}
currentmedia=m_wmp1.GetCurrentMedia();
filelen=currentmedia.GetDuration();
tmpstring.Format("%f",filelen);
}
程序则陷入死循环,哪位高手能告诉我怎么回事?谢谢!
另外,我看有人说直接用
filelen = m_wmp1.newMedia("E:\\7.avi").GetDuration();
不需播放即可获取时长,但我这样写后得到的filelen =0,应怎样修改?望高手告知,再次感谢!
Do
If w1.openState = 13 Then Exit Do
doevents
Loop
在vc中如果实现了"doevents",也可以实现上述功能
void CTest3Dlg::OnButton1()
{ MSG msg;
CWMPMedia currentmedia;
int tmp=0;
double filelen;
CString tmpstring;
m_wmp1.SetUrl("E:\\7.avi");
while (tmp !=13)
{
tmp = m_wmp1.GetOpenState();
while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} }
currentmedia=m_wmp1.GetCurrentMedia();
filelen=currentmedia.GetDuration();
tmpstring.Format("%f",filelen);
MessageBox(tmpstring);}