简体   繁体   English

为所有浏览器嵌入 Windows Media Player

[英]Embedding Windows Media Player for all browsers

Edit: This question was written in 2008, which was like 3 internet ages ago.编辑:这个问题是在 2008 年写的,就像 3 年前的互联网。 If this question is still relevant to your environment, please accept my condolences.如果这个问题仍然与您的环境相关,请接受我的哀悼。 Everyone else should convert into a format supported by your browsers (That would be H.264 if Internet Explorer is needed, and probably AV1, VP8/VP9 if not) and use the<video> element .其他所有人都应该转换为您的浏览器支持的格式(如果需要 Internet Explorer,则为 H.264,如果不需要,则可能为 AV1、VP8/VP9)并使用<video>元素


We are using WMV videos on an internal site, and we are embedding them into web sites.我们在内部网站上使用WMV视频,并将它们嵌入到网站中。 This works quite well on Internet Explorer, but not on Firefox.这在 Internet Explorer 上非常有效,但在 Firefox 上则不然。 I've found ways to make it work in Firefox, but then it stops working in Internet Explorer.我找到了让它在 Firefox 中工作的方法,但随后它在 Internet Explorer 中停止工作。

We do not want to use Silverlight just yet, especially since we cannot be sure that all clients will be running Windows XP with Windows Media Player installed.我们暂时还不想使用 Silverlight,特别是因为我们不能确定所有客户端都将运行安装了 Windows Media Player 的 Windows XP。

Is there some sort of Universal Code that embeds WMP into both Internet Explorer and Firefox, or do we need to implement some user-agent-detection and deliver different HTML for different browsers?是否有某种通用代码可以将 WMP 嵌入到 Internet Explorer 和 Firefox 中,或者我们是否需要实现一些用户代理检测并为不同的浏览器提供不同的 HTML?

The following works for me in Firefox and Internet Explorer:以下在 Firefox 和 Internet Explorer 中对我有用:

<object id="mediaplayer" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701" standby="loading microsoft windows media player components..." type="application/x-oleobject" width="320" height="310">
<param name="filename" value="./test.wmv">
     <param name="animationatstart" value="true">
     <param name="transparentatstart" value="true">
     <param name="autostart" value="true">
     <param name="showcontrols" value="true">
     <param name="ShowStatusBar" value="true">
     <param name="windowlessvideo" value="true">
     <embed src="./test.wmv" autostart="true" showcontrols="true" showstatusbar="1" bgcolor="white" width="320" height="310">
</object>

May I suggest the jQuery Media Plugin ?我可以推荐jQuery Media Plugin吗? Provides embed code for all kinds of video, not just WMV and does browser detection, keeping all that messy switch/case statements out of your templates.为所有类型的视频提供嵌入代码,而不仅仅是 WMV 并进行浏览器检测,将所有杂乱的 switch/case 语句排除在模板之外。

Use the following.使用以下内容。 It works in Firefox and Internet Explorer.它适用于 Firefox 和 Internet Explorer。

        <object id="MediaPlayer1" width="690" height="500" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
            codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
            standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject"
            >
            <param name="FileName" value='<%= GetSource() %>' />
            <param name="AutoStart" value="True" />
            <param name="DefaultFrame" value="mainFrame" />
            <param name="ShowStatusBar" value="0" />
            <param name="ShowPositionControls" value="0" />
            <param name="showcontrols" value="0" />
            <param name="ShowAudioControls" value="0" />
            <param name="ShowTracker" value="0" />
            <param name="EnablePositionControls" value="0" />


            <!-- BEGIN PLUG-IN HTML FOR FIREFOX-->
            <embed  type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
                src='<%= GetSource() %>' align="middle" width="600" height="500" defaultframe="rightFrame"
                 id="MediaPlayer2" />

And in JavaScript,在 JavaScript 中,

    function playVideo() {
        try{
                if(-1 != navigator.userAgent.indexOf("MSIE"))
                {
                        var obj = document.getElementById("MediaPlayer1");
                            obj.Play();

                }
                else
                {
                            var player = document.getElementById("MediaPlayer2");
                            player.controls.play();

                }
             }  
        catch(error) {
            alert(error)
        } 


        }

Elizabeth Castro has an interesting article on this problem: Bye Bye Embed . Elizabeth Castro 有一篇关于这个问题的有趣文章: Bye Bye Embed Worth a read on how she attacked this problem, as well as handling QuickTime content.值得一读,了解她如何解决这个问题,以及如何处理 QuickTime 内容。

