Skip to content

Stream Headers for Android #3

@thepag

Description

@thepag

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions