/*
加载本地html文件
// System.IO.FileInfo file = new System.IO.FileInfo("wmh.html");
//this.webBrowser1.Url = new Uri(file.FullName);
//webBrowser1.DocumentCompleted += webBrowser1DocumentCompleted; //加载地图完成时调用
//if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "wmh.html"))
//{
this.webBrowser1.Url = new Uri(wmh.html);
}
this.webBrowser1.ObjectForScripting = this;
*/
var itemId = 0;
function init()
{
if( navigator.appName.indexOf("Microsoft Internet") == -1 )
{
onVLCPluginReady()
}
else if( document.readyState == ‘complete’ )
{
onVLCPluginReady();
}
else
{
/* Explorer loads plugins asynchronously */
document.onreadystatechange = function()
{
if( document.readyState == ‘complete’ )
{
onVLCPluginReady();
}
}
}
}
function getVLC(name)
{
if (window.document[name])
{
return window.document[name];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1)
{
if (document.embeds && document.embeds[name])
return document.embeds[name];
}
else
{
return document.getElementById(name);
}
}
function doItemCount()
{
var vlc = getVLC("vlc");
if( vlc )
{
var count = vlc.playlist.items.count;
//document.getElementById("itemCount").value = " Items: " + count + " ";
}
}
//这里是播放的函数 可以从c#里面调
/*
private void Form1_Shown(object sender, EventArgs e)
{
// if (checkBrowser())//输入参数
// {
//string targetURL = textBox1.Text;
doGo1(targetURL);
// }
}
public void doGo1(string targetURL)//
{
webBrowser1.Document.InvokeScript("doGo1", new string[] { targetURL });
}
*/
function doGo1(targetURL)
{
var vlc = getVLC("vlc");
//targetURL = "rtsp://202.104.126.35/demo";
if( vlc )
{
vlc.playlist.items.clear();
var options = [":rtsp-tcp"];
var itemId = vlc.playlist.add(targetURL,"",options);
//var itemId = vlc.playlist.add("rtsp://202.104.126.35/demo");
if( itemId != -1 )
{
// play MRL
vlc.playlist.playItem(itemId);
}
else
{
alert("cannot play at the moment !");
}
doItemCount();
//document.getElementById("btn_stop").disabled = false;
}
}
function RtspDelete()
{
var vlc = getVLC("vlc");
vlc.playlist.items.clear();
}
function doAdd(targetURL)
{
var vlc = getVLC("vlc");
var options = [":vout-filter=deinterlace", ":deinterlace-mode=linear"];
if( vlc )
{
vlc.playlist.items.clear();
var itemId=vlc.playlist.add(targetURL);
//vlc.playlist.add(targetURL, "", options);
if( itemId != -1 )
{
// play MRL
vlc.playlist.playItem(itemId);
}
doItemCount();
}
}
/*
function doGo(mrl)
{
mrl = "rtsp://202.104.126.35/demo";
var vlc = getVLC("vlc");
itemId=vlc.playlist.add(mrl);
vlc.playlist.playItem(itemId);
document.getElementById("btn_stop").disabled = false;
}
*/
function updateVolume(deltaVol)
{
var vlc = getVLC("vlc");
vlc.audio.volume += deltaVol;
}
function doPlay()
{
vlc.playlist.playItem(itemId);
document.getElementById("btn_stop").disabled = false;
document.getElementById("btn_play").disabled = true;
}
function doStop()
{
getVLC("vlc").playlist.stop();
document.getElementById("btn_stop").disabled = true;
document.getElementById("btn_play").disabled = false;
}
//仅适用于IE浏览器是,并且安装有vlc插件,则返回true;
function isInsalledIEVLC()
{
var vlcObj = null;
var vlcInstalled= false;
try {
vlcObj = new ActiveXObject("VideoLAN.Vlcplugin.1");
if( vlcObj != null )
{
vlcInstalled = true
}
} catch (e)
{
vlcInstalled= false;
}
return vlcInstalled;
}
//仅适用于firefox浏览器是,并且安装有vlc插件,则返回true;
function isInsalledFFVLC()
{
var numPlugins=navigator.plugins.length;
for (i=0;i
{
plugin=navigator.plugins[i];
if(plugin.name.indexOf("VideoLAN") > -1 || plugin.name.indexOf("VLC") > -1)
{
return true;
}
}
return false;
}
这里是浏览器检测是不是安装了vlc,没有安装就马上安装个
/* 浏览器检测 */
function checkBrowser()
{
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if ( browser=="Netscape" && version>=4)
{
if(isInsalledFFVLC())
{
alert("已装VLC");
}
else
{
alert("未装VLC");
location.href="http://download.videolan.org/pub/videolan/vlc/2.2.1/win32/vlc-2.2.1-win32.exe";
//location.href=“http://rj.baidu.com/soft/detail/12124.html?ald”;
}
}else if(browser=="Microsoft Internet Explorer" && version>=4)
{
if(isInsalledIEVLC())
{
alert("已装VLC");
}else
{
alert("未装VLC,请先安装");
location.href="http://download.videolan.org/pub/videolan/vlc/2.2.1/win32/vlc-2.2.1-win32.exe";
//location.href=“http://rj.baidu.com/soft/detail/12124.html?ald";
}
}
}
这里是调用本地vlc播放器的插件这里十分重要
codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"
width="1140" height="520" id="vlc" events="True">
type="application/x-vlc-plugin"
version="VideoLAN.VLCPlugin.2"
width="600"
height="480"
text="Waiting for video"
name="vlc"
>
本文由【waitig】发表在等英博客 本文固定链接:html 嵌入vlc插件 欢迎关注本站官方公众号,每日都有干货分享!
点赞 (0)赏分享 (0)