如题,怎样通过程序获取avi,mp4,wmv,swf,flv等常见视频或flash的播放时长?谢谢!

解决方案 »

  1.   

    如果用vb,可以通过调用mediaplayer控件来实现,代码如下(w1就是一个mediaplayer控件):
    Private Sub Command1_Click()
    w1.URL = "e:\7.avi"
    Do
        If w1.openState = 13 Then Exit Do
    LoopMsgBox w1.currentMedia.durationEnd Sub
    但在vc我也用同样思路,但控件的openState似乎总不改变,不知哪位能有好的解决办法?谢谢!
      

  2.   

    很多格式的视频文件 mediaplayer根本就不能播放的
      

  3.   

    暂时先不考虑这个问题,我最终程序只要支持我前面提到过的几种格式就可以了。我的程序的主要功能是外界告诉程序某视频文件应播放多长时间,程序进行播放。程序需要根据时段播放时长和文件播放时长(我现在所提的问题就是怎样获此数据)计算出在此时间段内视频应播放几遍(windowsmediaplayer似乎没有循环播放的功能) 。例如,外界告诉程序播放a.avi16分钟,而a.avi的播放时长为5分钟,则程序需要播放4遍(即设置windowsmediaplayer的playcount=4)
      

  4.   

    MCI(媒体控制接口),记得不清了,你在网上查下。
      

  5.   

    我在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,应怎样修改?望高手告知,再次感谢!
      

  6.   

    楼主贴的vb代码应该也是有误的,应为
    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);}
      

  7.   

    时长是遍历整个视频文件,通过pts计算出来的。