public static void SaveInfo() { string filename = "fileinfo.txt"; Debug.Print("Writing ID3 info to " + filename); if (File.Exists(@"\SD\" + filename)) { File.Delete(@"\SD\" + filename); } using (FileStream fs = new FileStream(@"\SD\" + filename, FileMode.OpenOrCreate, FileAccess.Write)) { StreamWriter sw = new StreamWriter(fs); foreach (string track in DirectoryEx.GetFiles(@"\USB\")) { if (track.Length > 4 && track.Substring(track.Length - 3).ToLower() == "mp3") { ID3Tag temp = ID3TagReader.ReadFile(track); sw.WriteLine(temp.Path + "|" + temp.Artist + "|" + temp.Album + "|" + temp.Title); temp.Dispose(); } } sw.Close(); fs.Close(); } LED.State = LEDState.Ready; Debug.Print("Finished writing to file"); }
// Create an ID3Tag void CreateTag() { PrivateObject accessor = new PrivateObject(typeof(ID3Tag)); accessor.SetFieldOrProperty("Artist", "Artist"); accessor.SetFieldOrProperty("Album", "Album"); accessor.SetFieldOrProperty("Title", "Title"); accessor.SetFieldOrProperty("Comment", "Comment"); accessor.SetFieldOrProperty("Year", "Year"); accessor.SetFieldOrProperty("Genre", "Genre"); tag = (ID3Tag)accessor.Target; }
private void SetTagContent(ID3Tag tag, bool overwriteExistingTags) { if (!tag.HasTitle || overwriteExistingTags) { tag.Title = TrackTitleTag; } if (!tag.HasAlbum || overwriteExistingTags) { tag.Album = AlbumTag; } if (!tag.HasArtist || overwriteExistingTags) { tag.Artist = ArtistTag; } if (!tag.HasGenre || overwriteExistingTags) { tag.Genre = GenreTag; } }
private void ReadTagsFromFile() { if (Status != ItemStatus.Complete) { return; } if (!CompleteDestination.EndsWith(".mp3", StringComparison.CurrentCultureIgnoreCase)) { return; } try { ID3Tag tag = ID3v2Tag.ReadTag(CompleteDestination); if (tag == null) { tag = ID3v1Tag.ReadTag(CompleteDestination); if (tag == null) { tag = new ID3v2Tag(); } } TrackTitleTag = tag.Title; AlbumTag = tag.Album; ArtistTag = tag.Artist; GenreTag = tag.Genre; _tagsSet = true; } catch (Exception ex) { Trace.TraceError("Error: unable to read ID3 Tag for file: " + CompleteDestination + ". " + ex.Message); } }
public Mp3Decoder(string mp3File) { // encoder modules lame = new Lame(); gaud = new GetAudio(); ga = new GainAnalysis(); bs = new BitStream(); p = new Presets(); qupvt = new QuantizePVT(); qu = new Quantize(); vbr = new VBRTag(); ver = new Mp3Version(); id3 = new ID3Tag(); rv = new Reservoir(); tak = new Takehiro(); parse = new Parse(); mpg = new MPGLib(); intf = new Interface(); common = new Mpg.Common(); lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg); bs.setModules(ga, mpg, ver, vbr); id3.setModules(bs, ver); p.Modules = lame; qu.setModules(bs, rv, qupvt, tak); qupvt.setModules(tak, rv, lame.enc.psy); rv.Modules = bs; tak.Modules = qupvt; vbr.setModules(lame, bs, ver); gaud.setModules(parse, mpg); parse.setModules(ver, id3, p); // decoder modules mpg.setModules(intf, common); intf.setModules(vbr, common); gfp = lame.lame_init(); /* * turn off automatic writing of ID3 tag data into mp3 stream we have to * call it before 'lame_init_params', because that function would spit * out ID3v2 tag data. */ gfp.write_id3tag_automatic = false; /* * Now that all the options are set, lame needs to analyze them and set * some more internal options and check for problems */ lame.lame_init_params(gfp); parse.input_format = GetAudio.sound_file_format.sf_mp3; var inPath = new StringBuilder(mp3File); var enc = new Enc(); gaud.init_infile(gfp, inPath.ToString(), enc); var skip_start = 0; var skip_end = 0; if (parse.silent < 10) { Console.Write( "\rinput: {0}{1}({2:g} kHz, {3:D} channel{4}, ", inPath, inPath.Length > 26 ? "\n\t" : " ", gfp.in_samplerate / 1000, gfp.num_channels, gfp.num_channels != 1 ? "s" : ""); } if (enc.enc_delay > -1 || enc.enc_padding > -1) { if (enc.enc_delay > -1) { skip_start = enc.enc_delay + 528 + 1; } if (enc.enc_padding > -1) { skip_end = enc.enc_padding - (528 + 1); } } else { skip_start = gfp.encoder_delay + 528 + 1; } Console.Write("MPEG-{0:D}{1} Layer {2}", 2 - gfp.version, gfp.out_samplerate < 16000 ? ".5" : "", "III"); Console.Write(")\noutput: (16 bit, Microsoft WAVE)\n"); if (skip_start > 0) { Console.Write("skipping initial {0:D} samples (encoder+decoder delay)\n", skip_start); } if (skip_end > 0) { Console.Write("skipping final {0:D} samples (encoder padding-decoder delay)\n", skip_end); } wavsize = -(skip_start + skip_end); parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize; Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2); }
public bool WriteTagsToFile(bool overwriteExistingTags) { if (Status != ItemStatus.Complete) { return(false); } if (!CompleteDestination.EndsWith(".mp3", StringComparison.CurrentCultureIgnoreCase)) { return(false); } try { ID3Tag tag = null; switch (ID3v2Tag.LookForTag(CompleteDestination)) { case ID3Versions.None: case ID3Versions.Unknown: default: tag = new ID3v2Tag(); SetTagContent(tag, overwriteExistingTags); tag.WriteTag(CompleteDestination, ID3Versions.V2_4); break; case ID3Versions.V1: case ID3Versions.V1_0: case ID3Versions.V1_1: tag = ID3v1Tag.ReadTag(CompleteDestination); SetTagContent(tag, overwriteExistingTags); tag.WriteTag(CompleteDestination, ID3Versions.V1_1); break; case ID3Versions.V2: case ID3Versions.V2_2: case ID3Versions.V2_3: tag = ID3v2Tag.ReadTag(CompleteDestination); SetTagContent(tag, overwriteExistingTags); tag.WriteTag(CompleteDestination, ID3Versions.V2_3); break; case ID3Versions.V2_4: tag = ID3v2Tag.ReadTag(CompleteDestination); SetTagContent(tag, overwriteExistingTags); tag.WriteTag(CompleteDestination, ID3Versions.V2_4); break; } } catch (Exception ex) { Trace.TraceError("Error writing tags to: " + CompleteDestination + ". " + ex.Message); return(false); } return(true); }
public Mp3Decoder(Stream mp3Stream) { // encoder modules lame = new Lame(); gaud = new GetAudio(); ga = new GainAnalysis(); bs = new BitStream(); p = new Presets(); qupvt = new QuantizePVT(); qu = new Quantize(); vbr = new VBRTag(); ver = new Mp3Version(); id3 = new ID3Tag(); rv = new Reservoir(); tak = new Takehiro(); parse = new Parse(); mpg = new MPGLib(); intf = new Interface(); common = new Mpg.Common(); lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg); bs.setModules(ga, mpg, ver, vbr); id3.setModules(bs, ver); p.Modules = lame; qu.setModules(bs, rv, qupvt, tak); qupvt.setModules(tak, rv, lame.enc.psy); rv.Modules = bs; tak.Modules = qupvt; vbr.setModules(lame, bs, ver); gaud.setModules(parse, mpg); parse.setModules(ver, id3, p); // decoder modules mpg.setModules(intf, common); intf.setModules(vbr, common); gfp = lame.lame_init(); /* * turn off automatic writing of ID3 tag data into mp3 stream we have to * call it before 'lame_init_params', because that function would spit * out ID3v2 tag data. */ gfp.write_id3tag_automatic = false; /* * Now that all the options are set, lame needs to analyze them and set * some more internal options and check for problems */ lame.lame_init_params(gfp); parse.input_format = GetAudio.sound_file_format.sf_mp3; var enc = new Enc(); gaud.init_infile(gfp, mp3Stream, enc); SkipStart = 0; SkipEnd = 0; if (enc.enc_delay > -1 || enc.enc_padding > -1) { if (enc.enc_delay > -1) { SkipStart = enc.enc_delay + 528 + 1; } if (enc.enc_padding > -1) { SkipEnd = enc.enc_padding - (528 + 1); } } else { SkipStart = gfp.encoder_delay + 528 + 1; } WavSize = -(SkipStart + SkipEnd); parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize; Framesize = parse.mp3input_data.framesize; SampleRate = parse.mp3input_data.samplerate; Length = parse.mp3input_data.nsamp; Channels = gfp.num_channels; Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2); }
public Song(string path) { Path = path; Id3Tag = new ID3Tag(Path); }