Question

I need a help, I am working on a streaming audio system, and I have a problem with chunked transfer encoding, actually I don't know how to make it workable on the IOS, Android etc. Is there any alternative of chunked encoding? This is my code:

<?php
header('Transfer-Encoding: chunked');
header('Content-Type:audio/mpeg');
header('Connection: keep-alive');
ob_clean();
flush();

$buffer = '';
    $handle = fopen($filepath, 'rb');
    if($handle === false){
        return false;
    }

    while(!feof($handle)){
        $buffer = fread($handle, 8192);

        echo sprintf("%x\r\n", strlen($buffer));
        echo $buffer;
        echo "\r\n";

        ob_flush();
        flush();
    }

    echo sprintf("%x\r\n", 0);
    echo "\r\n";



    fclose($handle);
?>

Thanks for help

Était-ce utile?

La solution

Android prior to 2.3 does not support chunked encoding for its own player. Other players that implement their own clients may also have issues. I have not tested iOS. Chunked encoding is also problematic for many desktop streaming clients as well. It's best not to use it to maximize compatibility.

There are two ways to do this. The first is to return an HTTP/1.0 response. This means that you do not have to specify a content length, and the response stops when the server stops sending it.

The second way is similar to the first, but allows you to work with HTTP/1.1. Just set the header Connection: close. Then, you do not have to specify content length, and do not have to send your data in chunked encoding.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top