Commit fe411aeb authored by Anssi Piirainen's avatar Anssi Piirainen

Merge pull request #176 from flowplayer/danielr-163new

Danielr 163new
parents 822363d6 9aee3605
......@@ -57,6 +57,7 @@ package org.flowplayer.view {
private var _play:PlayButtonOverlay;
private var _rotation:RotatingAnimation;
private var _playDetectTimer:Timer;
private var _startTime:Number;
public function PlayButtonOverlayView(resizeToTextWidth:Boolean, play:PlayButtonOverlay, pluginRegistry:PluginRegistry) {
_resizeToTextWidth = resizeToTextWidth;
......@@ -464,10 +465,10 @@ package org.flowplayer.view {
private function bufferUntilStarted(event:ClipEvent = null):void {
if (event && event.isDefaultPrevented()) return;
startBuffering();
createPlaybackStartedCallback(stopBuffering);
createPlaybackStartedCallback();
}
private function createPlaybackStartedCallback(callback:Function):void {
private function createPlaybackStartedCallback():void {
log.debug("detectPlayback()");
if (! _player.isPlaying()) {
......@@ -479,29 +480,30 @@ package org.flowplayer.view {
return;
}
var time:Number = _player.status.time;
_startTime = _player.status.time;
if (_playDetectTimer) {
_playDetectTimer.reset();
_playDetectTimer = null;
}
_playDetectTimer = new Timer(200);
//#163 use weak reference event here
_playDetectTimer.addEventListener(TimerEvent.TIMER,
function(event:TimerEvent):void {
var currentTime:Number = _player.status.time;
log.debug("on detectPlayback() currentTime " + currentTime + ", time " + time);
if (Math.abs(currentTime - time) > 0.2) {
_playDetectTimer.stop();
log.debug("playback started");
callback();
} else {
log.debug("not started yet, currentTime " + currentTime + ", time " + time);
}
}, false, 0, true);
_playDetectTimer.addEventListener(TimerEvent.TIMER,onPlayDetect);
log.debug("doStart(), starting timer");
_playDetectTimer.start();
}
//#163 move play detect timer to external listener and clear when done.
private function onPlayDetect(event:TimerEvent):void
{
var currentTime:Number = _player.status.time;
log.debug("on detectPlayback() currentTime " + currentTime + ", time " + _startTime);
if (Math.abs(currentTime - _startTime) > 0.2) {
stopBuffering();
_playDetectTimer.stop();
_playDetectTimer.removeEventListener(TimerEvent.TIMER,onPlayDetect);
_playDetectTimer = null;
_startTime = NaN;
log.debug("playback started");
} else {
log.debug("not started yet, currentTime " + currentTime + ", time " + _startTime);
}
}
}
}
......@@ -28,16 +28,17 @@ import flash.utils.Timer;
public function RotatingAnimation() {
createRotation();
_rotationTimer = new Timer(50);
//#163 weak reference event
_rotationTimer.addEventListener(TimerEvent.TIMER, rotate, false,0,true);
_rotationTimer.addEventListener(TimerEvent.TIMER, rotate);
_rotationTimer.start();
}
public function start():void {
_rotationTimer.addEventListener(TimerEvent.TIMER, rotate);
_rotationTimer.start();
}
public function stop():void {
_rotationTimer.removeEventListener(TimerEvent.TIMER, rotate);
_rotationTimer.stop();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment