Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can i get the ID3 info on MP3s

How can i get the ID3 info on MP3s

Scheduled Pinned Locked Moved C#
questioncsharp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    visiontec
    wrote on last edited by
    #1

    How can i get all the relavant info from an MP3 file using C#? like the ID3 tag and the other MPEG info? And also how can i edit it? VisionTec

    L 1 Reply Last reply
    0
    • V visiontec

      How can i get all the relavant info from an MP3 file using C#? like the ID3 tag and the other MPEG info? And also how can i edit it? VisionTec

      L Offline
      L Offline
      Leon van Wyk
      wrote on last edited by
      #2

      This is not perfect but it works. namespace id3 { using System; using System.IO; using System.Text; class FileCommands { public static void GetMP3Tag (ref MP3 paramMP3) { try { // Read the 128 byte ID3 tag into a byte array FileStream oFileStream; oFileStream = new FileStream(paramMP3.fileComplete , FileMode.Open); byte[] bBuffer = new byte[128]; oFileStream.Seek(-128, SeekOrigin.End); oFileStream.Read(bBuffer,0, 128); oFileStream.Close(); // Convert the Byte Array to a String Encoding instEncoding = new ASCIIEncoding(); // NB: Encoding is an Abstract class string id3Tag = instEncoding.GetString(bBuffer); // If there is an attched ID3 v1.x TAG then read it if (id3Tag .Substring(0,3) == "TAG") { paramMP3.id3Title = id3Tag.Substring( 3, 30).Trim(); paramMP3.id3Artist = id3Tag.Substring( 33, 30).Trim(); paramMP3.id3Album = id3Tag.Substring( 63, 30).Trim(); paramMP3.id3Year = id3Tag.Substring( 93, 4).Trim(); paramMP3.id3Comment = id3Tag.Substring( 97,28).Trim(); // Get the track number if TAG conforms to ID3 v1.1 if (id3Tag[125]==0) paramMP3.id3TrackNumber = bBuffer[126]; else paramMP3.id3TrackNumber = 0; paramMP3.id3Genre = bBuffer[127]; paramMP3.hasID3Tag = true; // ********* IF USED IN ANGER: ENSURE to test for non-numeric year } else { // ID3 Tag not found so create an empty TAG in case the user saces later paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf(".")); paramMP3.id3Artist = ""; paramMP3.id3Album = ""; paramMP3.id3Year = ""; paramMP3.id3Comment = ""; paramMP3.id3TrackNumber = 0; paramMP3.id3Genre = 0; paramMP3.hasID3Tag = false; } } catch { // ID3 Tag not found so create an empty TAG in case the user saces later paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf(".")); paramMP3.id3Artist = ""; paramMP3.id3Album = ""; paramMP3.id3Year = ""; paramMP3.id3Comment = ""; paramMP3.id3TrackNumber = 0; paramMP3.id3Genre = 0; paramMP3.hasID3Tag = false; } } public static void UpdateMP3Tag (ref MP3 paramMP3) { // Trim any whitespace paramMP3.id3Title = paramMP3.id3Title.Trim(); paramMP3.id3Artist =

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups