Blog

Tagged by 'chrome'

  • Published on
    -
    1 min read

    Autoplaying HTML5 Video In Chrome

    Whilst working on the new look for my website, I wanted to replace areas where I previously used low-grade animated GIF's for the more modern HTML5 video. Currently, the only place I use HTML5 video is on my 404 page as a light-hearted reference to one of the many memorable quotes that only fans of the early Star Trek films will understand. These are the films I still hold in very high regard, something the recent "kelvin timeline" films are missing. Anyway, back to the post in hand...

    Based on Chrome's new policies introduced in April 2018 I was always under the impression that as long as the video is muted, this won't hinder in any way the autoplay functionality. But for the life of me, mt HTML5 video did not autoplay, even though all worked as intended in other browsers such as Firefox.

    You can work around Chrome's restrictions through JavaScript.

    Code

    The HTML is as simple as adding your HTML5 video.

    <video id="my-video" autoplay muted loop playsinline>
         <source src="/enterprise-destruction.mp4" type="video/mp4" />
    </video>
    

    All we need to do is target our video and tell it to play automatically. I have added a timeout to the script just to ensure the video has enough time to render on the page before our script can do its thing.

    var myVideo = $("#my-video");
    
    setTimeout(function () {
        myVideo.muted = true;
        myVideo.play();
    }, 100);
    

    It's worth noting that I don't generally write much about front-end approaches (excluding JavaScript) as I am first and foremost a backend developer. So this might not be the most ideal solution and appreciate any feedback.

  • My Nexus 5 upgraded to Android version 5.0 a few months back and it's by far the best update yet (apart from the minor bugs). An OS that is as beautiful to look at as well as use.

    One of the most intriguing things I noticed was that the colour of my Chrome browser address bar would occasionally change if I went certain websites. Being a developer who works in the web industry, this peaked my interest. So I had to find out how to do this.

    After doing some online research, I found adding the this feature couldn't be simpler. Just add the following META tag to your page:

    <meta name="theme-color" content="#4c7a9f">
    

    I carried out this change on my site and it looks kinda cool!

    Before
    Android Chrome Browser Colour (Before)
    After
    Android Chrome Browser Colour (After)
  • It seems there is going to be a growing trend where apps on our mobile devices will open webpages whilst you are inside the app itself instead of using the devices' native browser. A prime example of this is Facebook. In recent updates during the tail end of last year, both their iOS and Android offerings open webpages from within the application.

    This isn't a bad thing. In fact I quite like having webpages opening within the application, since this creates a nice seamless experience. However, the Facebook in-app browser doesn't seem to render a webpage in the same manner as the devices' own native browser (Safari/Chrome). I started noticing this whilst working on a complex website that was very much custom JavaScript driven.

    The only thing I could do is modify specific mark-up or features that affected my website negatively when opened from within Facebook by detecting the user-agent. In my code (using ASP.NET C#), I was required to carry out additional browser checks:

    //User is within Facebook browser.
    if (Request.UserAgent.IndexOf("FBAN") > -1)
    {
        if (Request.UserAgent.Contains("iPhone OS 8_0_2"))
        {
            //You are using iPhone version 8.0.2.
        }
        
        if (Request.UserAgent.Contains("Chrome"))
        {
            //You are in the Facebook App in Android.
        }
    }
    else
    {
        //You are not in Facebook App.
    }
    

    You can modify the code above to create a nice self-contained method to return an enumeration as I ended up doing to be used when required.