如何使用单个php文件和多个媒体文件创建播放列表?
我正在尝试创建一个很棒的音乐播放列表,只使用一个单php文件 现在,使用此代码,我可以从单个媒体文件源流式传输歌曲:如何使用单个php文件和多个媒体文件创建播放列表?,php,file,stream,media,Php,File,Stream,Media,我正在尝试创建一个很棒的音乐播放列表,只使用一个单php文件 现在,使用此代码,我可以从单个媒体文件源流式传输歌曲: <?php // Try and open the remote stream if (!$stream = fopen('http://example.com/audio.mp3', 'r')) { // If opening failed, inform the client we have no content header('HTTP/1.
<?php
// Try and open the remote stream
if (!$stream = fopen('http://example.com/audio.mp3', 'r')) {
// If opening failed, inform the client we have no content
header('HTTP/1.1 500 Internal Server Error');
exit('Unable to open remote stream');
}
// It's probably an idea to remove the execution time limit - on Windows hosts
// this could result in the audio stream cutting off mid-flow
set_time_limit(0);
// Inform the client we will be sending it some MPEG audio
header('Content-Type: audio/mpeg');
// Send the data
fpassthru($stream);
// Thanks DaveRandom
?>
正如@nomaD所说,您必须使用客户端脚本,计算曲目的分钟数,然后运行计时器,一旦达到时间,就用新曲目调用另一个php。您可能需要检查此流媒体是实时协议。而php使用单一http请求-响应协议。
这意味着,您的php不会被自动调用,由播放器自动播放另一首歌曲。充其量,播放器将在曲目结束时停止,只有当listner再次单击play时,才会发送第二个请求
现在,您需要有办法确定播放另一首曲目的第二个请求。会话在非基于浏览器的用户代理(如媒体播放器)中可能不起作用。因此,您可以在php查询字符串中使用唯一的id,并使用本地db/etc来跟踪上次播放的内容
无论哪种方式,自动切换曲目都需要更多的php代码、http缓冲区检查和mp3文件解析,因此最后一个流和附加到下一个流时不需要下一个mp3文件头/id3/等。一次使用一个php文件处理一个mp3可能会更好,然后使用一些客户端脚本异步调用它(例如jQuery的$.get())