This class implements IAudioCodec and and combines codecs to create generic media properties for a file.
Inheritance: IAudioCodec, IVideoCodec
Exemple #1
0
        public AudioFile(string nameOnServer, string serverPath, TagLib.Tag tag, TagLib.Properties properties)
        {
            this.NameOnServer = nameOnServer;
            this.Title        = tag.Title;

            //this.Path = string.Format("/AudioFiles/{0}", tag.Title);
            this.ServerPath = serverPath;
            this.Duration   = properties.Duration;
            this.DateAdded  = DateTime.Now;
        }
 private void Read(bool read_tags, ReadStyle style, out uint aiff_size, out long tag_start, out long tag_end)
 {
     base.Seek(0L);
     if (base.ReadBlock(4) != FileIdentifier)
     {
         throw new CorruptFileException("File does not begin with AIFF identifier");
     }
     aiff_size = base.ReadBlock(4).ToUInt(true);
     tag_start = -1L;
     tag_end = -1L;
     if ((this.header_block == null) && (style != ReadStyle.None))
     {
         long offset = base.Find(CommIdentifier, 0L);
         if (offset == -1L)
         {
             throw new CorruptFileException("No Common chunk available in AIFF file.");
         }
         base.Seek(offset);
         this.header_block = base.ReadBlock(0x1a);
         StreamHeader header = new StreamHeader(this.header_block, (long) ((ulong) aiff_size));
         ICodec[] codecs = new ICodec[] { header };
         this.properties = new TagLib.Properties(TimeSpan.Zero, codecs);
     }
     long num2 = -1L;
     if (base.Find(SoundIdentifier, 0L, ID3Identifier) == -1L)
     {
         num2 = base.Find(ID3Identifier, 0L);
     }
     long num3 = base.Find(SoundIdentifier, 0L);
     if (num3 == -1L)
     {
         throw new CorruptFileException("No Sound chunk available in AIFF file.");
     }
     base.Seek(num3 + 4L);
     long startPosition = (((long) base.ReadBlock(4).ToULong(true)) + num3) + 4L;
     if (num2 == -1L)
     {
         num2 = base.Find(ID3Identifier, startPosition);
     }
     if (num2 > -1L)
     {
         if (read_tags && (this.tag == null))
         {
             this.tag = new TagLib.Id3v2.Tag(this, num2 + 8L);
         }
         base.Seek(num2 + 4L);
         uint num6 = base.ReadBlock(4).ToUInt(true) + 8;
         long num7 = num2;
         base.InvariantStartPosition = num7;
         tag_start = num7;
         num7 = tag_start + num6;
         base.InvariantEndPosition = num7;
         tag_end = num7;
     }
 }
        public MidiFile(string name) : base("")
        {
            this.tag = new MidiTag();
            TagLib.Tag tag      = this.tag;
            char[]     chrArray = new char[] { '\\' };
            tag.Title = name.Split(chrArray).Last <string>();
            MediaPlayer mediaPlayer = new MediaPlayer();

            mediaPlayer.Open(new Uri(name));
            while (!mediaPlayer.NaturalDuration.HasTimeSpan)
            {
            }
            Duration naturalDuration = mediaPlayer.NaturalDuration;

            this.properties = new TagLib.Properties(naturalDuration.TimeSpan, new ICodec[0]);
        }
