Thursday, February 24, 2011

Popcornjs - bug #127... again

Remember how I said I finished my bug? Well... I lied, lol. Upon receiving a "review-needs-work" status, and gaining a better understanding of javascript from class, I looked over my code and found that I needed to do it again.

My Example
Let's say you've got two subtitles: one starts at 3 seconds and has no end specified, the other starts at 10 and ends at 15. Now, if you set the first subtitle's end to the end of the video, the second subtitle will never disappear. I had to somehow arrange that an endless subtitle has it's end set to the end of the video ONLY if there isn't another subtitle coming up. Seeing as I don't have access to the next subtitle while I'm creating them (naturally), I had to do a little bit of backwards work.

Solution
(from popcorn.js):

if ( currentSubtitle ) {
previousSubtitle = currentSubtitle;
}
currentSubtitle = options;

if ( previousSubtitle && previousSubtitle.noEnd ) {
previousSubtitle.noEnd = false;
previousSubtitle.end = currentSubtitle.start;
Popcorn.removeTrackEvent( this, Popcorn.getLastTrackEventId( this ) );
Popcorn.addTrackEvent( this, previousSubtitle );
}
setup._setup.call( this, currentSubtitle );
Popcorn.addTrackEvent( this, currentSubtitle );

Confused? Here's what's happening:
This chunk of code is run once for each subtitle. Earlier, if it doesn't find an end options.noEnd is set which allows the end to be the end of the video (in popcorn.subtitle.js). So the first time through, (creating the endless one) the subtitle will be continuous and added to the list of track events.

...Follow me so far? Good.

The second time it runs through, it will see that there is a previous subtitle with noEnd set. It will remove the previous subtitle from the track list, change it's end to the start time of the current subtitle, and re-add it to the track list. Then business continues as usual for the current subtitle.

Wanna see my genious for yourself?
https://github.com/DanVentura/popcorn-js/tree/bug127/plugins/subtitle
Have fun ;)

No comments:

Post a Comment