PHP mp3流元数据

时间:2017-04-30 06:21:15

标签: php stream metadata mp3 podcast

我有一个基于PHP的流框架,如果我尝试将元数据附加到缓冲区,则流开始出现噼里啪啦的噪音,整个流开始崩溃!

我的元数据注入代码:

$o = $i;
$old_buffer = substr(file_get_contents($settings["music_directory"].$playfiles[$i]["filename"]), $playfiles[$i]["audiostart"] + $track_pos, $playfiles[$i]["audiolength"] - $track_pos);
while(time() - $start_time < $settings["max_listen_time"]) {
    $i = ++$i % count($playfiles);
    $buffer = $old_buffer.substr(file_get_contents($settings["music_directory"].$playfiles[$i]["filename"]), $playfiles[$i]["audiostart"], $playfiles[$i]["audiolength"]);

    for($j = 0; $j < floor(strlen($buffer) / $settings["buffer_size"]); $j++) {
        if($icy_data) {
            if($i == $o + 1 && ($j * $settings["buffer_size"]) <= strlen($old_buffer))
                $payload = "StreamTitle='{$playfiles[$o]["artist"]} - {$playfiles[$o]["title"]}';".chr(0);
            else
                $payload = "StreamTitle='{$playfiles[$i]["artist"]} - {$playfiles[$i]["title"]}';".chr(0);

            $metadata = chr(ceil(strlen($payload) / 16)).$payload.str_repeat(chr(0), 16 - (strlen($payload) % 16));
        }


        if(empty($metadata))
            $metadata = "";

        echo substr($buffer, $j * $settings["buffer_size"], $settings["buffer_size"]).$metadata;
    }
    $o = $i;
    $old_buffer = substr($buffer, $j * $settings["buffer_size"]);
}

0 个答案:

没有答案