Ejemplo n.º 1
0
        /// <summary>Write the track to the output stream.</summary>
        /// <param name="outputStream">The output stream to which the track should be written.</param>
        internal void Write(Stream outputStream)
        {
            Validate.NonNull("outputStream", outputStream);

            // Make sure we have an end of track marker if we need one
            if (!HasEndOfTrack && m_requireEndOfTrack)
            {
                throw new InvalidOperationException("The track cannot be written until it has an end of track marker.");
            }

            using (MemoryStream memStream = new MemoryStream()) {
                // Get the event data and write it out
                for (int i = 0; i < m_events.Count; i++)
                {
                    m_events[i].Write(memStream);
                }

                // Tack on the header and write the whole thing out to the main stream.
                MTrkChunkHeader header = new MTrkChunkHeader(memStream.ToArray());
                header.Write(outputStream);
            }
        }