<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="VLC_Play.aspx.cs" Inherits="MainWeb.Video.Pages.VLC_Play" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>視頻播放</title> <script type="text/javascript" src="/Scripts/jquery-1.9.1.min.js"></script> </head> <body> <form id="form1" runat="server"> <div id="div_VLC" style="height: 100%; overflow: hidden;"> <%-- <object class="vlc" type='application/x-vlc-plugin' events='True' width="100%" height="100%"> <param name='mrl' value='' /> <param name='volume' value='50' /> <param name='autoplay' value='true' /> <param name='loop' value='false' /> <param name='fullscreen' value='false' /> </object>--%> <%-- <div style="height: 1000px; overflow: auto;"> <object id="vlc" class="vlc" type='application/x-vlc-plugin' events='True' width="720" height="540" classid='clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921'> <param name='mrl' value='' /> <param name='volume' value='50' /> <param name='autoplay' value='true' /> <param name='loop' value='false' /> <param name='fullscreen' value='false' /> </object> </div>--%> </div> <script type="text/javascript"> //上面的object 在其餘瀏覽器中有效,下面的object在ie下面有效; //可使用js判斷瀏覽器類型來動態插入object對象: function showPlayer(id, url) { var vhtml = '<object id="vlc" class="vlc"'; //var userAg = navigator.userAgent; //if (-1 != userAg.indexOf("MSIE")) { vhtml += ' classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"'; //} //else if (-1 != userAg.indexOf("Firefox") || -1 != userAg.indexOf("Chrome") || -1 != userAg.indexOf("Opera") || -1 != userAg.indexOf("Safari")) { vhtml += ' type="application/x-vlc-plugin"'; //} vhtml += ' events="True"'; //vhtml += ' width="' + $(window).width() + '"'; //vhtml += ' height="' + $(window).height() + '"'; vhtml += '>'; //下面這些播放器的參數本身配置吧 vhtml += " <param name='mrl' value='' />"; vhtml += " <param name='volume' value='50' />"; vhtml += " <param name='autoplay' value='true' />"; vhtml += " <param name='loop' value='false' />"; vhtml += " <param name='fullscreen' value='true' />"; vhtml += ' </object>'; document.getElementById("div_VLC").innerHTML = vhtml; $("#vlc").width($(window).width()); $("#vlc").height($(window).height() - 30); //setTimeout(function () { if (_url != '') { play(_url); } //}, 5000); } /* 瀏覽器檢測 */ function checkBrowser() { var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字符串 if (!!window.ActiveXObject || "ActiveXObject" in window || userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) { if (isInsalledIEVLC()) { //alert("已裝VLC"); } else { alert("未裝VLC,請先安裝"); window.open("http://dl.pconline.com.cn/html_2/1/124/id=6661&pn=0.html"); location.href = "https://get.videolan.org/vlc/3.0.3/win64/vlc-3.0.3-win64.exe"; //https://www.videolan.org/ } } else if (userAgent.indexOf("Firefox") > -1) { if (isInsalledFFVLC()) {// //alert("已裝VLC"); } else { alert("未裝VLC"); window.open("http://dl.pconline.com.cn/html_2/1/124/id=6661&pn=0.html"); location.href = "https://get.videolan.org/vlc/3.0.3/win64/vlc-3.0.3-win64.exe"; //https://www.videolan.org/ } } else { alert("VLC播放器暫時僅支持IE和火狐瀏覽器!"); } //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"; // } //} } function isInsalledIEVLC() { var vlcObj = null; var vlcInstalled = false; try { vlcObj = new ActiveXObject("VideoLAN.Vlcplugin.2"); if (vlcObj != null) { vlcInstalled = true } } catch (e) { vlcInstalled = false; } return vlcInstalled; } function isInsalledFFVLC() { var numPlugins = navigator.plugins.length; for (i = 0; i < numPlugins; i++) { plugin = navigator.plugins[i]; if (plugin.name.indexOf("VideoLAN") > -1 || plugin.name.indexOf("VLC") > -1) { return true; } } return false; } checkBrowser(); function play(mrl) { var vlc = document.getElementById("vlc"); vlc.playlist.clear(); //將地址添加到播放列表 var options = new Array(":newwork-caching=100"); var id = vlc.playlist.add(mrl, "MNVideo", options); vlc.playlist.playItem(id); //vlc.playlist.add(mrl); //播放 //vlc.playlist.play(); _vlc = vlc; } var _url = 'http://110.10.142.121/test.mp4'; // screen:// rtsp://172.30.0.10:555/2 elem.href rtsp://172.16.15.186:554/12345.sdp $(function () { showPlayer(); $(window).resize(function () { showPlayer(); }); }) /*針對有的彈出框中關閉界面(隱藏)資源未釋放問題須要作調整*/ setInterval(function () { if ($("#div_VLC").is(":hidden")) { playListClear(); } }, 2000); var _vlc; function playListClear() { _vlc.playlist.stop(); _vlc.playlist.clear(); } //window.onbeforeunload = function (event) { playListClear(); delete _vlcs; return confirm("肯定離開此頁面嗎?"); } //window.onunload = function () { playListClear() } </script> </form> </body> </html>