You could use conditional comments to get IE and Firefox to do different things你可以使用条件注释让 IE 和 Firefox 做不同的事情

<![if !IE]>
<p> Firefox only code</p>
<![endif]>

<!--[if IE]>
<p>Internet Explorer only code</p>
<![endif]-->

The browsers themselves will ignore code that isn't meant for them to read.浏览器本身会忽略不适合他们阅读的代码。

The best way to deploy video on the web is using Flash - it's much easier to embed cleanly into a web page and will play on more or less any browser and platform combination.在 Web 上部署视频的最佳方法是使用 Flash - 将其干净地嵌入到网页中要容易得多,并且或多或少可以在任何浏览器和平台组合上播放。 The only reason to use Windows Media Player is if you're streaming content and you need extraordinarily strong digital rights management, and even then providers are now starting to use Flash even for these.使用 Windows Media Player 的唯一原因是,如果您正在流式传输内容并且需要非常强大的数字版权管理,即使如此,提供商现在也开始使用 Flash,即使是这些。 See BBC's iPlayer for a superb example.请参阅 BBC 的 iPlayer 以获得极好的示例。

I would suggest that you switch to Flash even for internal use.我建议您即使在内部使用时也切换到 Flash。 You never know who is going to need to access it in the future, and this will give you the best possible future compatibility.您永远不知道将来谁需要访问它,这将为您提供最好的未来兼容性。

EDIT - March 20 2013. Interesting how these old questions resurface from time to time!编辑 - 2013 年 3 月 20 日。有趣的是,这些旧问题是如何不时重新出现的! How different the world is today and how dated this all seems.今天的世界是多么的不同,这一切似乎又是多么的陈旧。 I would not recommend a Flash only route today by any means - best practice these days would probably be to use HTML 5 to embed H264 encoded video, with a Flash fallback as described here: http://diveintohtml5.info/video.html我今天无论如何都不会推荐仅使用 Flash 的路线 - 如今的最佳实践可能是使用 HTML 5 嵌入 H264 编码的视频,并使用此处所述的 Flash 回退: http : //diveintohtml5.info/video.html

I found a good article about using the WMP with Firefox on MSDN.我在 MSDN 上找到了一篇关于在 Firefox 中使用 WMP的好文章。

Based on MSDN's article and after doing some trials and errors, I found using JavaScript is better than using conditional comments or nested "EMBED/OBJECT" tags.根据 MSDN 的文章,经过一些试验和错误,我发现使用 JavaScript 比使用条件注释或嵌套的“EMBED/OBJECT”标签更好。

I made a JS function that generate WMP object based on given arguments:我制作了一个基于给定参数生成 WMP 对象的 JS 函数:

<script type="text/javascript">
    function generateWindowsMediaPlayer(
        holderId,   // String
        height,     // Number
        width,      // Number
        videoUrl    // String
        // you can declare more arguments for more flexibility
        ) {
        var holder = document.getElementById(holderId);

        var player = '<object ';
        player += 'height="' + height.toString() + '" ';
        player += 'width="' + width.toString() + '" ';

        videoUrl = encodeURI(videoUrl); // Encode for special characters

        if (navigator.userAgent.indexOf("MSIE") < 0) {
            // Chrome, Firefox, Opera, Safari
            //player += 'type="application/x-ms-wmp" '; //Old Edition
            player += 'type="video/x-ms-wmp" '; //New Edition, suggested by MNRSullivan (Read Comments)
            player += 'data="' + videoUrl + '" >';
        }
        else {
            // Internet Explorer
            player += 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" >';
            player += '<param name="url" value="' + videoUrl + '" />';
        }

        player += '<param name="autoStart" value="false" />';
        player += '<param name="playCount" value="1" />';
        player += '</object>';

        holder.innerHTML = player;
    }
</script>

Then I used that function by writing some markups and inline JS like these:然后我通过编写一些标记和内联 JS 来使用该函数,如下所示:

<div id='wmpHolder'></div>

<script type="text/javascript">        
    window.addEventListener('load', generateWindowsMediaPlayer('wmpHolder', 240, 320, 'http://mysite.com/path/video.ext'));
</script>

You can use jQuery.ready instead of window load event to making the codes more backward-compatible and cross-browser.您可以使用jQuery.ready代替窗口加载事件来使代码向后兼容和跨浏览器。

