So I've seen a few workarounds here for cleanly looping video, I've tried all of them in this thread and the previous post worked pretty good but not each time and it got me thinking because of the timeout, I decided to dig a little deeper and see if I could replace the loader texture at the exact time needed
After reading the bug report and adobes response was:
"Basically, content can render video texture when Event.TEXTURE_READY event has been sent to ActionScript"
So I decided to watch this and match it up with the the MediaPlayerEventType.CURRENT_TIME_CHANGE event to see how much time went by when the video texture was NOT ready.
I tested on a 60.05 second video and saw these results at the end of the video at the time of looping.
As you can see below there are quite a bit of times both at the end of the video and at the beginning of the video where the texture is NOT ready, this is the time you either see black or green. Note that the texture becomes ready again at .205 in this run, which is close to the previous posts setTimeOut, but I have seen lower times, it varies a lot.
Snapshot of the end and beginning of a loop, note that texture doesn't show ready for several frames
Current time: 59.996 - Total Time: 60.05 -- Texture is ready
Current time: 60.012 - Total Time: 60.05 -- Texture is ready
Current time: 60.028 - Total Time: 60.05 -- Texture is ready
Current time: 60.044 - Total Time: 60.05 -- Not ready
Current time: 60.05 - Total Time: 60.05 -- Not ready
Current time: 0 - Total Time: 60.05 -- Not ready
Current time: 0 - Total Time: 60.05 -- Not ready
Current time: 60.05 - Total Time: 60.05 -- Not ready
Current time: 60.05 - Total Time: 60.05 -- Not ready
Current time: 0.137 - Total Time: 60.05 -- Not ready
Current time: 0.154 - Total Time: 60.05 -- Not ready
Current time: 0.169 - Total Time: 60.05 -- Not ready
Current time: 0.187 - Total Time: 60.05 -- Not ready
Current time: 0.205 - Total Time: 60.05 -- Texture is ready
Current time: 0.25 - Total Time: 60.05 -- Texture is ready
Current time: 0.287 - Total Time: 60.05 -- Texture is ready
Current time: 0.31 - Total Time: 60.05 -- Texture is ready
Based on this info, I wanted to see if I could have the renderTexture draw the first available frame of the video, not the end, but it doesn't really matter from what I've tried, then to watch for the moment the video texture is NOT ready which isn't necessarily the very end of the video, and replace the player texture the moment the texture is ready again after the loop starts.
In the end it is a clean loop in my opinion. No green or black. I would get the green sometimes in the previous posters example since the time 200 mil timer was hit and miss. I won't put the entire code here, just the stuff you will need to replicate.
This will draw the first frame of the video that is ready, sometime after it starts
//I had to "un"internalize ConcreteVideoTexture for this to work, there's probably a better way, which I'll look into.
private function videoPlayer_readyHandler(event:Event):void
{
_loader.source = _player.texture;
var texture:ConcreteVideoTexture = _player.texture as ConcreteVideoTexture;
texture.videoBase.addEventListener(flash.events.Event.TEXTURE_READY, textureReady);
}
private function textureReady(e:flash.events.Event):void
{
_textureReady = true;
if (!_firstAvailableFrameDrawn)
{
_firstAvailableFrameDrawn = true;
_renderTexture.draw(_loader);
}
}
private function onCurrentTimeChange(e:Event):void
{
if (_looping && _textureReady)
{
_looping = false;
_loader.source = _player.texture;
return;
}
_textureReady = false;
}
private function onVideoEnd(e:Event):void
{
_loader.source = _renderTexture;
_looping = true;
_player.seek(0);
_player.play();
}
Hope it helps
Bill