@@ -141,8 +141,10 @@ MediaPlayer.dependencies.TextTTMLXMLMP4SourceBuffer = function() {
141141 tfhd ,
142142 tfdt ,
143143 trun ,
144+ subs ,
144145 fragmentStart ,
145146 fragmentDuration = 0 ,
147+ ttmlData ,
146148 encoding = 'utf-8' ;
147149
148150 //no mp4, all the subtitles are in one xml file
@@ -202,6 +204,7 @@ MediaPlayer.dependencies.TextTTMLXMLMP4SourceBuffer = function() {
202204 tfhd = traf . getBoxByType ( 'tfhd' ) ;
203205 tfdt = traf . getBoxByType ( 'tfdt' ) ;
204206 trun = traf . getBoxByType ( 'trun' ) ;
207+ subs = traf . getBoxByType ( 'subs' ) ;
205208
206209 fragmentStart = tfdt . baseMediaDecodeTime / self . timescale ;
207210 fragmentDuration = 0 ;
@@ -212,13 +215,25 @@ MediaPlayer.dependencies.TextTTMLXMLMP4SourceBuffer = function() {
212215 }
213216
214217 self . buffered . addRange ( fragmentStart , fragmentStart + fragmentDuration ) ;
218+
219+ if ( subs ) {
220+ for ( var i = 0 ; i < subs . entry_count ; i ++ ) {
221+ for ( var j = 0 ; j < subs . entry [ i ] . subsample_count ; j ++ ) {
222+ //the first subsample is the one in which TTML text is set
223+ ttmlData = mdat . data . subarray ( 0 , subs . entry [ i ] . subSampleEntries [ 0 ] . subsample_size ) ;
224+ break ;
225+ }
226+ }
227+ } else {
228+ ttmlData = mdat . data ;
229+ }
215230
216231 //detect utf-16 encoding
217- if ( self . isUTF16 ( mdat . data ) ) {
232+ if ( self . isUTF16 ( ttmlData ) ) {
218233 encoding = 'utf-16' ;
219234 }
220235 // parse data and add to cues
221- self . convertUTFToString ( mdat . data , encoding )
236+ self . convertUTFToString ( ttmlData , encoding )
222237 . then ( function ( result ) {
223238 self . ttmlParser . parse ( result ) . then ( function ( cues ) {
224239 var i ,
0 commit comments