开发者

Automatically generate playlist with php

开发者 https://www.devze.com 2022-12-19 20:07 出处:网络
I generate a playlist with following script: <?php $dir= \'./music\'; $url= \'music\'; header(\'Content-type: text/xml\');

I generate a playlist with following script:

   <?php 
$dir        = './music';
$url        = 'music';

header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
echo '<playlist>';
if (is_dir($dir)) {
    $dp = opendir($dir);
    while (false !== ($file = readdir($dp))){       
        if ('mp3'==strtolower(substr($file, -3))) {                开发者_开发技巧     
            printf('<sound src="%s/%s" stream="true" soundbuffer="8">%s</sound>', $url, $file, str_replace('_', ' ', substr($file, 0, -4)));
            echo "\n";
        }        
    }
    closedir($dp);
}
echo '</playlist>';

How do I get the artist and length from each mp3 file?

Thanks in advance


You need to parse the file and extract the data. It can't give you any more info as you haven't indicated the ID3 version (and there are several). Wikipedia has information on the diffrences between ID3v1 and v2

A better option would be to use a library, something like ID3 or getID3


Have a look at this library.

http://getid3.sourceforge.net/

That will get you the artist and the title as well as length.


Take a look at this site also

http://www.refdev.com/free_scripts/PHP/Audio_Management/


You can also use this function here to read mp3 id3 tags:

http://www.barattalo.it/2010/02/22/reading-mp3-informations-with-php-id3-tags/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号