Exemple #4
0
 public void UpdateInfoFromFile(string fp)
 {
     try
     {
         using (TagLib.File f = TagLib.File.Create(Location))
         {
             f.RemoveTags(f.TagTypes & ~f.TagTypesOnDisk); // read tags and their versions as is from file
             this.Size       = (decimal)f.InvariantEndPosition;
             this.Tags       = f.Tag;
             this.Properties = f.Properties;
         }
     }
     catch (Exception ex)
     {
         DebugHelper.WriteException(ex, "Error reading info from file");
     }
 }
 private void Read(ReadStyle propertiesStyle)
 {
     long num;
     Dictionary<uint, Bitstream> dictionary = this.ReadStreams(null, out num);
     List<ICodec> codecs = new List<ICodec>();
     base.InvariantStartPosition = num;
     base.InvariantEndPosition = base.Length;
     foreach (uint num2 in dictionary.Keys)
     {
         this.tag.AddComment(num2, dictionary[num2].Codec.CommentData);
         codecs.Add(dictionary[num2].Codec);
     }
     if (propertiesStyle != ReadStyle.None)
     {
         PageHeader lastPageHeader = this.LastPageHeader;
         TimeSpan duration = dictionary[lastPageHeader.StreamSerialNumber].GetDuration(lastPageHeader.AbsoluteGranularPosition);
         this.properties = new TagLib.Properties(duration, codecs);
     }
 }
 private void Read(ReadStyle propertiesStyle)
 {
     base.Mode = TagLib.File.AccessMode.Read;
     try
     {
         this.tag = new TagLib.NonContainer.Tag(this);
         base.InvariantStartPosition = this.tag.ReadStart();
         base.TagTypesOnDisk |= this.StartTag.TagTypes;
         this.ReadStart(base.InvariantStartPosition, propertiesStyle);
         base.InvariantEndPosition = (base.InvariantStartPosition != base.Length) ? this.tag.ReadEnd() : base.Length;
         base.TagTypesOnDisk |= this.EndTag.TagTypes;
         this.ReadEnd(base.InvariantEndPosition, propertiesStyle);
         this.properties = (propertiesStyle == ReadStyle.None) ? null : this.ReadProperties(base.InvariantStartPosition, base.InvariantEndPosition, propertiesStyle);
     }
     finally
     {
         base.Mode = TagLib.File.AccessMode.Closed;
     }
 }
