Ejemplo n.º 1
0
 /// <exception cref="System.IO.IOException"></exception>
 private void SaveMpegFrames(RandomAccessFile saveFile)
 {
     int filePos = xingOffset;
     if (filePos < 0)
     {
         filePos = startOffset;
     }
     if (filePos < 0)
     {
         return;
     }
     if (endOffset < filePos)
     {
         return;
     }
     RandomAccessFile file = new RandomAccessFile(filename, "r");
     byte[] bytes = new byte[bufferLength];
     try
     {
         file.Seek(filePos);
         while (true)
         {
             int bytesRead = file.Read(bytes, 0, bufferLength);
             if (filePos + bytesRead <= endOffset)
             {
                 saveFile.Write(bytes, 0, bytesRead);
                 filePos += bytesRead;
             }
             else
             {
                 saveFile.Write(bytes, 0, endOffset - filePos + 1);
                 break;
             }
         }
     }
     finally
     {
         file.Close();
     }
 }
Ejemplo n.º 2
0
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="Mp3net.NotSupportedException"></exception>
 public virtual void Save(string newFilename)
 {
     if (String.Equals(filename, newFilename, StringComparison.OrdinalIgnoreCase))
     {
         throw new ArgumentException("Save filename same as source filename");
     }
     RandomAccessFile saveFile = new RandomAccessFile(newFilename, "rw");
     try
     {
         if (HasId3v2Tag())
         {
             saveFile.Write(id3v2Tag.ToBytes());
         }
         SaveMpegFrames(saveFile);
         if (HasCustomTag())
         {
             saveFile.Write(customTag);
         }
         if (HasId3v1Tag())
         {
             saveFile.Write(id3v1Tag.ToBytes());
         }
     }
     finally
     {
         saveFile.Close();
     }
 }