Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream Headers for Android #3

Open
thepag opened this issue Nov 21, 2014 · 0 comments
Open

Stream Headers for Android #3

thepag opened this issue Nov 21, 2014 · 0 comments

Comments

@thepag
Copy link
Member

thepag commented Nov 21, 2014

Recording this information here, due to relevancy. The original post on jPlayer google group may have more information.

Dom Wyss Wrote:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant