Building An HTML5 Video Player With Custom Controls
Building An HTML5 Video Player With Custom Controls
Custom Controls
Contents
- Introduction 1
- HTML5 video player 4
- Packaged HTML5 video players 7
- Integration with other video platforms 8
- Mobile challenges 10
- Glossary 12
HTML5 video player is technically a component built into HTML5 browsers. As of now, the key
concern was the split support for video codecs, but now all modern browsers support the H.264
standard. However, the look and feel of the video controls is not consistent across all the browsers.
The snapshot below certifies this point since we can see the same webpage in IE, Chrome and Firefox
having same options but a different UI.
How it works:
The HTML5 video tag contains two key attributes, ‘src’ and ‘controls’. The ‘src’ attribute holds the
URL which points to the video which is hosted on the web. Therefore, the control features decides
the visibility/appearance of the on-board/default video player controls. In this, the source of the
video tag which is present holds the URL - http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4’
The video tag supports three video formats which include - MP4, OGG and WebM. Out of these tags,
MP4 is the most widely supported format by all modern HTML5 browsers.
• MP4: MPEG 4 files with H264 video codec and AAC audio codec
• Ogg: Ogg files with Theora video codec and Vorbis audio codec
• WebM: WebM files with VP8 video codec and Vorbis audio codec
In order to support different formats in the video tag, we just need to remove the ‘src’ attribute of
the video tag and replace it with the ‘type’ attribute of the individual source tags.
The ‘controls’ attribute handles the visibility of the default video controls of the browser. If this
attribute is omitted, then default video controls of the browser will not be visible.
Apart from the above key attributes, HTML5 video tag supports various other attributes and each
feature offers different capabilities. For example, the ‘poster’ attribute allows specifying an image to
be shown until the user plays the video. The ‘autoplay’ attribute allows playing of video as soon as it
is ready without any user action.
Further, we will describe how a HTML5 player can be extended to play videos from YouTube, Vimeo
and Kaltura platforms.
The custom HTML5 player consists of three layers which include:
• Player Layout – This layer consists of a HTML structure for the Player including necessary player
controls. It offers overall control on the look and feel of the Player with the help of style sheet
and consumes JavaScript APIs exposed by the Player Core
• Player Core – This is the core layer of the Player consisting of JavaScript APIs. This layer exposes
JavaScript APIs for different video elements like play, pause, volume, total video duration,
current video time, etc. This layer internally consumes different wrapper APIs based on the type
of video
• Video Delivery Platforms – The video source file hosted on CDN platforms are streamed directly
from the respective CDN platform by this layer
Having seen the high level architecture, we will now elaborate on how custom control functionality
can be implemented within the video player.
Play and Pause Control: A common method can be created to toggle the video. This method can
internally detect the current state of the video based on which it either plays or pauses the video.
Video Seek bar: The JQuery UI range slider can be used for implementing a video seek bar. For the
the range slider, we need to provide the total duration of the video as the maximum parameter.
Fullscreen Control: The HTML5 Fullscreen API can be used to implement this feature. A common
method is used to toggle the video fullscreen, this method internally detects the current state of the
video fullscreen based on which it either enters the video into fullscreen mode or exits the video from
fullscreen mode.
These custom controls ensure the look and feel of the player control to remain consistent across all
the browsers, as seen in the screen snapshot below. (Reference: link http://clips.vorwaerts- gmbh.de/
big_buck_bunny.mp4 )
Things to remember
Following are some of the few generic guidelines which ensure player size and custom controls
remains intact in all scenarios:
• The z-index for html elements of the custom player controls has to be set to 2147483647. This
will keep the custom player controls visible when the video is in fullscreen mode
• If the video is embedded using HTML5 video tag then the following style sheet needs to be added
to hide the browser native video controls in the fullscreen mode
video::-webkit-media-controls {
display:none !important;
A Harbinger
} Systems White Paper
© Harbinger Group | www.harbingergroup.com
6
The viewport meta tag needs to be added in the player HTML to keep the player in its original size in
Table lists down some of the well-known HTML5 video players and compares them on different
playing the videos hosted across different video delivery platforms. There are many video delivery
platforms available but we will cover the most popular ones in this whitepaper.
YouTube
YouTube provides IFrame Player API using which YouTube videos can be embedded. This API provides
seamless interface with YouTube player and also offers the ability to control YouTube video events,
The HTML5 video player needs to implement ‘onYouTubeIframeAPIReady’ JavaScript function. The
Iframe API invokes this function once the JavaScript for player API is loaded. Internally, this method
can initialize the YouTube player object using YouTube video ID which would load the video.
The API offers ‘onReady’ and ‘onStateChange’ events. The ‘onReady’ event gets triggered when the
video player is ready to play the video and ‘onStateChange’ event gets triggered when the player
states the changes, which indicate that the player is playing, paused, finished and so forth. The
detailed information about IFrame API is available on Google developer portal.
https://developers.google.com/youtube/iframe_api_reference
Vimeo
Vimeo provides JavaScript Player API which gives the ability to control the embedded Vimeo player.
The API offers a window.postMessage() mechanism to interact with the player and the same can be
achieved by sending a serialized JSON object with postMessage(). The format of the JSON object is as
follows:
"method": "methodName",
A Harbinger
"value": "value" Systems White Paper
}
The API also offers ‘loadProgress’ and ‘playProgress’ events. In this functioning, ‘loadProgress’ event
gets triggered when the video is loading; it shows the current loaded percentage and the duration of
the video. The ‘playProgress’ event gets activated when the video is playing; it shows the seconds,
percentage exhausted and the total duration of the video. The detailed information about JavaScript
API is available on Vimeo developer portal. https://developer.vimeo.com/player/js-api
Please note, the Vimeo API does not provide the mechanism to
override or hide the default Vimeo video player controls. The
default Vimeo video player controls can be controlled by the owner
of the video from the Vimeo portal. This feature is available for the
users of Vimeo Plus or Pro account.
Kaltura
Kaltura provides a kWidget API using which a standalone video URL can be retrieved for the videos
hosted in Kaltura. The video URL then can be used as a source in the standard HTML5 video tag to
embed the video. The kWidget API returns multiple video URLs having different sizes and bitrates.
The kWidget API is available after we include it in the Kaltura player API library. JavaScript way of
including Kaltura Player API library is as follows:
<!-- Substitute {partner_id} for your Kaltura partner id, {uiconf_id} for uiconf player id -->
<script
src="http://cdnapi.kaltura.com/p/{partner_id}/sp/{partnerId}00/embedIframeJs/uiconf_id/{uiconf_id
}/partner_id/{partnerId}"></script>
http://player.kaltura.com/docs/index.php?path=api
• Similarly, the other video delivery platforms can be integrated seamlessly with the custom
video player, just by plugging the necessary APIs offered by the video platforms.
Mobile Challenges
Today, most of the mobile browsers are developed having HTML5 compatibility. HTML5 has
upgraded and advanced in the sector of Animation and Video but there is a huge scope of
improvement for mobile based browsers. However, recently developed mobile browsers do have
adequate support for HTML5 video tag specifications. Also, the screen size and network bandwidth of
a mobile device is small and limited when compared with desktop computers. These two factors
highlight the limitations on some of the attributes of the HTML5 video tag as listed below:
• Autoplay or preload is not supported on mobile devices. This means on mobile devices video
will not start playing or buffering till the time the user performs some action.
• Volume property of video is read-only on mobile devices. This means on mobile devices the user
will not be able to control video volume using custom controls. The video volume will be
controlled by the user using device volume control.
• HTML5 Fullscreen – iOS Safari browser and Android Stock browser does not support HTML5
Fullscreen APIs
• iPhone does not play video inline in the webpage, it plays the video in fullscreen mode using
native video controls. Therefore, the custom video player controls will not be visible on the
iPhone screen. Apple provides webkit-playsinline attribute for video tag to play video inline in
webpage, however, as observed by us, this attribute works only when the webpage is
bookmarked to iPhone home screen. The native video player application with custom controls
can be built for the iPhone with the help of MPMoviePlayerController class reference.
A Harbinger Systems White Paper
© Harbinger Group | www.harbingergroup.com 10
As we move ahead with the continuous evolvement of HTML5 video tag specification we can
experience that the player with HTML5 capabilities is emerging to be as a widely used standardized
common for delivering exceptional videos across browsers and devices. The three layered
architecture ensures new controls can be easily programmed in the custom HTML5 video player. It
also provides scalability to include other available delivery platforms.
Contact us now, to know more about our services in the HTML5 video player space.
• CDN: A content delivery network or content distribution network (CDN) is a large distributed
system of servers deployed in multiple data centers across the Internet
• Froogaloop: Small JavaScript utility framework to help with the complexities involved in dealing
with using the JavaScript API through window.postMessage for controlling Vimeo's Moogaloop
video player
• GPL: The GNU General Public License (GNU GPL or GPL) is the most widely used free software
license, which guarantees end users (individuals, organizations, companies) the freedoms to
run, study, share (copy), and modify the software
• H.264: Advanced Video Coding (MPEG-4 AVC) is a video coding format that is currently one of
the most commonly used formats for the recording, compression, and distribution of video
content
• JSON: JavaScript Object Notation is a lightweight data-interchange format. It is easy for humans
to read and write. It is easy for machines to parse and generate.
• MP4: Digital multimedia format most commonly used to store video and audio, but can also be
used to store other data such as subtitles and still images
• OGG: Free, open container format maintained by the Xiph.Org Foundation. The creators of the
Ogg format state that it is unrestricted by software patents and is designed to provide for
efficient streaming and manipulation of high quality digital multimedia.
• VP8: Video compression format owned by Google and created by On2 Technologies as a
successor to VP7
• WebM: Video file format, primarily intended to offer a royalty-free alternative to use in the
HTML5 video tag. The development of the format is sponsored by Google, the corresponding
Software is distributed under a BSD license.