26 March 2009
YouTube API having issues with seekTo()
At around midnight last night, while working on code that uses embeded YouTube video with the YouTube API, my JavaScript that loads a video and seeks to a specific location started failing on the load (on one page) and failing on the seek (on another). I was working on an unrelated area and so took the opportunity to add more JavaScript logging via Log4JS (highly recommended). The problem persisted, code was moved around, and finally all logging was removed with the idea that watching the JavaScript somehow changed the event sequence. No luck. Eventually, I backed up the changed code and re-got the "working" versions from svn. Still broken. So I went to my reference app and received the sad news that the call is, in fact, no longer working as it had. Sometimes, it is that third party library that's causing problems!
The only reference I've found is a thread back in Feb 19th that actually duplicates my issues on the YouTube reference page: using the "Load video" with a non-zero "Start at" value fails to seek. The thread also contains a suggested workaround: wait until after the video is done buffering before performing the seekTo(). To be continued...
[ updated 28 Mar 2009 ]
The solution is to call seekTo() after the playing event (1) has been received. So, the sequence is:
- onYouTubePlayerReady(playerId)
- onPlayerStateChange(newState == 1)
- player.seekTo(offset, true)
In my tests, I'd also seen error 100 (requested video not found) returned if I called seekTo() too quickly after onYouTubePlayerReady() fires. So, this is probably not a YouTube issue, more of a Programmer Is a Bonehead (PIB) issue.
- Bug in ListCookieHandler Java class posted by sstrader on 28 June 2010 at 12:25:24 PM
- A content voting microformat posted by sstrader on 23 April 2010 at 4:34:41 PM
- iPhone, the platform most hated by developers posted by sstrader on 13 April 2010 at 12:25:58 AM
- Singleton for Java posted by sstrader on 5 January 2010 at 11:03:02 PM
- Opera (and Eclipse) posted by sstrader on 25 October 2009 at 10:34:55 AM