Adding mime types (must know)

Now that we have set up the basic video code, it is time to try playing the video—in some circumstances, you may find that browsers will not play videos correctly if it can't determine the mime type to use. In this task, we implement an easy change to rectify this and allow videos to play correctly.

Note

Multi-Purpose Mail Extension (MIME) types are made up of two parts—a type and a subtype—and are means to help define file types so that a client PC can correctly interpret how to treat a file received from a server via the Internet. For example, the HTML5 video formats used in this book have the type of video, but the subtypes could be .ogg, .mp4, or .webm.

Getting ready

For this task, we don't need anything except your text editor.

How to do it...

  1. Crank up your favourite text editor and create a new text document. Save it as .htaccess into the root folder of your website.

    Tip

    You may want to use quotes around the filename when saving it; this forces your text editor to save it as that filename.

  2. Add the following text and save the file:
    AddType video/ogg .ogv
    AddType video/mp4 .mp4
    AddType video/webm .webm
  3. Try playing the video now—hopefully, you may find nothing has changed, and that the video still continues to play. The change you've made now ensures that anyone playing the video will be able to play it properly depending on which browser they use.

How it works...

In most instances, browsers will usually play the right video. However, the HTTP protocol doesn't know the concept of file extensions—this means you cannot rely on a browser being able to play the right video all of the time. To get around this, we add in this small configuration change, so that the browser is able to correctly determine the file format from the extension and play the video.

There's more...

As you will see later in this section, when we adapt the video code for use with other platforms, some platforms don't like the use of the type command within the video code. Using an .htaccess file may not appeal to some, but is a useful way to get around this issue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset