@@ -253,6 +253,17 @@ export function parseLyric(ttmlText: string): TTMLLyric {
253253 isDuet = false ,
254254 parentItunesKey : string | null = null ,
255255 ) {
256+ const startTimeAttr = lineEl . getAttribute ( "begin" ) ;
257+ const endTimeAttr = lineEl . getAttribute ( "end" ) ;
258+
259+ let parsedStartTime = 0 ;
260+ let parsedEndTime = 0 ;
261+
262+ if ( startTimeAttr && endTimeAttr ) {
263+ parsedStartTime = parseTimespan ( startTimeAttr ) ;
264+ parsedEndTime = parseTimespan ( endTimeAttr ) ;
265+ }
266+
256267 const line : LyricLine = {
257268 id : uid ( ) ,
258269 words : [ ] ,
@@ -263,15 +274,12 @@ export function parseLyric(ttmlText: string): TTMLLyric {
263274 ? isDuet
264275 : ! ! lineEl . getAttribute ( "ttm:agent" ) &&
265276 lineEl . getAttribute ( "ttm:agent" ) !== mainAgentId ,
266- startTime : 0 ,
267- endTime : 0 ,
277+ startTime : parsedStartTime ,
278+ endTime : parsedEndTime ,
268279 ignoreSync : false ,
269280 } ;
270281 let haveBg = false ;
271282
272- const startTime = lineEl . getAttribute ( "begin" ) ;
273- const endTime = lineEl . getAttribute ( "end" ) ;
274-
275283 const itunesKey = isBG
276284 ? parentItunesKey
277285 : lineEl . getAttribute ( "itunes:key" ) ;
@@ -363,10 +371,7 @@ export function parseLyric(ttmlText: string): TTMLLyric {
363371 }
364372 }
365373
366- if ( startTime && endTime ) {
367- line . startTime = parseTimespan ( startTime ) ;
368- line . endTime = parseTimespan ( endTime ) ;
369- } else {
374+ if ( ! startTimeAttr || ! endTimeAttr ) {
370375 line . startTime = line . words
371376 . filter ( ( w ) => w . word . trim ( ) . length > 0 )
372377 . reduce (
0 commit comments