diff options
author | Anika Henke <anika@selfthinker.org> | 2013-08-02 23:13:41 +0100 |
---|---|---|
committer | Anika Henke <anika@selfthinker.org> | 2013-08-02 23:13:41 +0100 |
commit | 3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7 (patch) | |
tree | 9963a34099190a1c9241c0e3d8df8de8c13c8171 /inc | |
parent | 2a2a2ba2f6092b0b68a7de0ccc798062682487f4 (diff) | |
download | rpg-3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7.tar.gz rpg-3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7.tar.bz2 |
Add several alternative formats to video for better browser compatibility
All .webm, .ogv and .mp4 files with the same filename are automatically
chosen as alternative sources when only one of them is mentioned in the
media syntax.
Diffstat (limited to 'inc')
-rw-r--r-- | inc/media.php | 29 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 30 |
2 files changed, 52 insertions, 7 deletions
diff --git a/inc/media.php b/inc/media.php index c76f2986c..c1dafe2a3 100644 --- a/inc/media.php +++ b/inc/media.php @@ -2132,4 +2132,33 @@ function media_resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x= return $okay; } +/** + * Return other media files with the same base name + * but a different extension. + * + * @param string $src - ID of media file + * @param array $exts - alternative extensions to find other files for + * + * @author Anika Henke <anika@selfthinker.org> + */ +function media_alternativefiles($src, $exts){ + + $files = array(); + list($srcExt, $srcMime) = mimetype($src); + $filebase = substr($src, 0, -1 * (strlen($srcExt)+1)); + + foreach($exts as $ext) { + $fileid = $filebase.'.'.$ext; + $file = mediaFN($fileid); + if(file_exists($file)) { + $files[$ext] = $fileid; + } + } + // if original wasn't any of $exts, return only original + if (empty($files)) { + $files[$srcExt] = $src; + } + return $files; +} + /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 747f0e8a0..bb5f6a4d2 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1095,9 +1095,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { }elseif(substr($mime,0,5) == 'video'){ + $origTitle = ''; // first get the $title if (!is_null($title)) { $title = $this->_xmlEntities($title); + $origTitle = $title; } if (!$title) { // just show the sourcename @@ -1113,7 +1115,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $att['class'] = "media$align"; //add video(s) - $ret .= $this->_video($src, $title, $mime, $width, $height, $att); + $ret .= $this->_video($src, $origTitle, $mime, $width, $height, $att); }elseif($mime == 'application/x-shockwave-flash'){ if (!$render) { @@ -1269,16 +1271,30 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(!$atts['width']) $atts['width'] = 320; if(!$atts['height']) $atts['height'] = 240; - $url = ml($src,array('cache'=>$cache),true,'&'); + // prepare alternative formats + $extensions = array('webm', 'ogv', 'mp4'); + $types['webm'] = 'video/webm; codecs="vp8, vorbis"'; + $types['ogv'] = 'video/ogg; codecs="theora, vorbis"'; + // mp4 would be 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', but Android doesn't like it + $types['mp4'] = ''; + $alternatives = media_alternativefiles($src, $extensions); // @todo: add poster $this->doc .= '<video '.buildAttributes($atts).' controls="controls">'.NL; - // @todo: foreach all extensions - $this->doc .= '<source src="'.hsc($url).'" />'.NL; + foreach($alternatives as $ext => $file) { + $url = ml($file,array('cache'=>$cache),true,'&'); + $type = $types[$ext]; + if (!$title) { + $title = $this->_xmlEntities(utf8_basename(noNS($file))); + } - // alternative content - // @todo: foreach all extensions - $this->internalmedia($src, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + $this->doc .= '<source src="'.hsc($url).'"'; + if (!empty($type)) $this->doc .= ' type=\''.$type.'\''; + $this->doc .= ' />'.NL; + + // alternative content + $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly'); + } // finish $this->doc .= '</video>'.NL; |