Thursday, February 10, 2011

Popcorn.js - bug # 127

I finally finished my first bug for popcorn.js. The bug I was assigned was to make it easier to specify subtitles, found here: https://webmademovies.lighthouseapp.com/projects/63272-popcorn-js/tickets/bins/261878

Basically, when making subtitles you have to specify an 'in' and an 'out' so it knows what time in the video to show up and disappear. They wanted to be able to make a subtitle continuous by not specifying an 'out'. For example, if a subtitle immediately follows another subtitle, it would be redundant to specify the 'out' as the next subtitle's 'in'.

Now, this seems easy... just get the 'in' from the next subtitle, right? HA! Too bad I didn't find a way to access the next subtitle within the first subtitle. Fortunately I found a workaround: if you set the 'out' to a greater value than the next subtitle's 'out' (even if you set it to 1000000), it should seamlessly go into the next subtitle without any problems.

As I mentioned before, I don't have access to the next subtitle (cause it doesn't exist when you're creating the first). I figured that the fix would be to set the missing 'out' element to the maximum value available... the video duration.

options.out = this.video.duration

Yet another problem... fantastic. For some odd reason, if you call this statement for the very first subtitle in the video, this.video.duration is 0. This is because this.video.readyState is not 4. In other words, the video isn't ready yet. I have discovered the folly of Javascript, it's too fast for itself LOL.

Fortunately I found a "start:" function, which is called when the subtitle is put into the video. By the time this function is called, the readyState is 4 and video.duration returns as expected. There was also some other problems but if you're interested check out my branch.

I liked this bug. It taught me a lot about Popcorn.js and JavaScript :D

1 comment: