【问题标题】:Generate 30 second preview of mp3 using Getid3使用 Getid3 生成 30 秒的 mp3 预览
【发布时间】:2013-06-24 04:33:29
【问题描述】:

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

我读到了:

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

但我无法让它工作。

【问题讨论】:

  • 该代码不会进行 30 秒的预览,它会从大约 20 秒开始播放整首歌曲。是你的问题吗?
  • @BelginFish 看看我的回答?

标签: php audio getid3


【解决方案1】:

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

【讨论】:

  • 您正在使用 $id3_info,即使它没有设置,这不会导致问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-07
  • 2011-06-18
  • 1970-01-01
  • 2021-10-17
  • 2019-09-14
  • 1970-01-01
相关资源
最近更新 更多