From 3d7a9e0a1cba0b173b6b03f5c88a8eb975286cc7 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Fri, 2 Aug 2013 23:13:41 +0100 Subject: 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. --- inc/media.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'inc/media.php') 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 + */ +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: */ -- cgit v1.2.3