Cómo leer etiquetas de archivos MP3


Quiero tener un programa que lea metadatos de un archivo MP3. Mi programa también debería poder editar estos metadatos. ¿Qué puedo hacer?

Tengo que buscar código fuente abierto. Pero tienen código; pero no idea simplificada para mi trabajo que van a hacer.

Cuando leí más encontré que los metadatos se almacenan en el propio archivo MP3. Pero todavía no soy capaz de hacer una idea completa de mi programa de bebé.

Cualquier ayuda será apreciada; con un programa o muy idea (como algoritmo). :)

Author: TuringTux, 2009-10-29

5 answers

Los últimos 128 bytes de un archivo mp3 contienen metadatos sobre el archivo mp3., Puede escribir un programa para leer los últimos 128 bytes...

ACTUALIZACIÓN:

Implementación de ID3v1

La información se almacena en los últimos 128 bytes de un MP3. etiqueta tiene los siguientes campos, y las compensaciones dadas aquí, son de 0-127.

 Field      Length    Offsets
 Tag        3           0-2
 Songname   30          3-32
 Artist     30         33-62
 Album      30         63-92
 Year       4          93-96
 Comment    30         97-126
 Genre      1           127

WARINING - Esta es solo una forma fea de obtener metadatos y podría no estar allí porque el mundo se ha movido a id3v2. id3v1 es en realidad obsoleto. Id3v2 es más complejo que esto, por lo que idealmente debería usar bibliotecas existentes para leer datos id3v2 de mp3s . Sólo estoy sacando esto.

 26
Author: Jaskirat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-29 20:27:43

Jd3lib es una biblioteca Java que maneja MP3 y sus etiquetas. Probablemente un punto de partida útil.

 14
Author: Brian Agnew,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-29 18:55:23

Http://www.id3.org/Implementations sería un buen lugar para comenzar

 12
Author: user197132,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-29 18:54:52

Puede utilizar apache tika Java API para el análisis de metadatos de MP3 como título, álbum, género, duración, compositor, artista y etc.. los tarros requeridos son tika-parsers-1.4, tika-core-1.4.

Programa De Ejemplo:

package com.parse.mp3;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.parser.mp3.Mp3Parser;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class AudioParser {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String fileLocation = "G:/asas/album/song.mp3";

        try {

        InputStream input = new FileInputStream(new File(fileLocation));
        ContentHandler handler = new DefaultHandler();
        Metadata metadata = new Metadata();
        Parser parser = new Mp3Parser();
        ParseContext parseCtx = new ParseContext();
        parser.parse(input, handler, metadata, parseCtx);
        input.close();

        // List all metadata
        String[] metadataNames = metadata.names();

        for(String name : metadataNames){
        System.out.println(name + ": " + metadata.get(name));
        }

        // Retrieve the necessary info from metadata
        // Names - title, xmpDM:artist etc. - mentioned below may differ based
        System.out.println("----------------------------------------------");
        System.out.println("Title: " + metadata.get("title"));
        System.out.println("Artists: " + metadata.get("xmpDM:artist"));
        System.out.println("Composer : "+metadata.get("xmpDM:composer"));
        System.out.println("Genre : "+metadata.get("xmpDM:genre"));
        System.out.println("Album : "+metadata.get("xmpDM:album"));

        } catch (FileNotFoundException e) {
        e.printStackTrace();
        } catch (IOException e) {
        e.printStackTrace();
        } catch (SAXException e) {
        e.printStackTrace();
        } catch (TikaException e) {
        e.printStackTrace();
        }
        }
    }
 10
Author: MAA,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-13 06:02:01

Para J2ME(que es con lo que estaba luchando), aquí está el código que funcionó para mí..

import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.*;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MetaDataControl;
import javax.microedition.midlet.MIDlet;

public class MetaDataControlMIDlet extends MIDlet implements CommandListener {
  private Display display = null;
  private List list = new List("Message", List.IMPLICIT);
  private Command exitCommand = new Command("Exit", Command.EXIT, 1);
  private Alert alert = new Alert("Message");
  private Player player = null;  

  public MetaDataControlMIDlet() {    
    display = Display.getDisplay(this);
    alert.addCommand(exitCommand);
    alert.setCommandListener(this);
    list.addCommand(exitCommand);
    list.setCommandListener(this);
    //display.setCurrent(list);

  }

  public void startApp() {
      try {
      FileConnection connection = (FileConnection) Connector.open("file:///e:/breathe.mp3");
      InputStream is = null;
      is = connection.openInputStream();
      player = Manager.createPlayer(is, "audio/mp3");
      player.prefetch();
      player.realize();
    } catch (Exception e) {
      alert.setString(e.getMessage());
      display.setCurrent(alert);
      e.printStackTrace();
    }

    if (player != null) {
      MetaDataControl mControl = (MetaDataControl) player.getControl("javax.microedition.media.control.MetaDataControl");
      if (mControl == null) {
        alert.setString("No Meta Information");
        display.setCurrent(alert);
      } else {
        String[] keys = mControl.getKeys();
        for (int i = 0; i < keys.length; i++) {
          list.append(keys[i] + " -- " + mControl.getKeyValue(keys[i]), null);
        }
        display.setCurrent(list);
      }
    }
  }

  public void commandAction(Command cmd, Displayable disp) {
    if (cmd == exitCommand) {
      notifyDestroyed();
    }
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

}
 2
Author: user1048839,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-24 18:43:07