是否可以使用getid3生成30秒的mp3预览?我不打算创建它的副本并将其保存在服务器上,只需在请求mp3时创建预览。
我读到了这个:
http://www.stephenwalcher.com/blog/2012/01/17/how-to-extract-and-play-part-of-an-mp3-in-php/
但是我无法让它发挥作用。
答案 0 :(得分:2)
如果你想避免使用ID3标签库,你可以将其修改为只播放10%的歌曲,这将使用以下代码:
$handle = fopen($filename, 'r');
$content = fread($handle, filesize($filename));
$length = strlen($content);
if (!$session->IsLoggedIn()) {
$length = round(strlen($content) / 10); /* Change 10 to be 2 to play 50% of the song, or 5 to play 20% of the song. A value of 10 will play 10% of the song, a decent preview amount */
$content = substr($content, $length * .66 /* Start extraction 2/3 of that in; if it does turn out to be 30 seconds, it will start 20 seconds in.*/, $length);
}
header("Content-Type: {$id3_info['mime_type']}");
header("Content-Length: {$length}");
print $content;