Ran across a pesky problem in one of the websites I have been burning the midnight oil on. Basically the site has 6 main pages, one of which contains a video gallery. Everything was working just fine and dandy. Then we decided to add a "trailer" on the homepage to welcome users to the site. This page also worked fine and dandy... until I clicked on the video gallery. The addition of this trailer on the homepage prevented the movies in the gallery from playing for a few minutes. Damn it.
Is the movie still playing after you leave the home page? Maybe the gallery is not playing until the trailer is finished. I went back and triple ensured the trailer was stopped on page exit... it did not help, there was still a delay. ugh.
Well maybe the trailer is still loading even though it is stopped since it is a progressive download. That makes sense, and the time it takes to load is about the time these videos are waiting to play in the movie gallery. This makes more sense to me... Flash should be able to play two videos at once anyways. Not sure what I was thinking above.
Ok, no biggie. I will just remove the flv from the stage and set it to null and let the garbage handler take it... NOPE, not so easy. That probably wasn't the best idea in hind sight since the garbage handler only runs when it feels like it. Plus, since the video is still loading there could be a reference somewhere keeping it from being collected.
Hmmm. Lets crack open the API. flvPlayBack.closeVideoPlayer(activeVideoPlayerIndex). Perfect! That should do the trick..... NOPE AGAIN. Had I read the fine print I would have realized that this only works when you have multiple videos in the flvPlayback. You can't close the default index, it will throw an error (which it did). Well crap.
With some digging, however, you can close the VideoPlayer if you have direct access to it. In order to gain access you need to call: flvPlayback.getVideoPlayer(activeVideoPlayerIndex). Once you have the videoPlayer you can call videoPlayer.close(). Viola! The stream is closed and the video gallery can start immediately upon opening. Perfecto!
One thing to note: Check the Flv's source to make sure it is not an empty string before you get the video player. If the flv's source has not been set then getVideoPlayer() will throw an error.
Hopefully someone finds this helpful and saves them time. Sorry for the long-windedness of the article... I could have explained the solution in one paragraph but I tend to learn better through mistakes (as you can see). Hopefully including the logic, or lack of logic, is a good learning tool.