My favorites | Sign in
Logo
                
Search
for
Updated Apr 02, 2009 by svollbehr
Labels: Phase-Implementation
ID3v1  
The Programmer's Reference Guide: ID3v1 Class

PHP-Reader Documentation: ID3v1 Class

By wphilipw, svollbehr

Introduction

ID3v1 class provides a fully standards compliant implementation of the ID3v1.0 and ID3v1.1 standards. The ID3 tag can be used with various files including MPEG Layer III, or MP3. The class is capable of both reading and writing tag information.

Table of Contents

Class Information

Examples

Example #1: How to read ID3v1 information

ID3v1 class functions just work and the only way to show that is to see them in action:

<?php
require_once("ID3v1.php");

$id3 = new ID3v1("file.mp3");
$val = $id3->getTitle(); // or getArtist, getAlbum, getYear, ...

The class also supports shorthands for getting and assigning field values. The above code could also be written as shown below.

$id3 = new ID3v1("file.mp3");
$val = $id3->title;      // or artist, album, year, ...

See the class documentation found in the source package for the documentation for all the available tag fields.

Example #2: How to write ID3v1 information

Writing new ID3v1 tags is as an easy task as reading them. One simply creates an instance of the class, assigns needed values and commits the changes.

<?php
require_once("ID3v1.php");

$id3 = new ID3v1();
$id3->setTitle("My song title");
$id3->write("file.mp3");

It is also possible to read current tag content, alter it and then rewrite it back to the media file.

<?php
require_once("ID3v1.php");

$id3 = new ID3v1("file.mp3");
$id3->setTitle("{$id3->getTitle()} by me!"); // append something to the title
$id3->setAlbum("My album");
$id3->write();

Similarly to when you read the tag information, you can also use the class shorthands to assign the information.

<?php
require_once("ID3v1.php");

$id3 = new ID3v1("file.mp3");
$id3->title = "{$id3->getTitle()} by me!"; // append something to the title
$id3->album = "My album";
$id3->genre = "Rock";                      // or $id3->genre = 17;

$id3->track = 5;                           // uses ID3v1.1 when track is given

$id3->write();

The ID3v1 class will automatically determine which version of the tag format to use based on whether you set a track or not. See the class documentation found in the source package for the documentation for all the available tag fields. Also, leave a comment if you come up with an idea for an example that would be nice to have added here!


Sign in to add a comment
Hosted by Google Code