         @entrySizes.push bits.read_uint32()
     return
 
+  getSampleSizes: (sampleNumber, len=1) ->
+    sizes = []
+    if @sampleSize isnt 0
+      for i in [len...0]
+        sizes.push @sampleSize
+    else
+      for i in [len...0]
+        sizes.push @entrySizes[sampleNumber - 1]
+        sampleNumber++
+    return sizes
+
   # Returns the sample size for the given sample number
-  getSampleSize: (sampleNumber) ->
-    if @sampleSize is 0  # the samples have different sizes
-      return @entrySizes
-    else  # all samples are the same size
-      return @entrySizes[sampleNumber]  # TODO: sampleNumber - 1?
+  getSampleSize: (sampleNumber, len=1) ->
+    if @sampleSize isnt 0  # all samples are the same size
+      return @sampleSize * len
+    else  # the samples have different sizes
+      totalLength = 0
+      for i in [len...0]
+        if sampleNumber > @entrySizes.length
+          throw new Error "Sample number is out of range: #{sampleNumber} > #{@entrySizes.length}"
+        totalLength += @entrySizes[sampleNumber - 1]  # TODO: Is -1 correct?
+        sampleNumber++
+      return totalLength
 
   getDetails: (detailLevel) ->
     str = "sampleSize=#{@sampleSize} sampleCount=#{@sampleCount}"

Bits = require './bits'
fs = require 'fs'

formatDate = (date) ->
  date.toISOString()

TAG_CTOO = new Buffer([0xa9, 0x74, 0x6f, 0x6f]).toString 'utf8'

class MP4File
  constructor: (filename) ->

      time += entry.sampleDelta * entry.sampleCount
    return time / mdhdBox.timescale

  # Returns a decoding time for the given sample number.
  # The sample number starts at 1.
  getDecodingTime: (sampleNumber) ->
    mdhdBox = @findParent('mdia').find('mdhd')

    sampleNumber--
    time = 0
    for entry in @entries
      if sampleNumber > entry.sampleCount
