最有效的在网页上播放 Rtsp 流的插件,具有良好的浏览器兼容性

发布于 2024-11-10 18:02:13 字数 2362 浏览 1 评论 0原文

这是我的代码的概述。 用户按下录制按钮,它会触发服务器启动监控流,并返回一个我想在网站上播放的 rtsp url。

我尝试过 vlc 插件,但它似乎不可靠,以下代码会产生后面提到的问题。

任何其他实现此功能的想法都非常受欢迎。

  xmlhttp.onreadystatechange  = function()
    {
     if (xmlhttp.readyState == 4) {
       if(xmlhttp.status == 200) {
         res_array = xmlhttp.responseText.split("#");
         session_id = res_array[0];
        alert(res_array.length);
         if (res_array.length == 4)
         {
             document.getElementById("jsession").innerHTML = xmlhttp.responseText;
             rstp_url = res_array[1];
             jsession_id = res_array[2];
             var vid_tag = '<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"';
             vid_tag += ' codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"' ;
             vid_tag += ' width="320" height="240" id="vlc" events="True"> <param name="Src" value=" ' + rstp_url +' " /> ';
             vid_tag += ' <param name="ShowDisplay" value="True" /> <param name="AutoLoop" value="False" /><param name="AutoPlay" value="True" />' ;
             vid_tag += '<EMBED pluginspage="http://www.videolan.org" type="application/x-vlc-plugin" progid="VideoLAN.VLCPlugin.2" width="320" height="240"' ;
             vid_tag +=' autoplay="yes" loop="no" target="'+rstp_url+'" name="vlc"> </EMBED></OBJECT>';
             document.getElementById("StopRecording").disabled = false;
             document.getElementById("StartRecording").disabled = true;
             document.getElementById("StopPlayback").visible = false;
             document.getElementById("Playback").disabled = true;
             alert(vid_tag);
             document.getElementById("video_handler").innerHTML = vid_tag;
             document.getElementById("jsession").innerHTML = xmlhttp.responseText;//Update the HTML Form element
         }
         else
            {
             alert("Make sure usename,password and deviceref is correct");
            }
       }
       else {
          alert("Error during AJAX call. Please try again");
       }
     }
};

这些是我遇到的以下问题。

  • 不能在 IE6 中工作。
  • 流媒体播放不可靠。有时播放有时不播放。解决此问题的唯一正确方法似乎是在 res_array 长度之后添加一个警告框,如果选中
  • 即使尝试播放音频源,也会出现一个用于播放视频的黑框。

PS 如果我尝试使用 HTML5 并且我了解 jquery 等框架,那么这会变得更容易吗?但我不可能在这个项目中使用它。

Here is a overview of my code.
User press a record button and it hits the server to start a surveillance stream,and it returns a rtsp url which I want to play on the website.

I have tried vlc plugin, but it seems to be unreliable the following code creates the after-mentioned problems.

Any other ideas to implement this functionality is more than welcome.

  xmlhttp.onreadystatechange  = function()
    {
     if (xmlhttp.readyState == 4) {
       if(xmlhttp.status == 200) {
         res_array = xmlhttp.responseText.split("#");
         session_id = res_array[0];
        alert(res_array.length);
         if (res_array.length == 4)
         {
             document.getElementById("jsession").innerHTML = xmlhttp.responseText;
             rstp_url = res_array[1];
             jsession_id = res_array[2];
             var vid_tag = '<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"';
             vid_tag += ' codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"' ;
             vid_tag += ' width="320" height="240" id="vlc" events="True"> <param name="Src" value=" ' + rstp_url +' " /> ';
             vid_tag += ' <param name="ShowDisplay" value="True" /> <param name="AutoLoop" value="False" /><param name="AutoPlay" value="True" />' ;
             vid_tag += '<EMBED pluginspage="http://www.videolan.org" type="application/x-vlc-plugin" progid="VideoLAN.VLCPlugin.2" width="320" height="240"' ;
             vid_tag +=' autoplay="yes" loop="no" target="'+rstp_url+'" name="vlc"> </EMBED></OBJECT>';
             document.getElementById("StopRecording").disabled = false;
             document.getElementById("StartRecording").disabled = true;
             document.getElementById("StopPlayback").visible = false;
             document.getElementById("Playback").disabled = true;
             alert(vid_tag);
             document.getElementById("video_handler").innerHTML = vid_tag;
             document.getElementById("jsession").innerHTML = xmlhttp.responseText;//Update the HTML Form element
         }
         else
            {
             alert("Make sure usename,password and deviceref is correct");
            }
       }
       else {
          alert("Error during AJAX call. Please try again");
       }
     }
};

These are the following problems I have.

  • Not working in IE6.
  • The stream playing is unreliable. It sometime plays and sometimes doesnt. The only proper way of fixing this seems to be adding a alert box just after the res_array length if check
  • Even if try to play a audio source,a black box for playing a video appears.

P.S. Would this get any easier if I try using HTML5 and I know about frameworks such as jquery, but it is not possible for me to use it in this project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鯉魚旗 2024-11-17 18:02:13

由于您没有提到操作系统:
另一个仅限 Windows 的选项是编写您自己的 RTSP DirectShow 源过滤器。然后可以为 RTSP 协议注册这样的过滤器。在网页上,您可以通过以下方式插入:

<div id="mtvPlayer"> 
    <embed 
        type="application/x-mplayer2" 
        pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" 
        name="mediaplayer1" 
        ShowStatusBar="true" 
        EnableContextMenu="false" 
        autostart="true" 
        loop="false" 
        src="rtsp://<<RTSP URI>>" 
        width="352px"
        height="288px"
    /> 
</div> 

如果过滤器注册正确,则会自动加载 RTSP 源过滤器并构建适当的媒体管道。这是我使用过的方法,它适用于 IE8、chrome 和 firefox。我没有用IE6测试过。无论如何,谁仍然使用该浏览器 :P

这种方法的缺点是工作量很大(而且很复杂),或者至少您需要一些扎实的 DirectShow 经验来实现过滤器并满足不同的媒体类型。

Since you don't mention OS:
Another windows-only option is to write your own RTSP DirectShow source filter. Such a filter can then be registered for the RTSP protocol. On the webpage you can insert it via:

<div id="mtvPlayer"> 
    <embed 
        type="application/x-mplayer2" 
        pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" 
        name="mediaplayer1" 
        ShowStatusBar="true" 
        EnableContextMenu="false" 
        autostart="true" 
        loop="false" 
        src="rtsp://<<RTSP URI>>" 
        width="352px"
        height="288px"
    /> 
</div> 

If the filter is registered correctly, the RTSP source filter is automatically loaded and an appropriate media pipeline is constructed. This is the approach I've used and it works on IE8, chrome and firefox. I have not tested it with IE6. Who still uses that browser anyway :P

The downside of this approach is that it's quite a bit of work (and complex), or at least you need some solid DirectShow experience to implement the filter and cater for different media types.

ぽ尐不点ル 2024-11-17 18:02:13

如果我没看错的话,听起来它总是显示流,但并不总是自动播放,对吗?我猜想这是一个时间问题,对象在对象完全写入页面之前尝试自动播放。如果是这种情况,设置 autoplay=false 然后在创建对象后调用 controlname.play 可以解决问题吗?

If I'm reading this correctly, it sounds like it's always displaying the stream, but not always auto-playing, correct? I would guess it's a timing issue where the object is trying to autoplay before the object it fully written to the page. If that's the case, would setting autoplay=false and then calling a controlname.play after creating the object fix the issue?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文