MP4_Mangler.FragmentBoxes.traf.AddFrame C# (CSharp) Method

AddFrame() public method

Add a frame to this traf
public AddFrame ( GenericMediaFrame frame ) : void
frame GenericMediaFrame
return void
        public void AddFrame(GenericMediaFrame frame)
        {
            if (_children.Last() is trun) { // looking at .ismv files in a hex editor, they use multiple frames/trun.
                trun ot = _children.Last() as trun;
                ot.AddFrame(frame);
            } else {
                var t = new trun();
                t.AddFrame(frame);
                AddChild(t);
            }
            Header.AddFrame(frame);
        }

Usage Example

        /// <summary>
        /// Add a frame to the track
        /// </summary>
        public void AddFrame(UInt32 TrackID, GenericMediaFrame frame)
        {
            // Ensure correct boxes
            if (Tracks == null)
            {
                Tracks = new traf(TrackID);
                AddChild(Tracks);
            }
            if (TrackID != Tracks.TrackId)
            {
                throw new Exception("Fragments should only contain a single track");
            }
            if (Dependencies == null)
            {
                Dependencies = new sdtp();
                AddChild(Dependencies);
            }

            // Add this frame
            Tracks.AddFrame(frame);
            Dependencies.AddFrame(frame);
            // Add duration
            Duration += frame.FrameDuration;
        }