首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Getid3生成30秒的mp3预览

使用Getid3生成30秒的mp3预览
EN

Stack Overflow用户
提问于 2013-06-24 12:33:29
回答 1查看 1.2K关注 0票数 0

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

我读到了这个:

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

但是我不能让它工作。

EN

回答 1

Stack Overflow用户

发布于 2013-06-24 12:53:40

如果你想避免使用ID3标签库,你可以修改它,只播放歌曲的10%,这将使用以下代码:

代码语言:javascript
复制
$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; 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17268070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档