phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Finally - fixed attachment mod not playing MP4 videos on iOS


 
Search this topic... | Search phpBB2 Discussion... | Search Box
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Author Message
JLA
Board Member



Joined: 30 Apr 2009

Posts: 329
Location: U.S.A


flag
PostPosted: Wed Oct 23, 2019 3:35 pm 
Post subject: Finally - fixed attachment mod not playing MP4 videos on iOS

Finally after putting it on the back burner - we've fixed attachment mod's ability to playback MP4 videos using videojs on Apple iPhone, iPad, iOS devices.

Example of this working now here
http://www.jlaforums.com/viewtopic.php?t=239387290

Turn out the trick is since the playback file is called by a separate php file - you have to send some headers in the response that were not being sent by the old way. Here is the specific code that deals with this for those who might have ran into the same problem

Code:

$fp = fopen(**LOCATION OF YOUR FILE**  . $physical_filename, "rb");
         $size = **GIVE THE FILE SIZE HERE EITHER THROUGH PHP OR STORED IN DB/CACHE**;
         $length = $size;
         $start = 0;
         $end = $size - 1;
         header('Content-type: flv-application/octet-stream');
         header("Accept-Ranges: 0-$length");
         if (isset($_SERVER['HTTP_RANGE'])) {
         $c_start = $start;
         $c_end = $end;
         list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);

         if (strpos($range, ',') !== false) {
            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            header("Content-Range: bytes $start-$end/$size");
            exit;
         }

         if ($range == '-') {
            $c_start = $size - substr($range, 1);
         } else {
         $range = explode('-', $range);
            $c_start = $range[0];
            $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
         }

         $c_end = ($c_end > $end) ? $end : $c_end;

         if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            header("Content-Range: bytes $start-$end/$size");
            exit;
         }

         $start = $c_start;
         $end = $c_end;
         $length = $end - $start + 1;
         fseek($fp, $start);
         header('HTTP/1.1 206 Partial Content');
         }

         header("Content-Range: bytes $start-$end/$size");
         header("Content-Length: ".$length);

         $buffer = 1024 * 8;

         while(!feof($fp) && ($p = ftell($fp)) <= $end) {
         if ($p + $buffer > $end) {
            $buffer = $end - $p + 1;
         }
         set_time_limit(0);
         echo fread($fp, $buffer);
         flush();
         }

         fclose($fp);
         exit;




Happy now

_________________
http://www.jlaforums.com
Back to top
JLA
Board Member



Joined: 30 Apr 2009

Posts: 329
Location: U.S.A


flag
PostPosted: Tue Oct 29, 2019 10:07 pm 
Post subject: Re: Finally - fixed attachment mod not playing MP4 videos on

After some more testing - found that some larger files were causing intermittent fast-cgi php requests to return 500 when someone would watch one of these videos.

Made this change and the problem seems to not (currently) persist. icon_biggrin.gif

Change
Code:
$buffer = 1024 * 8;


to

Code:
$buffer = 1024 * 4;


Any ideas????



JLA wrote:
Finally after putting it on the back burner - we've fixed attachment mod's ability to playback MP4 videos using videojs on Apple iPhone, iPad, iOS devices.

Example of this working now here
http://www.jlaforums.com/viewtopic.php?t=239387290

Turn out the trick is since the playback file is called by a separate php file - you have to send some headers in the response that were not being sent by the old way. Here is the specific code that deals with this for those who might have ran into the same problem

Code:

$fp = fopen(**LOCATION OF YOUR FILE**  . $physical_filename, "rb");
         $size = **GIVE THE FILE SIZE HERE EITHER THROUGH PHP OR STORED IN DB/CACHE**;
         $length = $size;
         $start = 0;
         $end = $size - 1;
         header('Content-type: flv-application/octet-stream');
         header("Accept-Ranges: 0-$length");
         if (isset($_SERVER['HTTP_RANGE'])) {
         $c_start = $start;
         $c_end = $end;
         list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);

         if (strpos($range, ',') !== false) {
            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            header("Content-Range: bytes $start-$end/$size");
            exit;
         }

         if ($range == '-') {
            $c_start = $size - substr($range, 1);
         } else {
         $range = explode('-', $range);
            $c_start = $range[0];
            $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
         }

         $c_end = ($c_end > $end) ? $end : $c_end;

         if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            header("Content-Range: bytes $start-$end/$size");
            exit;
         }

         $start = $c_start;
         $end = $c_end;
         $length = $end - $start + 1;
         fseek($fp, $start);
         header('HTTP/1.1 206 Partial Content');
         }

         header("Content-Range: bytes $start-$end/$size");
         header("Content-Length: ".$length);

         $buffer = 1024 * 8;

         while(!feof($fp) && ($p = ftell($fp)) <= $end) {
         if ($p + $buffer > $end) {
            $buffer = $end - $p + 1;
         }
         set_time_limit(0);
         echo fread($fp, $buffer);
         flush();
         }

         fclose($fp);
         exit;




Happy now

_________________
http://www.jlaforums.com
Back to top
Display posts from previous:   
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0259 seconds using 16 queries. (SQL 0.0026 Parse 0.0008 Other 0.0226)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo