Skip to main content
February 11, 2009
Question

Issue with addAsync

  • February 11, 2009
  • 2 replies
  • 911 views
Hi,

I have an issue with addAsync that handler function is not invoked when event fired. It does not work as I use addAsync in deeper function calls as below code.

The player does fire MediaComplete event but correct handler never get called. Anyone know has ideas of what the problem is?

Here is the flow of the code:
- Play a video
- Let it plays for 10 seconds (wait for a none existing event)
- Seek to the end of time elapse
- Verify video is stopped playing

public function testVidSeekBeyondLength():void
{
var uuid:String = "7b992781-37f7-4abd-a948-f7d540237aa7";
Player.Instance.addEventListener(Events.VideoLoaded,
addAsync(putVideoPlayFor10Secs,
45000,
null,
null));
Player.Instance.callMethod("playId", uuid);
}

private function putVideoPlayFor10Secs(e:Event):void
{
Player.Instance.removeEventListener(e.type, putVideoPlayFor10Secs);
Player.Instance.addEventListener(Events.NotExist,
addAsync(neverInvoke,
10000,
null,
verifyVidSeekBeyondLength));
}

private function verifyVidSeekBeyondLength(e:Event):void
{
Player.Instance.removeEventListener(Events.NotExist, neverInvoke);
var length:Number = Player.Instance.videoWindow.Duration;
Player.Instance.addEventListener(Events.MediaComplete,
addAsync (verifyVidSeekBeyondLengthStop,
15000,
null,
errorVidSeekBeyondLengthNotStop));
Player.Instance.callMethod("seek", length);
}

private function verifyVidSeekBeyondLengthStop(e:Event):void
{
Player.Instance.removeEventListener(e.type, verifyVidSeekBeyondLengthStop);
var length:Number = Player.Instance.videoWindow.Duration;
var start:int = new int(length / 60);
var expectedPos:String = new String(start) + ":";
var pos:String = Player.Instance.callMethod("getPosition") as String;
Assert.assertTrue("Position should be the video's length.", pos.indexOf(expectedPos) == 0);

var state:String = Player.Instance.callMethod("getState") as String;
Assert.assertEquals("Video should be stopped after seek beyond its length.", PlayerState.Stopped, state);
}

private function errorVidSeekBeyondLengthNotStop(param:Object):void
{
fail("Video was not stopped after seek beyond its length.");
}

Thanks,
Dina
This topic has been closed for replies.

2 replies

February 15, 2009
Hi Daniel,

Introducing timer instead of waiting for a nono existing event help me to solve the problem. You are right, removing function returned from addAsync is the correct behavior. This is another compliment to the solution.

Thanks a lot.

Dina
Participating Frequently
February 13, 2009
I suspect the problem is that because verifyVidSeekBeyondLength is<br />defined as the errorFunction for the addAsync, once that has triggered<br />FlexUnit assumes that the test has failed and it doesn't expect any<br />further testing to occur. As a result all future events are ignored<br />which is why MediaComplete is ignored. If you were instead to define<br />and start your own 10 second Timer that has as it'<br />TimerEvent.TIMER_COMPLETE an addAsync(verifyVidSeekBeyondLength,<br />15000) handler it would work correctly.<br /><br />As a side note, the call in the test to<br />Player.Instance.removeEventListener(e.type, putVideoPlayFor10Secs);<br />isn't doing anything. You would need to remove the function returned<br />by the addAsync() call to truly remove the event listener that was<br />registered.<br /><br />-- Daniel R. <danielr@neophi.com> [http://danielr.neophi.com/]<br /><br />On Wed, Feb 11, 2009 at 3:05 PM, Dina So <member@adobeforums.com> wrote:<br />> A new discussion was started by Dina So in<br />><br />> FlexUnit Development --<br />> Issue with addAsync<br />><br />> Hi,<br />><br />> I have an issue with addAsync that handler function is not invoked when<br />> event fired. It does not work as I use addAsync in deeper function calls as<br />> below code.<br />><br />> The player does fire MediaComplete event but correct handler never get<br />> called. Anyone know has ideas of what the problem is?<br />><br />> Here is the flow of the code:<br />> - Play a video<br />> - Let it plays for 10 seconds (wait for a none existing event)<br />> - Seek to the end of time elapse<br />> - Verify video is stopped playing