-1

I been playing around with the HTML5 and I seem to be have trouble getting the video to play well across all browsers. IE supports HTML5 video but when the video is playing a green transparent background is covering the video. If you didn't know that play this video on your IE browser. Here is a Imgur screenshot, IE11.

enter image description here

So my way around it is I converted the video to a SWF file and implemented the script below

<?php 
      if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT'])) {?>
      <div id="flashContent">
              <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="100%" id="flow" align="middle" style="">
                <param name="movie" value="/index.files/Flow_Double_Size_v01.swf" />
                <param name="quality" value="high" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="transparent" />
                <param name="scale" value="noscale" />
                <param name="menu" value="false" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="sameDomain" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="/index.files/Flow_Double_Size_v01.swf" width="100%" height="100%">
      <param name="movie" value="/index.files/Flow_Double_Size_v01.swf" />
            <param name="quality" value="high" />
            <param name="play" value="true" />
            <param name="loop" value="true" />
            <param name="wmode" value="transparent" />
            <param name="scale" value="noscale" />
            <param name="menu" value="false" />
            <param name="devicefont" value="false" />
            <param name="salign" value="" />
            <param name="allowScriptAccess" value="sameDomain" />
          <!--<![endif]-->
            <a href="http://www.adobe.com/go/getflash">
              <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
            </a>
          <!--[if !IE]>-->
          </object>
          <!--<![endif]-->
        </object>
      </div>
      <?php }else{  ?>
        <div class="video-container">
          <video autoplay="autoplay" loop class="bg-1">
            <source src="/index.files/html5video/Flow_Updates_MP4_Codec_v02.m4v" type="video/mp4">
            <source src="/index.files/html5video/Flow_Updates_MP4_Codec_v02.ogv" type="video/ogg">
            <source src="/index.files/html5video/Flow_Updates_MP4_Codec_v02.webm" type="video/webm">
          </video>
        </div>
      <?php }; ?>

So the issues I'm running into is every now and then the flash player won't be interpreted by IE and it'll just play nothing, one day it's playing the next its not. I would clear the cache and tested this on our clients computer to see if they are running a flash blocker and they are not. When I viewd the source with the developer tools on IE that's when I realized the conditional statement isn't even read.

I got the PHP script from CSS Tricks I also updated the script that I found in the comments with if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT'])) { }

If there's an alternative to this I would appreciate. I have also tried the fallback version for the HTML5 player with the flash embed but IE does not seem to fall back to it. I need IE to specically play the SWF file.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
Jose Gomez
  • 43
  • 10
  • In both cases you are relying on the honesty of the browser to report itself to your code. With JS you can check if a particular functionality is available within the JS engine. I'll try to find some resources. – MonkeyZeus Jan 16 '14 at 21:55
  • http://stackoverflow.com/a/1042154/2191572 and make sure to check out the comment with 50+ votes or http://css-tricks.com/snippets/javascript/check-if-function-exists-before-calling/ – MonkeyZeus Jan 16 '14 at 21:56
  • @MonkeyZeus How about using Modernizr? That's generally pretty handy for detecting browser functionality, and you can trim it down to only include what you need. Agree in general, though - detecting functionality rather than checking for a specific browser is the best approach. – Matthew Daly Jan 16 '14 at 21:58
  • @MonkeyZeus Thanks. I'll give it a try and report back. – Jose Gomez Jan 16 '14 at 22:02
  • You're welcome, if you think about it then it's actually a benefit and not a crutch because it allows for both Javascript to be browser-agnostic and server-side languages to be browser agnostic as well. Heck a server can make a call to a PHP script on the back-end. Think about RSS feeds and xml feeds for phone apps which connect to servers to get info. Good luck! – MonkeyZeus Jan 16 '14 at 22:06
  • The green screen could be the result of how the browser calls upon the rendering power of your graphics card to play the video. – MonkeyZeus Jan 16 '14 at 22:11
  • @MonkeyZeus If it's because I'm using a virtual machine that totally bombs. I don't have a true windows machine to test it so as I was testing it and didnt see it playing, I was afraid that the client might not be able to as well. Which was why I created this. I'll have to test this later tonight. Thanks again. – Jose Gomez Jan 16 '14 at 22:51
  • 1
    Oh wow I didn't even consider that you might be using a VM, needle-in-a-haystack I guess lol. I tested it in all my available browsers: IE 10+11, FF, and Chrome and they all work flawlessly so I hope it's just a VM issue otherwise the developers of IE 11 made a big mistake somewhere – MonkeyZeus Jan 17 '14 at 00:30
  • I'm fairly certain it's going to be because you're using a VM, but would you mind keeping us updated? Other answers have suggested that turning off hardware acceleration for the graphic card in the VM takes care of it. – Matt McClure Jan 22 '14 at 17:14
  • @MattMcClure Sorry I haven't had time to test out these solutions, another priority has come up with this project but I will come back and try them before the launch. As for the turning of the hardware acceleration on the VM that option is not allowed for me. IT is preventing me to turn it off. – Jose Gomez Jan 29 '14 at 17:53
  • The video demo provided at `VideoJS` owrked flawless in my IE11 Windows 7 64bit. – Vitor Canova Feb 07 '14 at 15:36
  • I found out the video plays well in the newer versions of IE. I haven't found a true Windows OS with IE9. I had gone over to the clients building and tested the mp4 file w/ fallback versions on their environment. I don't think video is supported on IE8 which was what I was looking for so I had a flash fallback for it. – Jose Gomez Feb 20 '14 at 19:31

