Bolt CMS HTML5 Video Extension
What This Is
This deals with Bolt HTML5 Video versions 2.x.x+. If you need the demo for versions 1.x+ please see: Bolt HTML5 Video v1x page
This is a Bolt Content Management System extension that enables you to use a twig tag to insert HTML5 videos using the video element.
Bolt's video field uses oEmbed - relevant bolt docs on the field. This works great if you're using a video hosted on any of the video hosting services. If you have local videos, in your "files" directory, or on your own cdn you can't insert your videos. This allows that.
Upgrading to v2.x.x
Version 2.x.x no longer uses the filelist index in twig templates. Meaing the following code no longer works and MUST be changed.
{{ html5video( record.video.0, 'blogVideos' ) }}
The needed change is to remove the .0 from the record.video portion. It should now look as follows:
{{ html5video( record.video, 'blogVideos' ) }}
Removed Config Options
The config options of multiple_source
, video_types
, and save_data
have been removed. If
you are using those in your twig templates as over-rides similar to below you'll need to remove them from your
templates.
{# this will no longer work #}
{{ html5video( record.video, 'default', {
save_data: true,
multiple_source: true,
video_types: [ 'webm', 'mp4' ],
width_height: [ 640, '100%' ],
media_fragment: [6, 16 ]
} )
}}
{# this is how it should look now. without those removed options #}
{{ html5video( record.video, 'default', {
width_height: [ 640, '100%' ],
media_fragment: [6, 16 ]
} )
}}
This also means all the settings found under save_data_options are no longer applied.
Installation
In the backend of your Bolt install navigate to the "Extras" menu in your dashboard and click "view/install extensions". In the "Install New Extension" search box type either "HTML5 Videos" or paste the following snippet.
cdowdy/html5video
Then click "Browse Versions and install the latest stable version.
Setup
This extension comes with a custom field type you can add to your contentType fields. If you wish to use this
extension with your contentTypes you'll need to add it's field type to each field. The custom field type is: h5video
.
entries:
name: Entries
singular_name: Entry
fields:
# Other Fields Here!
video:
type: h5video
You can now upload or pick your files in your contentType edit or creation.
Uploading Multiple videos through the contenttype's edit or creation screen
Quick Usage
Once you have your contenttype fields set you can quickly use the twig tag in your templates with default settings.
Using the contenttype field like "record.video"
{{ html5video( record.video, 'default' ) }}
Using a file from "files"
{{ html5video( 'your-file.webm', 'default' ) }}
The default settings used are:
default:
use_cdn: false
attributes: [ 'controls']
preload: 'metadata'
Config Settings
For your own html5video settings you need to create a named config in the extensions config file. Either through a text editor and edit the "html5video.cdowdy.yml" file or through the extend screen and the "config" button located in the extensions info box .
Here is an example named config
blogVideos:
use_cdn: false
video_poster: 'path/to/poster.png'
attributes: [ 'controls', 'muted' ]
preload: 'metadata'
width_height: [ 400, '100%' ]
Using The Extension With Your Settings
With your named config in place you can move on to using the extension.
# Your Contenttypes.yml file and your contenttype
blogposts:
name: BlogPosts
singular_name: blogpost
fields:
# Other Fields above or below
video:
type: h5video
{# Your Template and using the example config from above called blogVideos #}
{{ html5video( record.video, 'blogVideos' ) }}
If you have multiple files in your files directory you'd like to use instead of picking them in your record edit and creation screen:
{# Your Template and using the example config from above called blogVideos #}
{{ html5video( [ 'your-file.webm', 'your-file.mp4' ], 'blogVideos' ) }}
Using Local Videos
'Local videos' is defined as videos stored locally on your server. You can see any local videos you have uploaded in Bolt's backend under the File Management > Uploaded Files page.
Below is an example of using a file from files.
File from "files". This is in a sub directory in files.
{{ html5video( 'demos/firefox-dev-serviceworkers-enable.webm', 'default' ) }}
To use the video that is locally stored and attached to our contentType's record you replace the file path with the contentType field you have chosen. For example:
{{ html5video( record.video, 'default' ) }}
Result:
Using A CDN
A CDN is defined as your personal content delivery network. Examples of these are Amazon Cloudfront or MaxCDN.
The CDN can be configured in the extensions config file so you all you have to do is pass a filename to the twig tag.
cdn_url: https://your-cdn.com/path/to/files/
Then in your twig template you can just pass the file name.
{{ html5video( 'my-cdn-file.webm', 'default' ) }}
The filename will be appended to your cdn URL set in the config.
<video controls preload="metadata">
<source src="https://your-cdn.com/path/to/files/my-cdn-file.webm" type="video/webm" >
</video>
Alternatively if you leave the config setting of cdn_url blank you can pass in the CDN url in the twig tag.
cdn_url:
{{ html5video( 'https://your-cdn.com/path/to/files/my-cdn-file.webm', 'default' ) }}
If you Have a CDN Url set and pass in the full CDN URL you will get a bad URL. You have to choose one or the other as of right now.
Advanced Usage
You can over ride just about any default setting or user supplied settings in the extensions config inside a template. You must supply the video file or url you wish to use, followed by a rule set (or use defaults) then followed by which custom settings you wish to use
When you decide to override inside the template you must follow the same conventions used in the extensions config. If an array is used ( brackets ie: [ ] ) use those in your templates too.
Over-ride an array option and a string
The Default settings
default:
use_cdn: false
attributes: [ 'controls']
preload: 'metadata'
Adding an option in our template to the attributes and preload setting and adding in a poster.
{{ html5video( record.video, 'default', {
preload: 'none',
video_poster: '/files/demos/sw-enable-poster.png',
attributes: [ 'controls', 'muted', 'loop', 'playsinline' ]
} )
}}
The video will now have muted, loop and playsinline along with controls as attributes and preload="none" added to the video element
Examples
Usage Examples of some of the available options that do affect the video markup and output
Multiple CDN Videos in a Template
Using a CDN you more than likely cannot access the file name in the backend of Bolt. You'll need to pass the filename(s) you wish to use in from your Twig template. Make sure you've setup your CDN URL first or use the full URL to your file on the CDN.
Using cdn_url
First we'll have to set the 'cdn_url' in our extensions config file and create or use a named config block.
Setting the 'cdn_url' and 'use_cdn' to true in our named config.
cdn_url: https://www.mycdn.com/
# a named config block:
useCDNUrl:
use_cdn: true
attributes: [ 'controls']
preload: 'auto'
result:
Video Author: Aaron Rickel License: ATTRIBUTION LICENSE 3.0
Once we've done this we can move to the template we are using for the record. Typically record.twig.
We'll then use an array (denoted with brackets) in our template with all the files we wish to use without the
portion of the URL found in
cdn_url:
{# record.twig - our template to display the record content #}
{{ html5video( ['yosemitie-spring.webm', 'yosemitie-spring.mp4' ], 'useCDNUrl' ) }}
Without a cdn_url set
Here no cdn_url is set so we have to use the full URL for our cdn in the template.
No 'cdn_url' and 'use_cdn' to true in our named config.
cdn_url:
# a named config block:
useCDNUrl:
use_cdn: true
attributes: [ 'controls']
preload: 'auto'
result:
Video Author: Aaron Rickel License: ATTRIBUTION LICENSE 3.0
Again we'll be working in your template used for the record —record.twig. We are also using brackets just like above and supplying all our videos we wish to use with the FULL URL.
{# record.twig - our template to display the record content #}
{{ html5video( ['https://www.mycdn.com/yosemitie-spring.webm', 'https://www.mycdn.com/yosemitie-spring.mp4' ], 'useCDNUrl' ) }}
Multiple Local Videos in a Template
This is for using multiple videos in a template with the videos located in your '/files/' directory. You'll need to have a named config block with 'use_cdn' set to false. This is also the default for the extension.
Our default config with 'use_cdn' set to false.
default:
use_cdn: false
attributes: [ 'controls']
preload: 'metadata'
result:
Just like the multiple videos using a cdn we'll use brackets with the file name, taking into account any sub directories, and the named config we are using.
{# record.twig - our template to display the record content #}
{{ html5video( ['your-file.webm', 'your-file.mp4' ], 'default' ) }}
Controlling A Videos Start and End Times
You can pass a media fragment ( a set of numbers) to the media_fragment setting. This allows you to start and stop a video at a specified time.
Your named config for the extension and providing a media fragment.
yourConfig:
# other settings here
media_fragment: [6, 16 ]
This video will start playing at 6 seconds and stop at 16.
result:
Video Author: Aaron Rickel License: ATTRIBUTION LICENSE 3.0
Using Videos for Animations like a Gif
You can drop bandwidth heavy gif animations and use videos instead! There are a few things you'll need to have for this to work and act like a gif in Android and eventually iOS 10+.
- mark the video as muted
- add the autoplay attribute
- add the loop attribute
- special snowflake iOS needs the playsinline attribute
gifLike:
attributes: [ 'autoplay', 'muted', 'loop', 'playsinline' ]
width_height: [ 640, '100%' ]
result:
Usage Tips
- Webm Files are typically smaller than MP4 files.
-
Don't Use Autoplay on videos!
- Autoplay is ok though for gif like animations
-
For gif like animations use the following in your attributes settings for best browser support & user experience
- autoplay
- muted
- loop
- playsinline
Extension Source and Bug Filling
The source for Bolt HTML5 Videos can be found at my github page
Bolt HTML5 Videos Bug filling
Bolt HTML5 Videos Extensions Store Page