0

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

我读了这个:

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

但我无法让它工作。

4

1 回答 1

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; 
于 2013-06-24T04:53:39.950 回答