-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoui_video.php
161 lines (143 loc) · 5.32 KB
/
oui_video.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/*
* This file is part of oui_player_abcnews,
* a oui_player v2+ extension to easily create
* HTML5 customizable video and audio players in Textpattern CMS.
*
* https://github.com/NicolasGraph/oui_video
*
* Copyright (C) 2018 Nicolas Morand
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA..
*/
/**
* Video
*
* Manages HTML5 <video> player.
*
* @package Oui\Player
*/
namespace Oui;
if (class_exists('Oui\Audio')) {
class Video extends Audio
{
protected static $iniDims = array(
'width' => '640',
'height' => '',
'ratio' => '16:9',
'responsive' => array(
'default' => 'false',
'valid' => array('true', 'false'),
),
);
protected static $iniParams = array(
'autoplay' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'controls' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'loop' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'muted' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'poster' => array(
'default' => '',
'valid' => 'url',
),
'preload' => array(
'default' => 'auto',
'valid' => array('none', 'metadata', 'auto'),
),
);
protected static $mediaType = 'video';
protected static $mediaPatterns = array(
'filename' => array(
'scheme' => '#^((?!(http|https)://(www\.)?)\S+\.(mp4|ogv|webm))$#i',
'id' => '1',
),
'url' => array(
'scheme' => '#^((https?://(www\.)?)\S+\.(mp4|ogv|webm))$#i',
'id' => '1',
),
);
protected static $mediaMimeTypes = array(
'mp4' => 'video/mp4',
'ogv' => 'video/ogg',
'webm' => 'video/webm',
);
/**
* {@inheritdoc}
*/
public function getHTML()
{
if ($sources = $this->getMediaInfos()) {
$src = array_shift($sources)['uri'];
$sourcesStr = array();
foreach ($sources as $source) {
$sourcesStr[] = '<source src="' . $source['uri'] . '" type="' . self::getMediaMimeType(pathinfo($source['uri'], PATHINFO_EXTENSION)). '">';
}
$paramsStr = '';
foreach ($this->getParams() as $param => $value) {
$paramsStr .= self::getSrcGlue() . ($value === true ? $param : $param . '=' . $value);
}
$dims = $this->getDims();
$wrapStyle = '';
$style = '';
extract($dims);
if ($responsive) {
$wrapStyle .= ' style="position: relative; padding-bottom:' . $height . '; height: 0; overflow: hidden"';
$style .= ' style="position: absolute; top: 0; left: 0; width: 100%; height: 100% ';
$width = $height = false;
} else {
foreach (array('width', 'height') as $dim) {
if (is_string($$dim)) {
$style = ' style="' . $dim . ':' . $$dim . '';
$$dim = false;
}
}
}
$style ? $style .= '"' : '';
$player = sprintf(
'<video src="%s"%s%s%s%s>%s%s</video>',
$src,
!$width ? '' : ' width="' . $width . '"',
!$height ? '' : ' height="' . $height . '"',
$style,
$paramsStr,
($sourcesStr ? n . implode(n, $sourcesStr) : ''),
n . gtxt(
'oui_player_html_player_not_supported',
array(
'{player}' => '<video>',
'{src}' => $src,
'{file}' => basename($src),
)
) . n
);
list($wraptag, $class) = $this->getWrap();
list($label, $labeltag) = $this->getLabel();
$wrapStyle && !$wraptag ? $wraptag = 'div' : '';
$wraptag ? $player = n . $player . n : '';
return doLabel($label, $labeltag) . n . doTag($player, $wraptag, $class, $wrapStyle);
}
}
}
}