Exemple #7
0
		/// <summary>
		///    Reads the information from file with a specified read style.
		/// </summary>
		/// <param name="propertiesStyle">
		///    A <see cref="ReadStyle" /> value specifying at what level
		///    of accuracy to read the media properties, or <see
		///    cref="ReadStyle.None" /> to ignore the properties.
		/// </param>
		private void Read (ReadStyle propertiesStyle)
		{
			Mode = AccessMode.Read;
			try {
				ImageTag = new CombinedImageTag (TagTypes.XMP | TagTypes.Png);

				ValidateHeader ();
				ReadMetadata ();

				TagTypesOnDisk = TagTypes;

				if (propertiesStyle != ReadStyle.None)
					properties = ExtractProperties ();

			} finally {
				Mode = AccessMode.Closed;
			}
		}
        /// <summary>
        ///    Reads the information from file with a specified read style.
        /// </summary>
        /// <param name="propertiesStyle">
        ///    A <see cref="ReadStyle" /> value specifying at what level
        ///    of accuracy to read the media properties, or <see
        ///    cref="ReadStyle.None" /> to ignore the properties.
        /// </param>
        private void Read(ReadStyle propertiesStyle)
        {
            Mode = AccessMode.Read;
            try {
                ImageTag = new CombinedImageTag (TagTypes.TiffIFD);

                ReadFile ();

                TagTypesOnDisk = TagTypes;

                if (propertiesStyle != ReadStyle.None)
                    properties = ExtractProperties ();

            } finally {
                Mode = AccessMode.Closed;
            }
        }
        private void Obtener_Tag(string ruta)
        {
            TagLib.File PistaMp3 = TagLib.File.Create(ruta);

            try { indice = PistaMp3.Tag.Track.Equals(0) ? indice = Buscar_Indice(Titulo) : indice = (int)PistaMp3.Tag.Track; }
            catch { indice = 0; }

            try
            {
                if (!PistaMp3.Tag.Title.Equals(string.Empty))
                    Titulo = PistaMp3.Tag.Title;
            }
            catch
            {
                Titulo = string.Empty;
            }

            try
            {
                CaratulaAlbum = Image.FromStream(new MemoryStream(PistaMp3.Tag.Pictures.ToList().Find(x => x.Type.ToString() == "FrontCover").Data.Data));
            }
            catch
            {
                CaratulaAlbum = null;
            }

            tagCancion = PistaMp3.Tag;
            propiedades = PistaMp3.Properties;

            PistaMp3.Dispose();
        }
        private void Read(bool read_tags, ReadStyle style, out uint riff_size, out long tag_start, out long tag_end)
        {
            bool flag;
            base.Seek(0L);
            if (base.ReadBlock(4) != FileIdentifier)
            {
                throw new CorruptFileException("File does not begin with RIFF identifier");
            }
            riff_size = base.ReadBlock(4).ToUInt(false);
            ByteVector vector = base.ReadBlock(4);
            tag_start = -1L;
            tag_end = -1L;
            long offset = 12L;
            long length = base.Length;
            uint num3 = 0;
            TimeSpan zero = TimeSpan.Zero;
            ICodec[] codecs = new ICodec[0];
        Label_0066:
            flag = false;
            base.Seek(offset);
            string str = base.ReadBlock(4).ToString(StringType.UTF8);
            num3 = base.ReadBlock(4).ToUInt(false);
            string key = str;
            if (key != null)
            {
                Dictionary<string, int> dictionary;
                int num4;
                if (<>f__switch$map3 == null)
                {
                    dictionary = new Dictionary<string, int>(6);
                    dictionary.Add("fmt ", 0);
                    dictionary.Add("data", 1);
                    dictionary.Add("LIST", 2);
                    dictionary.Add("ID32", 3);
                    dictionary.Add("IDVX", 4);
                    dictionary.Add("JUNK", 5);
                    <>f__switch$map3 = dictionary;
                }
                if (<>f__switch$map3.TryGetValue(key, out num4))
                {
                    switch (num4)
                    {
                        case 0:
                            if ((style != ReadStyle.None) && (vector == "WAVE"))
                            {
                                base.Seek(offset + 8L);
                                codecs = new ICodec[] { new WaveFormatEx(base.ReadBlock(0x12), 0) };
                                break;
                            }
                            break;

                        case 1:
                            if (vector == "WAVE")
                            {
                                base.InvariantStartPosition = offset;
                                base.InvariantEndPosition = offset + num3;
                                if (((style != ReadStyle.None) && (codecs.Length == 1)) && (codecs[0] is WaveFormatEx))
                                {
                                    WaveFormatEx ex = (WaveFormatEx) codecs[0];
                                    zero += TimeSpan.FromSeconds(((double) num3) / ((double) ex.AverageBytesPerSecond));
                                }
                                break;
                            }
                            break;

                        case 2:
                        {
                            string str3 = base.ReadBlock(4).ToString(StringType.UTF8);
                            if (str3 != null)
                            {
                                int num5;
                                if (<>f__switch$map2 == null)
                                {
                                    dictionary = new Dictionary<string, int>(4);
                                    dictionary.Add("hdrl", 0);
                                    dictionary.Add("INFO", 1);
                                    dictionary.Add("MID ", 2);
                                    dictionary.Add("movi", 3);
                                    <>f__switch$map2 = dictionary;
                                }
                                if (<>f__switch$map2.TryGetValue(str3, out num5))
                                {
                                    switch (num5)
                                    {
                                        case 0:
                                            if ((style != ReadStyle.None) && (vector == "AVI "))
                                            {
                                                AviHeaderList list = new AviHeaderList(this, offset + 12L, ((int) num3) - 4);
                                                zero = list.Header.Duration;
                                                codecs = list.Codecs;
                                                break;
                                            }
                                            goto Label_040E;

                                        case 1:
                                            if (read_tags && (this.info_tag == null))
                                            {
                                                this.info_tag = new InfoTag(this, offset + 12L, ((int) num3) - 4);
                                            }
                                            flag = true;
                                            break;

                                        case 2:
                                            if (read_tags && (this.mid_tag == null))
                                            {
                                                this.mid_tag = new MovieIdTag(this, offset + 12L, ((int) num3) - 4);
                                            }
                                            flag = true;
                                            break;

                                        case 3:
                                            if (vector == "AVI ")
                                            {
                                                base.InvariantStartPosition = offset;
                                                base.InvariantEndPosition = offset + num3;
                                                break;
                                            }
                                            break;
                                    }
                                }
                            }
                            break;
                        }
                        case 3:
                            if (read_tags && (this.id32_tag == null))
                            {
                                this.id32_tag = new TagLib.Id3v2.Tag(this, offset + 8L);
                            }
                            flag = true;
                            break;

                        case 4:
                            if (read_tags && (this.divx_tag == null))
                            {
                                this.divx_tag = new DivXTag(this, offset + 8L);
                            }
                            flag = true;
                            break;

                        case 5:
                            if (tag_end == offset)
                            {
                                tag_end = (offset + 8L) + num3;
                            }
                            break;
                    }
                }
            }
            if (flag)
            {
                if (tag_start == -1L)
                {
                    tag_start = offset;
                    tag_end = (offset + 8L) + num3;
                }
                else if (tag_end == offset)
                {
                    tag_end = (offset + 8L) + num3;
                }
            }
        Label_040E:
            if (((offset += (8 + num3)) + 8L) < length)
            {
                goto Label_0066;
            }
            if (style != ReadStyle.None)
            {
                if (codecs.Length == 0)
                {
                    throw new UnsupportedFormatException("Unsupported RIFF type.");
                }
                this.properties = new TagLib.Properties(zero, codecs);
            }
            if (read_tags)
            {
                TagLib.Tag[] tags = new TagLib.Tag[] { this.id32_tag, this.info_tag, this.mid_tag, this.divx_tag };
                this.tag.SetTags(tags);
            }
        }
 private void Read(ReadStyle propertiesStyle)
 {
     this.tag = new CombinedTag();
     base.Mode = TagLib.File.AccessMode.Read;
     try
     {
         FileParser parser = new FileParser(this);
         if (propertiesStyle == ReadStyle.None)
         {
             parser.ParseTag();
         }
         else
         {
             parser.ParseTagAndProperties();
         }
         base.InvariantStartPosition = parser.MdatStartPosition;
         base.InvariantEndPosition = parser.MdatEndPosition;
         this.udta_box = parser.UserDataBox;
         if (((this.udta_box != null) && (this.udta_box.GetChild(BoxType.Meta) != null)) && (this.udta_box.GetChild(BoxType.Meta).GetChild(BoxType.Ilst) != null))
         {
             base.TagTypesOnDisk |= TagTypes.Apple;
         }
         if (this.udta_box == null)
         {
             this.udta_box = new IsoUserDataBox();
         }
         this.apple_tag = new AppleTag(this.udta_box);
         TagLib.Tag[] tags = new TagLib.Tag[] { this.apple_tag };
         this.tag.SetTags(tags);
         if (propertiesStyle == ReadStyle.None)
         {
             base.Mode = TagLib.File.AccessMode.Closed;
         }
         else
         {
             IsoMovieHeaderBox movieHeaderBox = parser.MovieHeaderBox;
             if (movieHeaderBox == null)
             {
                 base.Mode = TagLib.File.AccessMode.Closed;
                 throw new CorruptFileException("mvhd box not found.");
             }
             IsoAudioSampleEntry audioSampleEntry = parser.AudioSampleEntry;
             IsoVisualSampleEntry visualSampleEntry = parser.VisualSampleEntry;
             ICodec[] codecs = new ICodec[] { audioSampleEntry, visualSampleEntry };
             this.properties = new TagLib.Properties(movieHeaderBox.Duration, codecs);
         }
     }
     finally
     {
         base.Mode = TagLib.File.AccessMode.Closed;
     }
 }
Exemple #12
0
        public ID3FileInfo(string path, bool deepLoad)
            : base(path, false)
        {
            if (IsValid)
            {
                try
                {
                    af = new TagLib.Mpeg.AudioFile(path, ReadStyle.Average);

                    if (deepLoad)
                    {
                        // This will actually toggle reading the audio header
                        TimeSpan duration = af.Properties.Duration;
                        _deepLoad = true;
                    }

                    _tag = af.Tag;
                    _prop = af.Properties;
                }
                catch
                {
                }

                _tagModified = false;
            }
        }