嵌入vlc(自用笔记)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" charset="UTF-8">
  var vdUrl =""; // 播放路径(定义为全局变量,给子页面播放控件提供播放路径)
  function showDialog(type){
     vdUrl="http://www.51-n.com/images/1234.flv";
     var temp=document.getElementsByName('fileName')[0].value;
     if(temp==''){
      alert('请选择一个有效的本地视频文件,或者输入网络视频地址...');
      return;
     }    
     vdUrl=temp;
     eventCode="XXXX";
     if(type==1){
        var winObj=window.open('./视频empty_play.html','play',
           'height=640, width=740,toolbar=yes, menubar=yes, scrollbars=no, resizable=no,location=no, status=no');
     }else if(type==2){
        var winObj=window.open('./play.html','play',
           'height=640, width=740,toolbar=yes, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
     }
    
  }
</script>
<title>test</title>
</head>

<body>
<input type="file" name="fileName" style="width: 350px">  
<input type="button" value=" 播  放 " οnclick="showDialog(1);">
<br>
<span style="color: red;font-weight: bold;font-size: 14px">提示:</span>
<span style="color: blue;font-weight: normal;font-size: 14px">请选择本地视频或者输入一个网络视频路径(建议先通过VLC media player播放通过)。</span>
</body>
</html>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>视频剪辑</title>
<script type="text/javascript" charset="UTF-8">
<!-- 屏蔽右键
   // document.οncοntextmenu=function(e){return false;}  
//-->
var vlc; // VLC对象
var itemId;  // 播放列表中播放节目的id
var vlcSound; // vlc音量大小(初始化默认为50)
var videoLength; // 视频总时长
var then_time; // 播放开始时间(播放开始的日期,看下面实现代码,它是毫秒哦)
var isPlaying=0; // 是否播放状态 (0 未播放 1 播放)
// 初始化 === 很重要哦,控制程序的入口
function initPlayUrl(){
vlc=document.getElementById("vlc");
// 添加播放地址
//vlc.playlist.add(window.opener.vdUrl);
// 播放
// vlc.playlist.play();
// 添加播放地址方式2 -- 推荐用下面的方法控制播放列表
var vedio_url=window.opener.vdUrl;
itemId= vlc.playlist.add(vedio_url);
    vlc.playlist.playItem(itemId);
   
    // 获取VLC当前音量
    vlcSound=vlc.audio.volume;
    // 设置VLC音量值
    document.getElementById("vlc_sound").value=vlcSound;
    // 播放按钮不可用
    document.getElementById("play_button").disabled=true;
   
    // 检查播放节目的状态 -- 注意这个是延时操作哦(setTimeout以毫秒为单位,这里延时0.5秒)
    setTimeout(checkVedioStatus,500);
}
// 检查播放节目的状态
function checkVedioStatus(){
    if(vlc.input.state>2 && vlc.input.state<5){
     isPlaying=1;
     // vlc.input.time 当前播放时长,单位毫秒
     // vlc.input.length 节目总时长,单位毫秒
     videoLength=parseInt(vlc.input.length/1000);
     var temp_total_time=parseTime(videoLength);
     // 总时长设置
     document.getElementById("vedio_length").value=temp_total_time;
     // 当前可以输入时间段跳转
     document.getElementById("time_change").disabled=false;
     // 获得当前系统时间
     then_time=new Date().getTime();
     // 计算当前播放时间点
     checkTime();
    }else{
     // 如果不是播放状态就在延时执行
     setTimeout(checkVedioStatus,500);
    }
}
// 实时检测系统时间,计算视频的播放时长(典型的秒表功能)
function checkTime(){
if(isPlaying==1){
  setTimeout("checkTime();",50);
  var temp_time=parseInt((new Date().getTime() - then_time)/1000);
  document.getElementById("current_video_time").value=parseTime(temp_time);
}
}
// 改变播放地址
function changeNewBeginTime(){
// vlc.input.time 获取当前播放时间(毫秒)/也可重设当前播放时间点
var jumpTime=document.getElementById("change_length").value;
if(jumpTime!=""){
  if(jumpTime>videoLength){
   alert("对不起,输入值大于视频总时长...");
   return;
  }
  vlc.input.time=jumpTime*1000;
  then_time=new Date()-jumpTime*1000;
}
}
// 把秒转换为时间格式(HH:mm:ss)
function parseTime(numLength){
var h_time=0;
var m_time=0;
var s_time=0;
if(numLength>=60){
  m_time=parseInt(numLength/60);
  s_time=parseInt(numLength%60);
}else{
  s_time=numLength;
}
if(m_time>=60){
  h_time=parseInt(m_time/60);
  m_time=parseInt(m_time%60);
}

if(h_time<10){
  h_time="0"+h_time;
}
if(m_time<10){
  m_time="0"+m_time;
}
if(s_time<10){
  s_time="0"+s_time;
}
return h_time+":"+m_time+":"+s_time;
}
// 停止播放
function stopPlay(){
vlc.playlist.stop();
isPlaying=0;

// 修改播放/停止按钮状态
document.getElementById("play_button").disabled=false;
    document.getElementById("stop_button").disabled=true;
   
    // 修改跳转按钮的状态
    document.getElementById("change_length").value="";
    document.getElementById("time_change").disabled=true;
   
    // 当前视频播放时间点清空
    document.getElementById("current_video_time").value="";
}
// 重新播放
function repeatPlay(){
vlc.playlist.play();
setTimeout(checkVedioStatus,500);
// 修改播放/停止按钮状态
document.getElementById("play_button").disabled=true;
    document.getElementById("stop_button").disabled=false;
}
// 静音
function noSound(){
if(vlcSound>0){
  vlcSound=0;
}
vlc.audio.toggleMute();
vlcSound=vlc.audio.volume;
document.getElementById("vlc_sound").value=vlcSound;
if(vlcSound==0){
  // document.getElementById("no_sound").value=" 恢复音量 ";
  document.getElementById("no_sound").value=" "+"恢复音量"+" ";
}else{
  // document.getElementById("no_sound").value=" 静    音 ";
  document.getElementById("no_sound").value=" "+"静"+"  "+"音"+" ";
}
}
// 音量加减
function soundChange(nums){
if(nums<0 && vlcSound==0){
  alert("音量最小,不能再减少音量....");
  return;
}
vlcSound+=nums;
if(vlcSound<=0){
  vlcSound=0;
  document.getElementById("no_sound").value=" "+"恢复音量"+" ";
}else{
  // 当音量>0的时候,都要把静音的标识打开
  document.getElementById("no_sound").value=" "+"静"+"  "+"音"+" ";
}
if(vlcSound>200){
  alert("音量最大,不能再增大音量....");
  vlcSound=200;
}
vlc.audio.volume =vlcSound;
document.getElementById("vlc_sound").value=vlcSound;
}
//全屏
function screenFull(){
  vlc.video.toggleFullscreen()
}
</script>
</head>

<body οnlοad="initPlayUrl()" >
<!--[if IE]><!-->
   <object type='application/x-vlc-plugin' id='vlc' events='True'
       classid='clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921' width="720" height="540">
          <param name='mrl' value='' />
          <param name='volume' value='50' />
          <param name='autoplay' value='false' />
          <param name='loop' value='false' />
          <param name='fullscreen' value='false' />
    </object>
<!--[endif]-->
<!--[if !IE]><!-->
    <object type='application/x-vlc-plugin' id='vlc' events='True' width="720" height="540">
        <param name='mrl' value='' />
        <param name='volume' value='50' />
        <param name='autoplay' value='true' />
        <param name='loop' value='false' />
        <param name='fullscreen' value='false' />
        <embed width="720" height="540" mrl="" volume="50" autoplay="true" loop="false" fullscreen="false"></embed>
    </object>
<!--<![endif]-->
<br><br>
<input type="button" value=" 播    放 "  οnclick="repeatPlay();" id="play_button">  
<input type="button" value=" 停    止 "  οnclick="stopPlay();" id="stop_button">  
<input type="button" value=" 静    音 "  οnclick="noSound();" id="no_sound">  
<input type="button" value=" 减少音量 "  οnclick="soundChange(-10);">  
<input type="button" value=" 增大音量 "  οnclick="soundChange(10);">  
<input type="button" value=" 全    屏 "  οnclick="screenFull();">
    
                  
<font color="red" size="2">音量:</font><input type="text" id="vlc_sound" style="width: 40px;color: blue">
<br>
<font color="red" size="2">总时长:</font><input type="text" id="vedio_length" style="width: 65px;color: blue"> 
<input type="text" id="current_video_time" style="width: 65px;color: blue">
                    
           
<font color="red" size="2">跳转:</font><input type="text" id="change_length" style="width: 100px;color: blue">
<span style="color: blue;font-weight: normal;font-size: 14px">秒</span>
 
<input type="button" value="确定" id="time_change" disabled="disabled" οnclick="changeNewBeginTime();">
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在WinForm中嵌入VLC播放器可以通过以下步骤实现: 首先,你需要下载并安装VLC播放器到你的计算机上。确保安装的版本与你的WinForm项目兼容。 接下来,创建一个新的WinForm应用程序。打开Visual Studio并选择创建一个新的WinForm项目。 在你的WinForm设计窗口中,确保工具箱窗格是可见的。如果不可见,可以在视图菜单中选择工具箱。 在工具箱中找到“Elements”选项,并将其拖动到你的WinForm窗口上。这是嵌入VLC播放器所需要的控件。 在代码视图中,找到你的Form的构造函数,并在其中添加代码,将VLC控件添加到你的WinForm窗口上。 使用以下代码: ``` VlcControl vlcControl = new VlcControl(); this.Controls.Add(vlcControl); vlcControl.Dock = DockStyle.Fill; ``` 然后,你需要设置VLC播放器的路径。使用以下代码,将VLC播放器库的路径设置为你所安装的位置: ``` vlcControl.VlcLibDirectoryNeeded += (sender, args) => { vlcControl.VlcLibDirectory = new DirectoryInfo(@"VLC安装路径"); }; ``` 在以上代码中,将“VLC安装路径”替换为您所安装的VLC播放器的实际路径。 现在,你可以通过设置`vlcControl.Source`属性来加载媒体文件到VLC播放器中。例如: ``` vlcControl.Source = new Uri("媒体文件路径"); ``` 将“媒体文件路径”替换为你要加载的媒体文件的实际路径。 最后,编译并运行你的WinForm应用程序。现在,你的VLC播放器已成功嵌入到WinForm窗口中。 请注意,为了正确运行VLC播放器,你的计算机上必须安装有VLC播放器。如果其他用户在没有安装VLC的计算机上运行你的应用程序,他们需要自行安装VLC播放器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值