在php中读取mp3流并回显到客户端
我想要实现的是一个页面,当客户端要连接时,该页面将不断地从本地ice cast服务器读取(在php中读取mp3流并回显到客户端,php,proxy,mp3,Php,Proxy,Mp3,我想要实现的是一个页面,当客户端要连接时,该页面将不断地从本地ice cast服务器读取(http://127.0.0.1:8000/stream.mp3),并将流回显到客户端,客户端可以在基本音频标签中播放流 <?php header("Content-Transfer-Encoding: binary"); header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"); header('Co
http://127.0.0.1:8000/stream.mp3
),并将流回显到客户端,客户端可以在基本音频标签中播放流
<?php
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header('Content-Disposition: attachment; filename="stream.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
print file_get_contents("http://127.0.0.1:443/stream.mp3");
file\u get\u contents
尝试将流读取到底,并且由于您尝试从广播服务器读取,因此没有尽头
如果HTML5是一个选项,那么以下方法可能会起作用
<audio autoplay>
<source src="http://127.0.0.1:443/stream.mp3" type="audio/mpeg">
</audio>
替代解决方案:
<?php
ob_start();
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header('Content-Disposition: attachment; filename="stream.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
$handle = fopen("http://127.0.0.1:443/stream.mp3");
while (($data = fread($handle, $bufferSize)) { //Buffer size needs to be large enough to not break audio up while getting the next part
echo $data;
ob_flush();
flush();
set_time_limit(30); // Reset the script execution time to prevent timeouts since this page will probably never terminate.
}
我更愿意在http服务器级别上这样做,通过http服务器代理ice cast服务器。这样的话,php就不用了。IIS Express可以这样做吗?对不起,我不知道。那么微软又做了与微软Outlook和微软Outlook Express相同的事情?为什么?对不起,我打算在本地托管ice cast,并转发http服务器端口。然后,连接到http服务器的客户端只允许以某种方式访问../stream.mp3,而不允许访问ice cast界面的任何其他部分。我已经记下了一个替代方案(不确定它是否有效,还没有测试它,但我不明白为什么它不会)。不幸的是,IIS Express不支持反向代理(根据)。请共享此解决方案并标记我