使用Getid3生成mp3的30秒预览



是否可以使用getid3生成mp3的30秒预览?我不想创建它的副本并将其保存在服务器上,只需在请求mp3时创建预览即可。

我读到这个:

http://www.stephenwalcher.com/blog/2012/01/17/how-to-extract-and-play-part-of-an-mp3-in-php/

但我没能让它发挥作用。

如果你想避免使用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; 

最新更新