I tested the codes over IE 9-10, Chrome 27, Firefox 21, Opera 12 and Safari 5, on Windows 7/8.我在 Windows 7/8 上通过 IE 9-10、Chrome 27、Firefox 21、Opera 12 和 Safari 5 测试了代码。

Encoding flash video is actually very easy with ffmpeg.使用 ffmpeg 编码 Flash 视频实际上非常容易。 You can use one command to convert from just about any video format, ffmpeg is smart enough to figure the rest out, and it'll use every processor on your machine.您可以使用一个命令从几乎任何视频格式进行转换,ffmpeg 足够聪明,可以解决其余问题,并且它将使用您机器上的每个处理器。 Invoking it is easy:调用它很容易:

ffmpeg -i input.avi output.flv

ffmpeg will guess at the bitrate you want, but if you'd like to specify one, you can use the -b option, so -b 500000 is 500kbps for example. ffmpeg 会猜测你想要的比特率,但如果你想指定一个,你可以使用 -b 选项,例如-b 500000是 500kbps。 There's a ton of options of course, but I generally get good results without much tinkering.当然有很多选择,但我通常无需太多修改即可获得良好的结果。 This is a good place to start if you're looking for more options: video options .如果您正在寻找更多选项,这是一个很好的起点:视频选项

You don't need a special web server to show flash video.您不需要特殊的网络服务器来显示 Flash 视频。 I've done just fine by simply pushing .flv files up to a standard web server, and linking to them with a good swf player, like flowplayer .通过简单地将 .flv 文件推送到标准 Web 服务器,并使用一个好的 swf 播放器(例如flowplayer )链接到它们,我已经做得很好了。

WMVs are fine if you can be sure that all of your users will always use [a recent, up to date version of] Windows only, but even then, Flash is often a better fit for the web.如果您可以确定所有用户将始终仅使用 [最近的、最新版本] Windows,WMV 就很好,但即便如此,Flash 通常更适合 Web。 The player is even extremely skinnable and can be controlled with javascript.播放器甚至是非常可换肤的,并且可以使用 javascript 进行控制。

I have found something that Actually works in both FireFox and IE, on Elizabeth Castro's site (thanks to the link on this site) - I have tried all other versions here, but could not make them work in both the browsers我在 Elizabeth Castro 的网站上发现了一些实际上在 FireFox 和 IE 中都有效的东西(感谢这个网站上的链接)——我在这里尝试了所有其他版本,但无法让它们在两种浏览器中都能正常工作

<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" 
  id="player" width="320" height="260">
  <param name="url" 
    value="http://www.sarahsnotecards.com/catalunyalive/fishstore.wmv" />
  <param name="src" 
    value="http://www.sarahsnotecards.com/catalunyalive/fishstore.wmv" />
  <param name="showcontrols" value="true" />
  <param name="autostart" value="true" />
  <!--[if !IE]>-->
  <object type="video/x-ms-wmv" 
    data="http://www.sarahsnotecards.com/catalunyalive/fishstore.wmv" 
    width="320" height="260">
    <param name="src" 
      value="http://www.sarahsnotecards.com/catalunyalive/fishstore.wmv" />
    <param name="autostart" value="true" />
    <param name="controller" value="true" />
  </object>
  <!--<![endif]-->
</object>

Check her site out: http://www.alistapart.com/articles/byebyeembed/ and the version with the classid in the initial object tag查看她的网站: http : //www.alistapart.com/articles/byebyeembed/以及初始对象标签中带有 classid 的版本

December 2020 : 2020 年 12 月:

  • We have now Firefox 83.0 and Chrome 87.0我们现在有 Firefox 83.0 和 Chrome 87.0
  • Internet Explorer is dead, it has been replaced by the new Chromium-based Edge 87.0 Internet Explorer 已死,已被新的基于 Chromium 的 Edge 87.0 取代
  • Silverlight is dead银光死了
  • Windows XP is dead Windows XP 已死
  • WMV is not a standard : https://www.w3schools.com/html/html_media.asp WMV 不是标准: https : //www.w3schools.com/html/html_media.asp

To answer the question :回答这个问题:

  • You have to convert your WMV file to another format : MP4, WebM or Ogg video.您必须将 WMV 文件转换为另一种格式:MP4、WebM 或 Ogg 视频。
  • Then embed it in your page with the HTML 5 <video> element .然后使用HTML 5 <video>元素将其嵌入到您的页面中。

I think this question should be closed.我认为这个问题应该关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM