Jump to content


gotoVideoTime doesnt seem to work

Recommended Posts



Thanks again for all of the fantastic commitment to the community. It's appreciated by many :-)


I'm currently having some odd issues with the VideoLoader class. I'm actually having two issues, the second came from the first but seems simpler. I'll detail that one first.


1) AutoPlay issue --


var videoContainer : Sprite = addChild(new Sprite()) as Sprite;
var videoLoader : VideoLoader = new VideoLoader("http://www.domain.com/path/to/video.flv", {name:"myVideo", container:videoContainer, scaleMode:"none", autoPlay:false});


This code 'works' but sometimes the video will autoPlay and sometimes it won't. If I refresh the browser multiple times I'll get it playing 1 times out of 4.


2) gotoVideoTime issue --


package greensock.loadingTest {
import com.greensock.events.LoaderEvent;
import com.greensock.loading.VideoLoader;

import mx.formatters.NumberFormatter;

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

public class VideoPlayer extends Sprite {
	private var _loopPoint : Point = new Point(0, 0);
	private var _shouldLoop : Boolean;
	private var _prevInLoop : Boolean;
	private var _videoLoader : VideoLoader;
	private var _videoContainer : Sprite;
	private var _tfState : TextField;
	private var _tfLoopPoint : TextField;
	private var _tfTitle : TextField;
	static private var FORMATTER : NumberFormatter = new NumberFormatter();
	FORMATTER.precision = 2;
	public function VideoPlayer(pUrl : String) {
		_videoContainer = addChild(new Sprite()) as Sprite;
		_videoLoader = new VideoLoader("http://ph-c.codedazur.lan/assets/flv/scene03.flv", {name:"myVideo", container:_videoContainer, scaleMode:"none", bgColor:0x666666, autoPlay:true, volume:1});
		_videoLoader.addEventListener(VideoLoader.PLAY_PROGRESS, handlePlayProgress);
		_videoLoader.addEventListener(VideoLoader.VIDEO_COMPLETE, handleVideoComplete);
		_tfState = this.addChild(new TextField()) as TextField;
		_tfState.autoSize = TextFieldAutoSize.LEFT;
		_tfState.width = 100;
		_tfLoopPoint = this.addChild(new TextField()) as TextField;
		_tfLoopPoint.autoSize = TextFieldAutoSize.LEFT;
		_tfLoopPoint.width = 100;
		_tfTitle = this.addChild(new TextField()) as TextField;
		_tfTitle.autoSize = TextFieldAutoSize.LEFT;
		_tfLoopPoint.x = 150;
		_tfTitle.y = 25;
		_tfTitle.text = pUrl;
		loopPoint = new Point(1, 10);
		addEventListener(MouseEvent.CLICK, handleMouseEventClick);

	private function handleMouseEventClick(event : MouseEvent) : void {
		shouldLoop = !shouldLoop;
		if (_videoLoader.videoTime == _videoLoader.duration) {
			_videoLoader.gotoVideoTime(0, true);

//		public function play() : void {
//			_videoLoader.playVideo();
//		}
//		public function stop() : void {
//			_videoLoader.pauseVideo();
//		}

	public function get loopPoint() : Point {
		return _loopPoint;

	public function set loopPoint(pValue : Point) : void {
		_loopPoint = pValue;
		_tfLoopPoint.text = _loopPoint.toString();

	public function get shouldLoop() : Boolean {
		return _shouldLoop;

	public function set shouldLoop(pValue : Boolean) : void {
		_shouldLoop = pValue;

	private function handlePlayProgress(event : LoaderEvent) : void {
		if (_shouldLoop && _prevInLoop && afterLoop) {
		_prevInLoop = inLoop;
		_tfState.text = _shouldLoop ? "looping=true" : "looping=false";
		_tfState.appendText(" [" + FORMATTER.format(_videoLoader.videoTime) + "]");

	private function handleVideoComplete(event : LoaderEvent) : void {
		if (_shouldLoop && inLoop) {

	private function get inLoop() : Boolean {
		return (!beforeLoop && !afterLoop);

	private function get beforeLoop() : Boolean {
		return (_videoLoader.videoTime < _loopPoint.x);

	private function get afterLoop() : Boolean {
		return (_videoLoader.videoTime > _loopPoint.y);

	private function restartLoop() : void {
		_videoLoader.gotoVideoTime(_loopPoint.x, true);


The point of this class is to have it seek to 1 second when it reaches 10 seconds [ you turn this feature on by clicking the video ]. The problem is that when it hits 10 seconds it seems to seek to 1 second as the progress indicator shows 1 as the videoTime, but then the event listener is no longer called after this. [ It may seem odd to use the point, but it was just a quick way of holding two numeric values ]. There are certainly a few things here and there that need refining, but the issue is that when I call gotoVideoTime, it seems to as the progressHandler says the video is at the correct point, but then the eventHandler is no longer called and the video simply keeps playing! I've also tried to just call _videoLoader.pauseVideo() in the restartLoop() function but this also doesn't work... however, it does seem to mute the video??


Any ideas would be much appreciated.


PS - I've made sure I'm at the latest revision [ 186 ]

Link to comment
Share on other sites

PS - I've made sure I'm at the latest revision [ 186 ]

What's [ 186 ]? Are you using version 1.73?


It would be unbelievably helpful if you could post the simplest possible example FLA that I can publish on my end to see the problem happening (doesn't need to be your production files). It's so much more difficult to troubleshoot without seeing the issue reproduced in context. Nobody else has reported autoPlay not working occasionally and I've never run into that issue (not to say it doesn't exist). Frankly, Adobe's NetStream is riddled with inconsistencies and bugs, so it can be a tricky one to diagnose. As far as I know right now, VideoLoader works around all of the bugs and inconsistencies, but maybe you ran into another one in which case I'd definitely want to jump on it and figure out a work around.


Again, please make sure you're using v1.73 first.

Link to comment
Share on other sites



Thanks very much for the reply. I've taken a look and have made a few isolated tests and found some new information.


First off though, the version.


When I said 186 [ now 188 ], I was talking about the svn revision number. I access the libraries as svn externals and am accessing trunk [ which should be the latest version correct? ]


Should I be accessing the latest version from a different svn url? Further this revision number has the following code in LoaderMax regarding the version


public class LoaderMax extends LoaderCore {		
	/** @private **/
	public static const version:Number = 1.731;



Secondly, the tests.


I've attached a zip file with a variety of tests defined below [ I couldn't include the flv as it was too large. The name of the flv that I used in the tests was 'game01.flv' and located in the same directory as the swf ]. What I noticed in the end is that when I compile for flash player 9 it does not work, but when compiling for flash player 10 it does. I've tested both using code in the timeline [ test2 ] as well as using a document class [ test 3 ]. I normally compile directly from FDT.



Tests autoplay with code directly in a fla.

Result: works just fine. my original version was compiled from FDT, not sure if this makes a difference and I can include the original swf when I'm back in the office if it's helpful



Tests the class that uses a VideoLoader instance and implements a looping control for the video

Result: works fine when exported for flashplayer 10, but doesn't work correclty when exported for flashplayer 9. The loop doesn't happen and the listeners dissapear.



Test is the same as Test2 but uses a document class

Result: same as test 2



Thanks again for taking a look at this!! Could you let me know if you think it's correctable for flashplayer 9 and also let me know the proper way to obtain the latest versions from svn?

Link to comment
Share on other sites

Aha! That's exactly what I needed. Thank you so much for the thorough description and the test files. It looks like you were exactly right about the Flash Player 9 vs 10 thing - NetStream behaves differently based on which version of the Flash Player you publish for! Lovely. Anyway, I believe I successfully worked around the issue in the latest version (posted a few minutes ago). Sorry for the inconvenience. And just so you know, the problem was introduced in version 1.73 (a couple of days ago) when I restructured and simplified some things in VideoLoader and worked around another bug in NetStream. As of version 1.74, I believe all NetStream bugs are worked around (at least all that I know of). Phew! Thanks again for the assist.

Link to comment
Share on other sites

Thanks! Glad to hear that the tests were helpful as well.


Did the question regarding svn and latest versions also make sense?


Thanks again!!

Link to comment
Share on other sites

Did the question regarding svn and latest versions also make sense?

Yep, and it sounded like you were using the correct SVN stuff - I deleted the URL in your post because that's only for Club GreenSock members :)


So is VideoLoader working well for you now?

Link to comment
Share on other sites

Oops, sorry about disclosing the svn secret ;-)


Unfortunately though, it still does not work. I was compiling it in FDT and tried both Flex / AS3 and Flashplayer 9 / 10.


I then created a new IDE project to test as well, and with both flash 9 / 10 it now does not work :-( What seems to be happening is the following:


Flashplayer 9 ->

When gotoVideoTime(pTime, true), line 111 in the VideoPlayer class, is called the video simply continues to play. The playProgress event also dissapears and reference seems be be lost to the video object.


Flashplayer 10 -> [ this used to work in the prior version though ]

When gotoVideoTime(pTime, true), line 111 in the VideoPlayer class, is called the video seeks to the correct time but does not play. The playProgress event does not dissapear though.


Basically the video should play until 2.5 seconds and then seek to 1.5 seconds and then start looping between these 2 timescodes.


I've attached the zip of the test which now also includes a test video file.


Please let me know if you need any more info on this.



Link to comment
Share on other sites

There was indeed a problem with the PLAY_PROGRESS event not being dispatched in Flash Player 9 after a gotoVideoTime() was called (fixed now in version 1.741), but all the other issues you experienced seem to be related to your code and the fact that you're only allowed to seek() to keyframes on a video (that restriction has nothing to do with VideoLoader/LoaderMax). So in your example, you try to gotoVideoTime(1.5) but there's no keyframe there, so it ends up at the closest keyframe after that which is at 3.6 in your particular video (the end) based on the way you encoded it. So if you add trace() statements in your handleVideoComplete() and handlePlayProgress() methods, you'll see that your code calls restartLoop() on every frame. That would explain the funky behavior. I reverted to an old version of VideoLoader and it did the same thing - did you say this same code worked with an old version of VideoLoader? I can't imagine how, but I may very well be missing something.


So the crux of the issue here seems to be related to keyframes and the way your video is encoded and the fact that the code you're using assumes that the NetStream in VideoLoader can seek() to a very specific time with no keyframe there. You could try encoding your video so that keyframes are placed much more frequently. If you change your code so that instead of 1.5, you use 0, everything appears to work just fine (aside from the PLAY_PROGRESS which is fixed in the latest version, 1.741). But please let me know if you believe there are other issues with VideoLoader - NetStream's inconsistencies (and outright bugs) have proven to be rather pesky. Ever played "whack-a-mole"? :)

Link to comment
Share on other sites



Thank you again for the response!!


The VideoPlayer code could quite well contain some non optimized code and or flow issues. The class will still be debugged and optimized. As we're compiling to flashplayer 9 then we hadn't started that process before making certain the seeking would work.


Also a VERY good point regarding key frames though. I just grabbed a miscellaneous flv from the server to test with. The comment about 'it used to work' is because I was using a different flv before, with for certain different keyframes, etc. So that explains that issue.


I will also test the PLAY_PROGRESS issue in flashplayer 9 and post back what my results were. I'm sure it works though!

Link to comment
Share on other sites



Just to confirm that things are working for both flashplayer 9 and flashplayer 10 now.


Thanks again!

Link to comment
Share on other sites

Fantastic - thanks for letting us know.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.