当前位置: 首页>>代码示例>>PHP>>正文


PHP Track::readId3方法代码示例

本文整理汇总了PHP中Track::readId3方法的典型用法代码示例。如果您正苦于以下问题:PHP Track::readId3方法的具体用法?PHP Track::readId3怎么用?PHP Track::readId3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Track的用法示例。


在下文中一共展示了Track::readId3方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addFiles

 /**
  * Scan the specified folder and subfolders, insert in the library the files found.
  *
  * @param string $folder Root folder to scan
  *
  * @return array Tracks inserted
  */
 public function addFiles($folder)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Artist.php';
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Album.php';
     $result = array();
     $this->scanFolders($folder, $this->folders);
     foreach ($this->files as $file) {
         //reset timeout for 20 seconds before processing each file
         set_time_limit(20);
         $track = new Track();
         $track->file = $file;
         $trackInfo = $track->readId3();
         if (key_exists('comments_html', $trackInfo)) {
             //ID3 has been found, we can use it
             if (key_exists('title', $trackInfo['comments_html'])) {
                 $track->title = $trackInfo['comments_html']['title'][0];
             }
             if (key_exists('album', $trackInfo['comments_html'])) {
                 $track->albumName = $trackInfo['comments_html']['album'][0];
             }
             if (key_exists('artist', $trackInfo['comments_html'])) {
                 $track->artistName = $trackInfo['comments_html']['artist'][0];
             }
             if (key_exists('track_number', $trackInfo['comments_html'])) {
                 $track->track = intval($trackInfo['comments_html']['track_number'][0]);
             }
             if (key_exists('year', $trackInfo['comments_html'])) {
                 $track->year = intval($trackInfo['comments_html']['year'][0]);
             }
             if (key_exists('audio', $trackInfo) && key_exists('bitrate_mode', $trackInfo['audio'])) {
                 $track->mode = $trackInfo['audio']['bitrate_mode'];
             }
             if (key_exists('audio', $trackInfo) && key_exists('bitrate', $trackInfo['audio'])) {
                 $track->bitrate = intval($trackInfo['audio']['bitrate']);
             }
             if (key_exists('playtime_seconds', $trackInfo)) {
                 $track->time = intval($trackInfo['playtime_seconds']);
             }
             if (key_exists('filesize', $trackInfo)) {
                 $track->size = intval($trackInfo['filesize']);
             }
         }
         if (!isset($track->title, $track->albumName, $track->artistName)) {
             //We use the filesystem pattern /path/artistName/albumName/title.ext
             $elements = explode('/', $file);
             $title = str_replace('-', ' ', str_replace('_', ' ', end($elements)));
             $albumName = str_replace('-', ' ', str_replace('_', ' ', prev($elements)));
             $artistName = str_replace('-', ' ', str_replace('_', ' ', prev($elements)));
             if (!isset($track->title)) {
                 $track->title = $title;
             }
             if (!isset($track->albumName)) {
                 $track->albumName = $albumName;
             }
             if (!isset($track->artistName)) {
                 $track->artistName = $artistName;
             }
         }
         //insert/update artist
         $artist = new Artist();
         $track->artist = $artist->insertIfRequired($track->artistName, null);
         //insert/update album
         $album = new Album();
         $track->album = $album->insertIfRequired($track->albumName, null, $track->artist);
         //insert track
         if ($track->insert()) {
             //add to the returned array
             array_push($result, $track->structureData($track));
         }
     }
     //return inserted files
     return $result;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:80,代码来源:Track.php


注:本文中的Track::readId3方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。