I'm just a hacker, not a developer, so if someone could run with this as an extension I think it might be useful. Many thanks to AmigoJack for getting me this far - his attribution is in the edits.
Dan
Open /includes/constants.php and find:
Code: Select all
// Categories - Attachments
define('ATTACHMENT_CATEGORY_NONE', 0);
define('ATTACHMENT_CATEGORY_IMAGE', 1); // Inline Images
define('ATTACHMENT_CATEGORY_WM', 2); // Windows Media Files - Streaming
define('ATTACHMENT_CATEGORY_RM', 3); // Real Media Files - Streaming
define('ATTACHMENT_CATEGORY_THUMB', 4); // Not used within the database, only while displaying posts
define('ATTACHMENT_CATEGORY_FLASH', 5); // Flash/SWF files
define('ATTACHMENT_CATEGORY_QUICKTIME', 6); // Quicktime/Mov files
Code: Select all
define('ATTACHMENT_CATEGORY_HTML5', 7); // Native HTML5 files
Code: Select all
'CAT_FLASH_FILES' => 'Flash files',
'CAT_IMAGES' => 'Images',
'CAT_QUICKTIME_FILES' => 'Quicktime media files',
'CAT_RM_FILES' => 'RealMedia media files',
'CAT_WM_FILES' => 'Windows Media media files',
Code: Select all
'CAT_H5_FILES' => 'HTML5 native media files',
Code: Select all
$cat_lang = array(
ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'],
ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'],
ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'],
ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES'],
Code: Select all
ATTACHMENT_CATEGORY_HTML5 => $user->lang['CAT_H5_FILES'],
Code: Select all
$types = array(
ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'],
ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'],
ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'],
ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES'],
Code: Select all
ATTACHMENT_CATEGORY_HTML5 => $user->lang['CAT_H5_FILES'],
Code: Select all
$block_array += array(
'UPLOAD_ICON' => $upload_icon,
'FILESIZE' => $filesize['value'],
'SIZE_LANG' => $filesize['unit'],
'DOWNLOAD_NAME' => utf8_basename($attachment['real_filename']),
'COMMENT' => $comment,
Code: Select all
/*** 2015-06-01 BEGIN AmigoJack
https://www.phpbb.com/community/viewtopic.php?f=71&t=2318416 ***/
'MIMETYPE'=> $attachment['mimetype'],
/*** 2015-06-01 END ***/
Code: Select all
// Windows Media Streams
case ATTACHMENT_CATEGORY_WM:
// Giving the filename directly because within the wm object all variables are in local context making it impossible
// to validate against a valid session (all params can differ)
// $download_link = $filename;
$block_array += array(
'U_FORUM' => generate_board_url(),
'ATTACH_ID' => $attachment['attach_id'],
'S_WM_FILE' => true,
);
// Viewed/Heared File ... update the download count
$update_count[] = $attachment['attach_id'];
break;
Code: Select all
// Native HTML5 Media Streams
case ATTACHMENT_CATEGORY_HTML5:
// HTML browsers play mp4, webm and ogg video formats - and, the mp3 audio format - natively
$block_array += array(
'U_FORUM' => generate_board_url(),
'ATTACH_ID' => $attachment['attach_id'],
'S_H5_FILE' => true,
);
// Viewed/Heared File ... update the download count
$update_count[] = $attachment['attach_id'];
break;
Code: Select all
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
Code: Select all
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use phpbb\symfony_request;
Code: Select all
if (!@file_exists($filename))
{
send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');
}
Code: Select all
// *** Adding HTML5 audio/video content! Caveat Emptor
if ($category == ATTACHMENT_CATEGORY_HTML5)
{
$response = new BinaryFileResponse($filename);
if ($attachment['mimetype'] == 'video/mp4')
{
$response->headers->set('Content-Type', 'video/mp4');
}
elseif ($attachment['mimetype'] == 'audio/mp3')
{
$response->headers->set('Content-Type', 'audio/mp3');
}
global $request;
$response->prepare(new symfony_request($request));
$response->send();
exit;
}
Code: Select all
<!-- ELSEIF _file.S_QUICKTIME_FILE -->
<object id="qtstream_{_file.ATTACH_ID}" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" width="320" height="285">
<param name="src" value="{_file.U_DOWNLOAD_LINK}" />
<param name="controller" value="true" />
<param name="autoplay" value="false" />
<param name="type" value="video/quicktime" />
<embed name="qtstream_{_file.ATTACH_ID}" src="{_file.U_DOWNLOAD_LINK}" pluginspage="http://www.apple.com/quicktime/download/" enablejavascript="true" controller="true" width="320" height="285" type="video/quicktime" autoplay="false"></embed>
</object>
Code: Select all
<!-- ELSEIF _file.S_H5_FILE -->
<!-- IF _file.MIMETYPE == 'audio/mp3' -->
<audio src="{_file.U_DOWNLOAD_LINK}" name="media" controls="true">
<source src="{_file.U_DOWNLOAD_LINK}" type="{_file.MIMETYPE}" controls="true">
</audio>
<!-- ELSE -->
<video src="{_file.U_DOWNLOAD_LINK}" width='80%' width='80%' controls="true">
<source src="{_file.U_DOWNLOAD_LINK}" type="{_file.MIMETYPE}" controls="true">
</video>
<!-- ENDIF -->
Code: Select all
<!-- IF _file.S_WM_FILE or _file.S_RM_FILE or _file.S_FLASH_FILE or _file.S_QUICKTIME_FILE -->
Code: Select all
<!-- IF _file.S_WM_FILE or _file.S_RM_FILE or _file.S_FLASH_FILE or _file.S_QUICKTIME_FILE or _file.S_H5_FILE -->
Code: Select all
'mp3' => 'audio/x-mpeg-3',
Code: Select all
'mp3' => 'audio/mp3',
You should now be able to upload mp4, webm and ogv video files and mp3 audio files and play them natively in an HTML5 compatible browser. On my desktop Windows computer, it works with Chrome and Firefox. N.B.: IE9 and above need a little help with HTML5. mp4's will play natively; webm needs a download: http://www.webmproject.org/ie. I have read that IE will play ogv's with the VLC player as a plugin, but I have not tried. IE11 on my desktop plays mp4's readily, but needed the download to play webm.