Grow your CSS skills. Land your dream job.

MP3 ID3 Tags

  • # July 3, 2010 at 1:51 am

    So I am trying to write a script where it browses a folder and gets all the mp3 id3 data for all the mp3′s in the folder.

    Code:
    < ?php

    $dir = TEMPLATEPATH . "/flash/music/";

    if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
    while (($fileread = readdir($dh)) !== false) {
    if($fileread == "." || $fileread == ".." || $fileread == "index.php" )
    continue;

    $fullpath = $dir . $fileread;
    echo "filename: $fullpath“;
    echo “
    “;

    $musicfile = $fullpath;
    fopen($fullpath, ‘r’);
    fseek($musicfile, -128, SEEK_END);

    $tag = fread($musicfile, 3);

    if($tag == “TAG”)
    {
    $data["song"] = trim(fread($musicfile, 30));
    $data["artist"] = trim(fread($musicfile, 30));
    $data["album"] = trim(fread($musicfile, 30));
    }
    else
    die(“MP3 file does not have any ID3 tag!”);

    fclose($musicfile);

    while(list($key, $value) = each($data))
    {
    print(“$key: $value
    rn”);
    }
    }
    }
    }

    ?>

    Its not working. I get this error:

    Code:
    filename: /[my_server_path]/public_html/new/wp-content/themes/default/flash/music/09 Low.mp3

    Warning: fseek(): supplied argument is not a valid stream resource in /[my_server_path]/public_html/new/wp-content/themes/default/functions.php on line 1039

    Warning: fread(): supplied argument is not a valid stream resource in /[my_server_path]/public_html/new/wp-content/themes/default/functions.php on line 1041
    MP3 file does not have any ID3 tag!

    Any help?

    Thanks.

    # July 3, 2010 at 12:17 pm

    Ok so I changed it to this:

    Code:
    < ?php

    $dir = TEMPLATEPATH . "/flash/music/";

    if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
    while (($fileread = readdir($dh)) !== false) {
    if($fileread == "." || $fileread == ".." || $fileread == "index.php" )
    continue;

    $fullpath = $dir . $fileread;

    $musicfile = fopen($fullpath, 'r');
    fseek($musicfile, -128, SEEK_END);

    $tag = fread($musicfile, 3);

    if($tag == "TAG")
    {
    $data["song"] = trim(fread($musicfile, 30));
    $data["artist"] = trim(fread($musicfile, 30));
    $data["album"] = trim(fread($musicfile, 30));
    }
    else
    {
    echo "MP3 file does not have any ID3 tag!";

    }

    fclose($musicfile);

    while(list($key, $value) = each($data))
    {
    print("$key: $value
    rn”);
    }
    }
    }
    }

    ?>

    and its returning this:
    MP3 file does not have any ID3 tag!
    Warning: Variable passed to each() is not an array or object in /[my_server_path]/public_html/new/wp-content/themes/default/functions.php on line 1053
    song: X&Y
    artist: Coldplay
    album: X&Y

    So oddly enough it only retrieves the second songs id3 data.
    Any ideas?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Projects

*May or may not contain any actual "CSS" or "Tricks".