The \HAPEL\Builder\Video()
class allows for the creation of complete <video>
components.
HAPEL already loads the Video Class automatically so all you need to do is to create an instance of the class like so:
$V = new \HAPEL\Builder\Video();
To create a video component, call the video()
method:
echo $V->get($class, $id, $style, $data, $attr);
The get()
method takes the standard HAPEL core parameters.
To set or unset additional get
parameters such as autoplay
or sources
, call one of the related methods below:
HTML Attribute | Default | Set Method | Unset Method |
---|---|---|---|
autoplay | false | setAutoplay() | unsetAutoplay() |
control | false | setControls() | unsetControls() |
height | setHeight($height) | unsetHeight() | |
loop | false | setLoop() | unsetLoop() |
muted | false | setMuted() | unsetMuted() |
poster | setPoster($src) | unsetPoster() | |
preload | 'none' | setPreload($preload) | unsetPreload() |
source | setSource($src, $type)) | unsetSources() | |
src | setSrc($src) | unsetSrc() | |
width | setWidth($width) | unsetWidth() |
Parameter | Type | Default | Required | Expected Values |
---|---|---|---|---|
$height | int | No |
Parameter | Type | Default | Required | Expected Values |
---|---|---|---|---|
$src | string | Yes |
Parameter | Type | Default | Required | Expected Values |
---|---|---|---|---|
$value | string | 'none' | No | 'none', 'auto', 'metadata' |
Parameter | Type | Default | Required | Expected Values |
---|---|---|---|---|
$src | string | 'none' | Yes | |
$type | string | 'video/mp4' | No | Usually will be 'video/{format}' |
Parameter | Type | Default | Required | Expected Values |
---|---|---|---|---|
$src | string | Yes |
Parameter | Type | Default | Required | Expected Values |
---|---|---|---|---|
$width | int | Yes |
Usage:
$V = new \HAPEL\Builder\Video();
$V->setControls();
$V->setSrc('fireworks.mp4')
echo $V->get('my-player');
Result:
<video class="my-player" controls="controls" src="fireworks.mp4"></video>
Usage:
$V = new \HAPEL\Builder\Video();
$V->setControls();
$V->setSource('fireworks.mp4');
$V->setSource('fireworks.avi', 'video/avi');
echo $V->get('my-player');
Result:
<video class="my-player" controls="controls">
<source src="fireworks.mp4" type="video/mp4">
<source src="fireworks.avi" type="video/avi">
</video>
Let's say you want to create two video components without calling a new instance. You can do this by using the unset methods.
Usage:
$V = new \HAPEL\Builder\Video();
$V->setControls();
$V->setSource('plane.mp4');
echo $V->get();
$V->unsetSources();
$V->setSource('boat.mp4');
echo $A->get();
Result:
<video>
<source src="plane.mp4" type="video/mp4">
</video>
<video>
<source src="boat.mp4" type="video/mp4">
</video>