当前位置: 首页 > 工具软件 > FX Player > 使用案例 >

Media Player控件使用

和谦
2023-12-01

1 新建Dialog应用程序
2 1)在Dialog上右击, 选择"Insert ActiveX Control"
  2)选择"Windows Media Player", ID为"IDC_OCX1"
3 1)在ClassWizard中为"IDC_OCX1"添加变量"m_player"
  2)Category:Control Variabletype:CWMPPlayer4

添加需要的".h文件",及控制代码 

#include "wmpplayer4.h"
#include "wmpcontrols.h"
#include "wmpsettings.h"

//wmpplayer4.h

m_wmp.openPlayer("F:\\a.avi");  //去等外部播放器并播放的电影或音乐.但不能对其进行下面的控制.不建议.

m_player.SetUrl("F:\\a.avi"); //设置要播的电影或者音乐

//wmpcontrols.h
m_player.GetControls().play(); //开始播放
m_player.GetControls().pause(); //暂停播放
m_player.GetControls().pause(); //停止
funSetPosition(int posPerCent) //设置播放进度条, 60% posPerCent=60
{
    if ( posPerCent >= 0 && posPerCent <= 100)
    {
        double percent = m_player.GetCurrentMedia().GetDuration() * (posPerCent/100);
        m_player.GetControls().SetCurrentPosition(percent);

        return 0;
    }
    else
        return 1;
}

//wmpsettings.h
funVolumeADD(int step) //音量增加
{
    long cur_vol = m_player.GetSettings().GetVolume();

    if (cur_vol < 100 - step)
        m_player.GetSettings().SetVolume( cur_vol + step);
    else
        m_player.GetSettings().SetVolume( 100);

    return 0;
}

funVolumeSUB(int step) //音量减少
{
    long cur_vol = m_player.GetSettings().GetVolume();

    if (cur_vol > step)
        m_player.GetSettings().SetVolume( cur_vol - step);
    else
        m_player.GetSettings().SetVolume( 0);

    return 0;
}

int CVideoFrame::funMute() //静音
{
    if (m_player.GetSettings().GetMute())
        m_player.GetSettings().SetMute(FALSE);
    else
        m_player.GetSettings().SetMute(TRUE);

    return 0;
}


 
另外, 可以为控件添加消息响应.
例如: 需要播放时全屏,并且双击退出全屏并暂停节目.
1 ClassWizard->Message Maps
  Object IDs:"IDC_OCX1" add Messages:"PlayStateChange"
        生成函数"OnPlayStateChangeOcx1(long NewState)"             
  Object IDs:"IDC_OCX1" add Messages:"DoubleClick"
        生成函数"OnDoubleClickOcx1(short nButton, short nShiftState, long fX, long fY)"
 

//播放时全屏
void OnPlayStateChangeOcx1(long NewState) 
{
    switch(NewState) 
    {
        case 1:        //stopped 
            break; 
        case 2:     //Paused; 
            break; 
        case 3:        //playing 
            m_player.SetFullScreen(TRUE);             
            break;             
        default:; 
    } 
}

//双击退出全屏 && 暂停
void OnDoubleClickOcx1(short nButton, short nShiftState, long fX, long fY) 
{
    m_player.SetFullScreen(FALSE);
    m_player.GetControls().pause();
}

 类似资料: