首先是在html页面调用:
第一种方式:下面直接给出的是调用函数
function doGo(targetURL, port)
{
var options = new Array("vlc",
":input-repeat=1",
":aspect-ratio=704:480",
"--no-drop-late-frames",
"--no-overlay");
document.vlc.playlistClear();
document.vlc.addTarget(targetURL+":"+port+"/stream", options, 4+8, -666);
};
第二种方式:vlc activex给出的范例页面
function doGo(targetURL)
{
var vlc = document.getElementById("vlc");
var options = new Array(":vout-filter=deinterlace", ":deinterlace-mode=linear");
vlc.playlist.clear();
//vlc.playlist.add(targetURL, null, options);
vlc.playlist.add(targetURL);
vlc.playlist.play();
if( monitorTimerId == 0 )
{
monitor();
}
};
其实是大同小异,只是一些引用方式的不一样。我们今天重点要讨论的是vc++中调用vlc的activex plugin,addTarget的第二个参数options在vc++里面如何实现。addTarget的第二个参数是VARIANT类型的,如何在vc++里面创建Array,并转化成VARIANT类型。
还是直接给出源码:
void CTestVlcDlg::OnConnect()
{
HRESULT hr;
SAFEARRAY *pSA;
SAFEARRAYBOUND aDim[1];
aDim[0].lLbound= 0;
aDim[0].cElements= 3; //下面需要用到多少个参数,修改这里
int i;
// create bstr safe array
pSA= SafeArrayCreate(VT_BSTR,1,aDim);
if (!pSA )
{
/// do something here on your own
return;
}
BSTR HUGEP *pbstr;
hr=SafeArrayAccessData(pSA,(void HUGEP**)&pbstr);
if (FAILED(hr))
{
// do something to prevent further errors
return;
}
// got options? tell vlc activeX about it
pbstr[0] = SysAllocString(OLESTR(":aspect-ratio=704:480"));
pbstr[1] = SysAllocString(OLESTR(":no-overlay"));
pbstr[2] = SysAllocString(OLESTR(":deinterlace-mode=linear"));
SafeArrayUnaccessData(pSA);
// well, the vlc.playlistClear(); is not important here, if you want to safe your playlist
m_pVlcCtrl->playlistClear();
m_pVlcCtrl->stop();
// declare safe array as Variant
CComVariant vOptions(pSA);
VARIANT zOptions;
zOptions.vt = VT_ARRAY|VT_UI1;
zOptions.parray = pSA;
int cOptionsCount;
char **cOptions;
if( FAILED(CreateTargetOptions(CP_UTF8, &zOptions, &cOptions, &cOptionsCount)) )
return ;
m_pVlcCtrl->addTarget ("rtsp://192.168.1.96:7889/stream", zOptions,4+8, -666);
m_pVlcCtrl->play();
}
不再作详细的介绍,这段代码也是从网上找了很久的SAFEARRAY 操作,摸索很久才搞出来的,记录下来,相信以后还会用的到。