Home | History | Annotate | Download | only in boxes
      1 /*
      2  * Copyright 2008 CoreMedia AG, Hamburg
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the License);
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an AS IS BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.coremedia.iso.boxes;
     18 
     19 
     20 import com.googlecode.mp4parser.AbstractBox;
     21 import com.googlecode.mp4parser.AbstractContainerBox;
     22 
     23 import java.util.List;
     24 
     25 /**
     26  * The metadata for a presentation is stored in the single Movie Box which occurs at the top-level of a file.
     27  * Normally this box is close to the beginning or end of the file, though this is not required.
     28  */
     29 public class MovieBox extends AbstractContainerBox {
     30     public static final String TYPE = "moov";
     31 
     32     public MovieBox() {
     33         super(TYPE);
     34     }
     35 
     36     public int getTrackCount() {
     37         return getBoxes(TrackBox.class).size();
     38     }
     39 
     40 
     41     /**
     42      * Returns the track numbers associated with this <code>MovieBox</code>.
     43      *
     44      * @return the tracknumbers (IDs) of the tracks in their order of appearance in the file
     45      */
     46     public long[] getTrackNumbers() {
     47 
     48         List<TrackBox> trackBoxes = this.getBoxes(TrackBox.class);
     49         long[] trackNumbers = new long[trackBoxes.size()];
     50         for (int trackCounter = 0; trackCounter < trackBoxes.size(); trackCounter++) {
     51             AbstractBox trackBoxe = trackBoxes.get(trackCounter);
     52             TrackBox trackBox = (TrackBox) trackBoxe;
     53             trackNumbers[trackCounter] = trackBox.getTrackHeaderBox().getTrackId();
     54         }
     55         return trackNumbers;
     56     }
     57 
     58     public MovieHeaderBox getMovieHeaderBox() {
     59         for (Box box : boxes) {
     60             if (box instanceof MovieHeaderBox) {
     61                 return (MovieHeaderBox) box;
     62             }
     63         }
     64         return null;
     65     }
     66 
     67 }
     68