3 Answers3

0

I mentioned this in the comments, but sniffing a particular browser is always going to be painful. I understand IE11 has made some changes to the user agent string as well, so MSIE no longer appears in it (source - http://www.sitepoint.com/internet-explorer-11-review/), which is probably the source of your problem.

A better approach is to detect specific functionality. Modernizr is a really great library for that, and is fairly easy to use. For instance, detecting h264 support might involve something like this:

if (Modernizr.video.h264 === false) {
    // Do stuff
}

Detecting video support seems to be a bit weird - Chrome returns "probably" for the code above, so I would ensure you do some cross-browser testing.

You can also create your own build of Modernizr including just the functionality you need, so it need not be that heavy.

EDIT: If you need to detect it in PHP, then you can search in the user agent string for "Trident". I believe that should work. However, I would always avoid browser sniffing unless absolutely necessary because you never know what future browsers will be like.

Matthew Daly
  • 9,212
  • 2
  • 42
  • 83
  • Well I figured that string of php was the cause since the article I got it from dates back 2-3 years ago. I will gather everyone input later tonight and see which one works best. Thanks again! – Jose Gomez Jan 16 '14 at 23:02
  • Also, our client is a corporate company and this website I'm building is for their internal employees which all of them are using Windows vista on IE8. Bummer :( – Jose Gomez Jan 16 '14 at 23:04
  • Ouch! I feel your pain :-( – Matthew Daly Jan 16 '14 at 23:09
  • As I've mentioned elsewhere, most of the traditional methods of detecting IE no longer work. IE10 abolished conditional comments, while IE 11 changed navigator.appName to "Netscape" and removed "MSIE" from the user agent screen. The only way I can think of that you could detect IE would be by searching for "Trident" in the user agent string. That said, browser sniffing is frowned upon - where possible, feature detection is a much better approach. – Matthew Daly Jan 16 '14 at 23:12
  • Have updated my answer to include detecting it in PHP. – Matthew Daly Jan 16 '14 at 23:15
0

I would recommend you not to avoid totally IE, since newest versions can play HTML5 video. I think would be better if you check the compatibility of the user browser if it can play html5 videos.

http://html5test.com/compare/browser/ie-10/ie-11.html

But If you don't want a huge library just to detect the browser, the code below my help you.

Approach A - vendor name:

var ie = (navigator.appName === 'Microsoft Internet Explorer') === true;

Approach B - regexp:

var ie =  (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) === true;

Approach C - conditional code (https://gist.github.com/padolsey/527683):

var ie = (function(){

    var undef,
        v = 3,
        div = document.createElement('div'),
        all = div.getElementsByTagName('i');

    while (
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
        all[0]
    );

    return v > 4 ? v : undef;
}());

Hope one of the suggestions may help you. If not, hope you'll find the best way to do so.

Good luck.

  • Sorry, but A and B definitely won't work. navigator.appName apparently returns "Netscape" in IE11, and MSIE doesn't appear in the user agent string. You could possibly search for "Trident", however. – Matthew Daly Jan 16 '14 at 23:00
  • Also, I don't think C will work in IE 10 or greater either - IE10 abolished conditional comments – Matthew Daly Jan 16 '14 at 23:21
0

Detecting Internet Explorer may not be necessary at all in this case, as the problem appears to be with this particular video file. IE can play most mp4 videos, but it occasionally fails if it doesn't like the way a video is encoded. If you're just experimenting, it is likely that when you use your own video, it will work just fine.

If that is not the case and either you're dead set on using this video file or you have the same problems with your own, I recommend playing with different encoding settings. ffmpeg is usually pretty good, and you can start with a command like this:

ffmpeg -i INPUTFILE -b 1500k -vcodec libx264 -vpre slow -vpre baseline -g 30 "OUTPUTFILE.mp4"

Have a look at the documentation and try a few different bit rates and presets. In the meantime I'll try to give videojs a heads-up that their video isn't working in IE and see if they can fix it.

Now, if you still can't solve the problem, the best way to detect a browser is on the client, since the user agent string can be changed. 99% of the time, you want to do feature detection, but when you're working around a browser-specific bug like this, browser detection is okay.

You can detect Internet Explorer by looking for document.documentMode. It's a value that IE gives you to tell you if it's running in compatibility mode. Other browsers don't have this property, so you can detect IE like this:

var isIE = 'documentMode' in document;
Community
  • 1
  • 1
brianchirls
  • 7,661
  • 1
  • 32
  • 32
  • FYI, Conditional comments no longer work with effect from IE10 – Matthew Daly Jan 22 '14 at 14:04
  • I stand corrected. Don't do it that way. http://msdn.microsoft.com/en-us/library/ie/hh801214%28v=vs.85%29.aspx – brianchirls Jan 22 '14 at 15:31
  • No response on twitter. https://twitter.com/bchirls/status/424211441147588608 Issue filed. https://github.com/videojs/videojs.com/issues/12 – brianchirls Jan 22 '14 at 15:40
  • The [other stack overflow question](http://stackoverflow.com/questions/17880189/videojs-in-ie10-shows-green-video) you linked to was the issue here too. The OP said he's only testing in a VM. – Matt McClure Jan 22 '14 at 17:03
  • I see that in the fine print now, thanks. Cursory googling seems to indicate it's a problem with hardware decoding of mp4. But I'm curious to see if it happens with all mp4 files or if it's specific to certain encode characteristics. – brianchirls Jan 22 '14 at 22:11