Advertisement
Guest User

Untitled

a guest
May 28th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. /*ID3 tags for Wave files.
  2. ID3 (Identify a MP3) is metadata container most often used for MP3 audio files. ID3 signature contains information about the title track, album, artist name, etc. about the file to be stored in the file itself. Please see ID3.
  3.  
  4. Wave files can also store metadata similar ID3.
  5. The code below shows how to add, delete, and read metadata from the Wav files.*/
  6.  
  7. private void WaveTag()
  8.  
  9. {
  10.  
  11. string fileName = "in.wav";
  12.  
  13. WaveReadWriter wrw = new WaveReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite));
  14.  
  15. //removes INFO tags from audio stream
  16.  
  17. wrw.WriteInfoTag(null);
  18.  
  19. //writes INFO tags into audio stream
  20.  
  21. Dictionary<WaveInfo, string> tag = new Dictionary<WaveInfo, string>();
  22.  
  23. tag[WaveInfo.Comments] = "Comments...";
  24.  
  25. wrw.WriteInfoTag(tag);
  26.  
  27. wrw.Close();
  28.  
  29. //reads INFO tags from audio stream
  30.  
  31. WaveReader wr = new WaveReader(File.OpenRead(fileName));
  32.  
  33. Dictionary<WaveInfo, string> dir = wr.ReadInfoTag();
  34.  
  35. wr.Close();
  36.  
  37. if (dir.Count > 0)
  38.  
  39. {
  40.  
  41. foreach (string val in dir.Values)
  42.  
  43. {
  44.  
  45. Console.WriteLine(val);
  46.  
  47. }
  48.  
  49. }
  50.  
  51. }
  52.  
  53. //In addition, we show how to do the same for mp3 files with ID3 Tag V1.0
  54.  
  55. private void Mp3Tag()
  56.  
  57. {
  58.  
  59. string fileName = "in.mp3";
  60.  
  61. Mp3ReadWriter mrw = new Mp3ReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite));
  62.  
  63. //removes ID3v1 tags from audio stream
  64.  
  65. mrw.WriteID3v1Tag(null);
  66.  
  67. //writes ID3v1 tags into audio stream
  68.  
  69. ID3v1 tag = new ID3v1();
  70.  
  71. tag.Comment = "Comment...";
  72.  
  73. mrw.WriteID3v1Tag(tag);
  74.  
  75. mrw.Close();
  76.  
  77. //reads ID3v1 tags from audio stream
  78.  
  79. Mp3Reader mr = new Mp3Reader(File.OpenRead(fileName));
  80.  
  81. ID3v1 id3v1 = mr.ReadID3v1Tag();
  82.  
  83. mr.Close();
  84.  
  85. if (id3v1 != null)
  86.  
  87. {
  88.  
  89. Console.WriteLine(id3v1.Comment);
  90.  
  91. }
  92.  
  93. }
  94.  
  95. //Audio Library needed for this example is here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement