Embedding Windows Media Player for all browsers

前端 未结 9 485
盖世英雄少女心
盖世英雄少女心 2020-12-01 03:55

We are using WMV videos 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 ma

相关标签:
9条回答
  • 2020-12-01 04:33

    The following works for me in Firefox and 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>
    
    0 讨论(0)
  • 2020-12-01 04:36

    I found a good article about using the WMP with Firefox on MSDN.

    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.

    I made a JS function that generate WMP object based on given arguments:

    <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:

    <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.

    I tested the codes over IE 9-10, Chrome 27, Firefox 21, Opera 12 and Safari 5, on Windows 7/8.

    0 讨论(0)
  • 2020-12-01 04:39

    You could use conditional comments to get IE and Firefox to do different things

    <![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.

    0 讨论(0)
  • 2020-12-01 04:42

    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 -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. 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. 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.

    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.

    0 讨论(0)
  • 2020-12-01 04:49

    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.

    0 讨论(0)
  • 2020-12-01 04:51

    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.

    0 讨论(0)
提交回复
热议问题