Dragging the knob to seek.
Works not-so-well with youtube. I'll revisit later... git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@686 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -8,9 +8,11 @@ import flash.display.Graphics;
|
|||||||
import flash.display.Shape;
|
import flash.display.Shape;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
|
|
||||||
|
import flash.events.Event;
|
||||||
import flash.events.MouseEvent;
|
import flash.events.MouseEvent;
|
||||||
|
|
||||||
import flash.geom.Point;
|
import flash.geom.Point;
|
||||||
|
import flash.geom.Rectangle;
|
||||||
|
|
||||||
import com.threerings.util.Log;
|
import com.threerings.util.Log;
|
||||||
import com.threerings.util.ValueEvent;
|
import com.threerings.util.ValueEvent;
|
||||||
@@ -76,10 +78,10 @@ public class SimpleVideoDisplay extends Sprite
|
|||||||
_track.y = NATIVE_HEIGHT - PAD - TRACK_HEIGHT - _hud.y;
|
_track.y = NATIVE_HEIGHT - PAD - TRACK_HEIGHT - _hud.y;
|
||||||
g = _track.graphics;
|
g = _track.graphics;
|
||||||
g.beginFill(0x000000, .7);
|
g.beginFill(0x000000, .7);
|
||||||
g.lineStyle(1, 0xFFFFFF);
|
|
||||||
g.drawRect(0, 0, TRACK_WIDTH, TRACK_HEIGHT);
|
g.drawRect(0, 0, TRACK_WIDTH, TRACK_HEIGHT);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
//g.drawRect(0, 0, TRACK_WIDTH - 2, TRACK_HEIGHT - 2);
|
g.lineStyle(2, 0xFFFFFF);
|
||||||
|
g.drawRect(0, 0, TRACK_WIDTH, TRACK_HEIGHT);
|
||||||
// _track is not added to _hud until we know the duration
|
// _track is not added to _hud until we know the duration
|
||||||
|
|
||||||
const trackMask :Shape = new Shape();
|
const trackMask :Shape = new Shape();
|
||||||
@@ -99,7 +101,6 @@ public class SimpleVideoDisplay extends Sprite
|
|||||||
|
|
||||||
_track.addEventListener(MouseEvent.CLICK, handleTrackClick);
|
_track.addEventListener(MouseEvent.CLICK, handleTrackClick);
|
||||||
_knob.addEventListener(MouseEvent.MOUSE_DOWN, handleKnobDown);
|
_knob.addEventListener(MouseEvent.MOUSE_DOWN, handleKnobDown);
|
||||||
_knob.addEventListener(MouseEvent.MOUSE_UP, handleKnobUp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,30 +146,33 @@ public class SimpleVideoDisplay extends Sprite
|
|||||||
{
|
{
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
// see if we can seek to a position
|
adjustSeek(event.localX);
|
||||||
const dur :Number = _player.getDuration();
|
|
||||||
if (isNaN(dur)) {
|
|
||||||
log.debug("Duration is NaN, track click dropped.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var perc :Number = event.localX / TRACK_WIDTH;
|
|
||||||
perc = Math.max(0, Math.min(1, perc));
|
|
||||||
log.debug("Seek", "x", event.localX, "perc", perc, "pos", (perc * dur));
|
|
||||||
|
|
||||||
_player.seek(perc * dur);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handleKnobDown (event :MouseEvent) :void
|
protected function handleKnobDown (event :MouseEvent) :void
|
||||||
{
|
{
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
// TODO
|
|
||||||
|
_dragging = true;
|
||||||
|
_knob.startDrag(false, new Rectangle(0, TRACK_HEIGHT/2, TRACK_WIDTH, 0));
|
||||||
|
addEventListener(Event.ENTER_FRAME, handleKnobSeekCheck);
|
||||||
|
addEventListener(MouseEvent.MOUSE_UP, handleKnobUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handleKnobUp (event :MouseEvent) :void
|
protected function handleKnobUp (event :MouseEvent) :void
|
||||||
{
|
{
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
// TODO
|
|
||||||
|
_dragging = false;
|
||||||
|
_knob.stopDrag();
|
||||||
|
removeEventListener(Event.ENTER_FRAME, handleKnobSeekCheck);
|
||||||
|
removeEventListener(MouseEvent.MOUSE_UP, handleKnobUp);
|
||||||
|
handleKnobSeekCheck(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function handleKnobSeekCheck (event :Event) :void
|
||||||
|
{
|
||||||
|
adjustSeek(_knob.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handlePlayerState (event :ValueEvent) :void
|
protected function handlePlayerState (event :ValueEvent) :void
|
||||||
@@ -198,6 +202,10 @@ public class SimpleVideoDisplay extends Sprite
|
|||||||
|
|
||||||
protected function handlePlayerPosition (event :ValueEvent) :void
|
protected function handlePlayerPosition (event :ValueEvent) :void
|
||||||
{
|
{
|
||||||
|
if (_dragging) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastKnobX = int.MIN_VALUE;
|
||||||
const pos :Number = Number(event.value);
|
const pos :Number = Number(event.value);
|
||||||
_knob.x = (pos / _player.getDuration()) * TRACK_WIDTH;
|
_knob.x = (pos / _player.getDuration()) * TRACK_WIDTH;
|
||||||
if (_knob.parent == null) {
|
if (_knob.parent == null) {
|
||||||
@@ -211,6 +219,24 @@ public class SimpleVideoDisplay extends Sprite
|
|||||||
log.warning("player error: " + event.value);
|
log.warning("player error: " + event.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function adjustSeek (trackX :Number) :void
|
||||||
|
{
|
||||||
|
// see if we can seek to a position
|
||||||
|
const dur :Number = _player.getDuration();
|
||||||
|
if (isNaN(dur)) {
|
||||||
|
log.debug("Duration is NaN, not seeking.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (trackX == _lastKnobX) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastKnobX = trackX;
|
||||||
|
var perc :Number = trackX / TRACK_WIDTH;
|
||||||
|
perc = Math.max(0, Math.min(1, perc));
|
||||||
|
log.debug("Seek", "x", trackX, "perc", perc, "pos", (perc * dur));
|
||||||
|
_player.seek(perc * dur);
|
||||||
|
}
|
||||||
|
|
||||||
protected function showHUD (show :Boolean) :void
|
protected function showHUD (show :Boolean) :void
|
||||||
{
|
{
|
||||||
if (show == (_hud.parent == null)) {
|
if (show == (_hud.parent == null)) {
|
||||||
@@ -279,6 +305,10 @@ public class SimpleVideoDisplay extends Sprite
|
|||||||
/** The seek selector knob, positioned on the hud. */
|
/** The seek selector knob, positioned on the hud. */
|
||||||
protected var _knob :Sprite;
|
protected var _knob :Sprite;
|
||||||
|
|
||||||
|
protected var _lastKnobX :int = int.MIN_VALUE;
|
||||||
|
|
||||||
|
protected var _dragging :Boolean;
|
||||||
|
|
||||||
/** Our mask, also defines our boundaries for clicking. */
|
/** Our mask, also defines our boundaries for clicking. */
|
||||||
protected var _mask :Shape;
|
protected var _mask :Shape;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user