public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            long pos = reader.BaseStream.Position;

            base.Read(reader);
            for (int i = 0; i < 2; i++) reader.ReadUInt32();  // unsigned int(32)[2] reserved = 0
            ChannelCount = reader.ReadUInt16();
            SampleSize = reader.ReadUInt16();
            PreDefined = reader.ReadUInt16(); // unsigned int(16) pre_defined = 0
            reader.ReadUInt16(); // unsigned int(16) reserved = 0
            SampleRate = reader.ReadUInt32() >> 16;

              // read esds or avcc boxes
            BoxType bt = reader.PeekNextBoxType();
            switch (bt.ToString().ToLower())
            {
            case "esds": // AudioSampleEntry type is mp4a (denotes AAC encoding)
            case "avcc":
                PrivDataFullBox = new AnyPrivFullBox(bt, string.Empty);
                PrivDataFullBox.Read(reader);
                break;
            case "wfex": // AudioSampleEntry type is wma
                PrivDataBox = new AnyPrivBox(bt, string.Empty);
                PrivDataBox.Read(reader);
                break;
               case "damr": // 3gpp sound
                PrivDataFullBox = new AnyPrivFullBox(bt, string.Empty);
                PrivDataFullBox.Read(reader);
                break;
            default:
                throw new Exception(string.Format("AudioSampleEntry has unknown contents: {0}", bt.ToString()));
            }
              }
        }
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            long startpos = reader.BaseStream.Position;

            base.Read(reader);
            reader.ReadUInt16(); // pre_defined = 0;
            reader.ReadUInt16(); // reserved = 0;
            for (int i = 0; i < 3; i++) reader.ReadUInt32();  // unsigned int(32)[3] pre_defined = 0
            Width = reader.ReadUInt16();
            Height = reader.ReadUInt16();
            HorizResolution = reader.ReadUInt32(); // = 0x0048000 = 72 dpi
            VertResolution = reader.ReadUInt32(); // = 0x0048000 = 72 dpi
            reader.ReadUInt32(); // reserved = 0
            FrameCount = reader.ReadUInt16(); // frame_count = 1

            // Compressor name has first 2 bytes which is the readable length, the rest are char's or null bytes
            CompressorName = "";
            ushort len = reader.ReadUInt16();
            // NOTE: Some encoders use only one byte for count of compressor name, so here
            // we test for whether the length is valid. If not valid, only the first byte is
            // used as the length.
            if (len > 30)
            {
              byte[] b = BitConverter.GetBytes(len);
              if (BitConverter.IsLittleEndian)
              {
            len = (ushort)b[1];
            CompressorName += (char)b[0];
              }
              else
              {
            len = (ushort)b[0];
            CompressorName += (char)b[1];
              }
            }
            for (int i=0; i<30; i++) {
              if (i < len)
            CompressorName += reader.ReadChar();
              else
            reader.ReadChar();
            }
            CompressorName = CompressorName.Trim().Replace("\0","");
            Depth = reader.ReadUInt16(); // depth = 0x0018
            reader.ReadUInt16();  // pre_defined = -1

            bool bOptionalBoxFound = true;
            while (bOptionalBoxFound) {
              bOptionalBoxFound = false;
              long pos = reader.BaseStream.Position;
              Box test = new Box(BoxTypes.Any);
              test.Read(reader);
              reader.BaseStream.Position = pos;

              if (test.Type == BoxTypes.CleanApertureBox) {
            CleanApertureBox = new CleanApertureBox();
            CleanApertureBox.Read(reader);
            bOptionalBoxFound = true;
              } else

              if (test.Type == BoxTypes.PixelAspectRatio) {
            PixelAspectRatioBox = new PixelAspectRatioBox();
            PixelAspectRatioBox.Read(reader);
            bOptionalBoxFound = true;
              } else

              // retrieve CodecPrivateData from avcC
              if (test.Type == BoxTypes.AvcC) {
            AvcCBox = new AvcCBox();
            AvcCBox.Read(reader);

            //if ((ulong) (reader.BaseStream.Position - pos) < this.Size) {
            //  // klude to work around Expression problem (missing uuid, but box size large enough for it)
            //  pos = reader.BaseStream.Position;
            //  test = new Box(BoxTypes.Any);
            //  test.Read(reader);
            //  reader.BaseStream.Position = pos;

            //  if (test.Type == BoxTypes.UUID) {
            //    Uuid = new UuidBox();
            //    Uuid.Read(reader);
            //  }
            //}
            bOptionalBoxFound = true;
              } else

              if (test.Type == BoxTypes.UUID) {
            Uuid = new UuidBox();
            Uuid.Read(reader);
              } else

              if (test.Type == BoxTypes.Mp4v) {
            PrivDataFullBox = new AnyPrivFullBox();
            PrivDataFullBox.Read(reader);
            bOptionalBoxFound = true;
              } else

              if (test.Type == BoxTypes.Vc1) {
            PrivDataBox = new AnyPrivBox();
            PrivDataBox.Read(reader);
            bOptionalBoxFound = true;
              }
            }
              }
        }