首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用php和getid3生成播放列表

用php和getid3生成播放列表
EN

Stack Overflow用户
提问于 2010-02-13 02:15:58
回答 2查看 3.3K关注 0票数 1

我使用php脚本生成一个播放列表,列表中的第一个歌曲条目对于所有字段(艺术家、标题、长度、文件名)都是空的。为什么?

这是脚本

代码语言:javascript
复制
 <?php

 require_once('getid3/getid3.php');

 $dir = 'mp3';
 $file_type = 'mp3';

 $play_list = '<?xml version="1.0" encoding="utf-8"?><config>';


 if (is_dir($dir)) {

 if ($dh = opendir($dir)) {

 while (($file = readdir($dh)) !== false) {

 if ($file != '.' && $file != '..') {

 $name_array = explode('.', $file);


 if ($name_array[1] == $file_type) {

 $play_list .= '<song>';

 $file = "$dir/$file";

 $getID3 = new getID3;

   $ThisFileInfo = $getID3->analyze($file);

  getid3_lib::CopyTagsToComments($ThisFileInfo);


         $play_list .= '<artist>'.$ThisFileInfo['comments_html']['artist'][0] . '</artist>';

         $play_list .= '<title>'. $ThisFileInfo['tags']['id3v2']['title'][0]. '</title>';

  $new_playtime = ereg_replace("[^A-Za-z0-9]", "", $ThisFileInfo['playtime_string'] );

  $play_list .= '<length>'.$new_playtime . '</length>';
  $play_list .= '<fileName>'.$file.'</fileName>';



 $play_list .= '</song>';

 }

 }

 }

 closedir($dh);

 $play_list .= '</config>';

 echo "$play_list";

 }

 }


     ?>

代码语言:javascript
复制
     <?xml version="1.0" encoding="utf-8"?>
    <config>

     <song><artist></artist><title></title><length></length><fileName>mp3/air - all i need.mp3</fileName></song>

<song><artist>Air</artist><title>Remember</title><length>234</length><fileName>mp3/air - remember.mp3</fileName></song>

<song><artist>Air</artist><title>You Make It Easy</title><length>401</length><fileName>mp3/air - you make it easy.mp3</fileName></song>

<song><artist>Ian Brown</artist><title>Dolphins Were Monkeys (Single Version)</title><length>258</length><fileName>mp3/Ian Brown - Dolphins Were Monkeys.mp3</fileName></song>

<song><artist>Ian Brown</artist><title>F.E.A.R.</title><length>431</length><fileName>mp3/Ian Brown - Fear.mp3</fileName></song>

<song><artist>Ian Brown</artist><title>Keep What Ya Got</title><length>348</length><fileName>mp3/Ian Brown - Keep What Ya Got.mp3</fileName></song>

<song><artist>Ian Brown</artist><title>My Star</title><length>509</length><fileName>mp3/Ian Brown - My Star.mp3</fileName></song>

<song><artist>Ian Brown</artist><title>Time Is My Everything</title><length>354</length><fileName>mp3/Ian Brown - Solarized - 02 - Time Is My Everything.mp3</fileName></song></config>      
EN

回答 2

Stack Overflow用户

发布于 2010-02-13 02:20:58

filename字段不为空:<song><artist></artist><title></title><length></length><fileName>mp3/air - all i need.mp3</fileName></song>

也许只是因为没有为"all i need.mp3“设置ID3标签?

附言:你应该对PATHINFO_EXTENSION使用pathinfo,而不是explode,因为如果一首歌包含几个点,它就不会被匹配。

票数 3
EN

Stack Overflow用户

发布于 2010-02-13 02:32:38

尝试使用glob()获取文件。http://us.php.net/manual/en/function.glob.php

代码语言:javascript
复制
$files = glob($dir . '/*.mp3');

foreach ($files as $file) {
...
}

使用pathinfo()获取文件扩展名信息。http://php.net/manual/en/function.pathinfo.php

不过,如果使用上面的glob()函数,就不必这样做了,因为*.mp3已经过滤了mp3文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2254080

复制
相关文章

相似问题

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