php stream mp3 to jPlayer

150 views
Skip to first unread message

Dom Wyss

unread,
Nov 20, 2014, 10:22:58 AM11/20/14
to jpl...@googlegroups.com
Hi there,

Dave Rodriguez and me did spend a bit of time on this.

For jPlayer to work with browsers on Android newer than 2.3, the stream must have different headers.

From this and this stackoverflow answers, we came to this solution

<?php
$path       = __DIR__ . 'tracks/track.mp3';
$fileSize   = filesize($path);
$strContext = stream_context_create(
   array(
       'http'=>array(
       'method'=>'GET',
       'header'=>"Accept-language: en\r\n"
       )
   )
);

header('Accept-Ranges:    none');
header('Cache-Control:    no-cache');
header('Content-type: audio/mpeg');
header('Pragma:    no-cache');

$userAgent = $_SERVER['HTTP_USER_AGENT'];
               
if (is_int(strpos($userAgent, 'Android')) && !is_int(strpos($userAgent, 'Android 2')))
{
    header('Transfer-Encoding:    none');
    header('Connection:    close');
}
else
{
  header('Content-Length:    ' . $fileSize);
}

$fpOrigin = fopen($path, 'rb', false, $strContext);
while(!feof($fpOrigin)){
    $buffer = fread($fpOrigin, 4096);
    echo $buffer;
    flush();
}
fclose($fpOrigin);
exit;

Hope this helps somebody!

All the best
Dom



Mark Panaghiston

unread,
Nov 21, 2014, 10:10:36 AM11/21/14
to jpl...@googlegroups.com
Take a look at this here:

If you would create an issue with this information there, that would be great.
Also, if you did made the Pull Request then I can get on Pull Requests I'm looking at merging into jPlayer core and its playlist ad-on.

And that just made me think... That smartReadFile repository does not have a CLA... I should add one and to our other repositories.

Mark Panaghiston

unread,
Nov 21, 2014, 10:19:14 AM11/21/14
to jpl...@googlegroups.com
I made this issue here for you:

I'm not sure if it applies to the smartReadFile or not, but recorded it there in case.
Reply all
Reply to author
Forward
0 new messages