为所有浏览器嵌入 Windows Media Player

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:08:39  来源:igfitidea点击:

Embedding Windows Media Player for all browsers

windowsembedmedia

提问by Michael Stum

We are using WMVvideos on an internal site, and we are embedding them into web sites. This works quite well on Internet Explorer, but not on Firefox. I've found ways to make it work in Firefox, but then it stops working in Internet Explorer.

我们在内部网站上使用WMV视频,并将它们嵌入到网站中。这在 Internet Explorer 上非常有效,但在 Firefox 上则不然。我找到了让它在 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?

采纳答案by Grant

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>

回答by Jake McGraw

May I suggest the 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.

我可以推荐jQuery Media Plugin吗?为所有类型的视频提供嵌入代码,而不仅仅是 WMV 并进行浏览器检测,将所有杂乱的 switch/case 语句排除在模板之外。

回答by Jake McGraw

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)
        } 


        }

回答by Jim Nelson

Elizabeth Castro has an interesting article on this problem: Bye Bye Embed. Worth a read on how she attacked this problem, as well as handling QuickTime content.

Elizabeth Castro 有一篇关于这个问题的有趣文章:Bye Bye Embed。值得一读,了解她如何解决这个问题,以及如何处理 QuickTime 内容。

回答by Grant

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.

浏览器本身会忽略不适合他们阅读的代码。

回答by Polsonby

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. 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. See BBC's iPlayer for a superb example.

在 Web 上部署视频的最佳方法是使用 Flash - 将其干净地嵌入到网页中要容易得多,并且或多或少可以在任何浏览器和平台组合上播放。使用 Windows Media Player 的唯一原因是,如果您正在流式传输内容并且您需要非常强大的数字版权管理,即使这样,提供商现在也开始使用 Flash 来处理这些内容。请参阅 BBC 的 iPlayer 以获得极好的示例。

I would suggest that you switch to Flash even for internal use. You never know who is going to need to access it in the future, and this will give you the best possible future compatibility.

我建议您即使在内部使用时也切换到 Flash。您永远不知道将来谁需要访问它,这将为您提供最好的未来兼容性。

EDIT - March 20 2013. Interesting how these old questions resurface from time to time! 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

编辑 - 2013 年 3 月 20 日。有趣的是,这些旧问题是如何不时重新出现的!今天的世界是多么的不同,这一切似乎又是多么的陈旧。我今天无论如何都不会推荐仅使用 Flash 的路线 - 现在的最佳做法可能是使用 HTML 5 嵌入 H264 编码的视频,并使用此处所述的 Flash 回退:http: //diveintohtml5.info/video.html

回答by Peter Burns

Encoding flash video is actually very easy with ffmpeg. 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. Invoking it is easy:

使用 ffmpeg 编码 Flash 视频实际上非常容易。您可以使用一个命令从几乎任何视频格式进行转换,ffmpeg 足够聪明,可以解决其余问题,并且它将使用您机器上的每个处理器。调用它很容易:

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 500000is 500kbps for example. 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.

ffmpeg 会猜测你想要的比特率,但如果你想指定一个,你可以使用 -b 选项,-b 500000例如 500kbps。当然有很多选择,但我通常无需太多修改即可获得良好的结果。如果您正在寻找更多选项,这是一个很好的起点:视频选项

You don't need a special web server to show flash video. 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.

您不需要特殊的网络服务器来显示 Flash 视频。通过简单地将 .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. The player is even extremely skinnable and can be controlled with javascript.

如果您能确定您的所有用户将始终仅使用 [最近的、最新版本] Windows,WMV 就很好,但即便如此,Flash 通常更适合 Web。播放器甚至是非常可换肤的,并且可以使用 javascript 进行控制。

回答by Perseus

I found a good article about using the WMP with Firefoxon 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.readyinstead of window load eventto 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 测试了代码。

回答by Vonzy

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 的版本