More prepatory renaming and refactoring. Nothing of interest.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@705 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2008-11-14 21:43:33 +00:00
parent decb92fc08
commit 3ce7fc7f6a
6 changed files with 127 additions and 113 deletions
@@ -63,9 +63,9 @@ import com.threerings.util.ValueEvent;
import com.threerings.util.Util;
import com.threerings.flash.media.FlvVideoPlayer;
import com.threerings.flash.media.MediaPlayerCodes;
import com.threerings.flash.media.SimpleVideoDisplay;
import com.threerings.flash.media.VideoPlayer;
import com.threerings.flash.media.VideoPlayerCodes;
/**
* Dispatched when the size of the media being loaded is known.
@@ -751,7 +751,7 @@ public class MediaContainer extends Sprite
} else if (_media is SimpleVideoDisplay) {
var vid :SimpleVideoDisplay = SimpleVideoDisplay(_media);
// vid.removeEventListener(VideoPlayerCodes.SIZE, handleVideoSizeKnown);
// vid.removeEventListener(MediaPlayerCodes.SIZE, handleVideoSizeKnown);
vid.unload();
}
}
@@ -68,11 +68,11 @@ public class FlvVideoPlayer extends EventDispatcher
_netStream.play(url);
if (_autoPlay) {
updateState(VideoPlayerCodes.STATE_PLAYING);
updateState(MediaPlayerCodes.STATE_PLAYING);
} else {
_netStream.pause();
updateState(VideoPlayerCodes.STATE_READY);
updateState(MediaPlayerCodes.STATE_READY);
}
}
@@ -99,7 +99,7 @@ public class FlvVideoPlayer extends EventDispatcher
{
if (_netStream != null) {
_netStream.resume();
updateState(VideoPlayerCodes.STATE_PLAYING);
updateState(MediaPlayerCodes.STATE_PLAYING);
}
// TODO: throw an error if _netStream == null??
}
@@ -109,7 +109,7 @@ public class FlvVideoPlayer extends EventDispatcher
{
if (_netStream != null) {
_netStream.pause();
updateState(VideoPlayerCodes.STATE_PAUSED);
updateState(MediaPlayerCodes.STATE_PAUSED);
}
}
@@ -190,12 +190,12 @@ public class FlvVideoPlayer extends EventDispatcher
_vid.width = _size.x;
_vid.height = _size.y;
dispatchEvent(new ValueEvent(VideoPlayerCodes.SIZE, _size.clone()));
dispatchEvent(new ValueEvent(MediaPlayerCodes.SIZE, _size.clone()));
}
protected function handlePositionCheck (event :TimerEvent) :void
{
dispatchEvent(new ValueEvent(VideoPlayerCodes.POSITION, getPosition()));
dispatchEvent(new ValueEvent(MediaPlayerCodes.POSITION, getPosition()));
}
protected function handleNetStatus (event :NetStatusEvent) :void
@@ -203,7 +203,7 @@ public class FlvVideoPlayer extends EventDispatcher
var info :Object = event.info;
if ("error" == info.level) {
log.warning("NetStatus error: " + info.code);
dispatchEvent(new ValueEvent(VideoPlayerCodes.ERROR, info.code));
dispatchEvent(new ValueEvent(MediaPlayerCodes.ERROR, info.code));
return;
}
// else info.level == "status"
@@ -228,7 +228,7 @@ public class FlvVideoPlayer extends EventDispatcher
// rewind to the beginning
_netStream.seek(0);
_netStream.pause();
updateState(VideoPlayerCodes.STATE_PAUSED);
updateState(MediaPlayerCodes.STATE_PAUSED);
break;
case "NetStream.Seek.Notify":
@@ -258,7 +258,7 @@ public class FlvVideoPlayer extends EventDispatcher
protected function redispatchError (event :ErrorEvent) :void
{
log.warning("got video error: " + event);
dispatchEvent(new ValueEvent(VideoPlayerCodes.ERROR, event.text));
dispatchEvent(new ValueEvent(MediaPlayerCodes.ERROR, event.text));
}
/**
@@ -274,7 +274,7 @@ public class FlvVideoPlayer extends EventDispatcher
if ("duration" in info) {
_duration = Number(info.duration);
if (!isNaN(_duration)) {
dispatchEvent(new ValueEvent(VideoPlayerCodes.DURATION, _duration));
dispatchEvent(new ValueEvent(MediaPlayerCodes.DURATION, _duration));
}
}
}
@@ -284,14 +284,14 @@ public class FlvVideoPlayer extends EventDispatcher
const oldState :int = _state;
_state = newState;
dispatchEvent(new ValueEvent(VideoPlayerCodes.STATE, newState));
dispatchEvent(new ValueEvent(MediaPlayerCodes.STATE, newState));
if (_state == VideoPlayerCodes.STATE_PLAYING) {
if (_state == MediaPlayerCodes.STATE_PLAYING) {
_positionChecker.start();
} else {
_positionChecker.reset();
if (oldState == VideoPlayerCodes.STATE_PLAYING) {
if (oldState == MediaPlayerCodes.STATE_PLAYING) {
handlePositionCheck(null);
}
}
@@ -307,7 +307,7 @@ public class FlvVideoPlayer extends EventDispatcher
protected var _netStream :NetStream;
protected var _state :int = VideoPlayerCodes.STATE_UNREADY;
protected var _state :int = MediaPlayerCodes.STATE_UNREADY;
/** Our size, null until known. */
protected var _size :Point;
@@ -0,0 +1,93 @@
//
// $Id$
package com.threerings.flash.media {
import flash.events.IEventDispatcher;
import com.threerings.util.ValueEvent;
/**
* Dispatched when the state of the mediaplayer changes, usually in response to commands
* such as play/pause, etc.
* <b>value</b>: an int state. @see MediaPlayerCodes
*
* @eventType com.threerings.flash.media.MediaPlayerCodes.STATE
*/
[Event(name="state", type="com.threerings.util.ValueEvent")]
/**
* Dispatched when the total duration of the media is known.
* <b>value</b>: a Number expressing the duration in seconds.
*
* @eventType com.threerings.flash.media.MediaPlayerCodes.DURATION
*/
[Event(name="duration", type="com.threerings.util.ValueEvent")]
/**
* Dispatched periodically as the position is updated, during playback.
* <b>value</b>: a Number expressing the position in seconds.
*
* @eventType com.threerings.flash.media.MediaPlayerCodes.POSITION
*/
[Event(name="position", type="com.threerings.util.ValueEvent")]
/**
* Dispatched when there's a problem.
* <b>value</b>: a String error code/message.
*
* @eventType com.threerings.flash.media.MediaPlayerCodes.ERROR
*/
[Event(name="error", type="com.threerings.util.ValueEvent")]
/**
* Implemented by media-playing backends.
*/
public interface MediaPlayer extends IEventDispatcher
{
/**
* @return a MediaPlayerCodes state constant.
*/
function getState () :int;
/**
* Play the media, if not already.
*/
function play () :void;
/**
* Pause the media, if not already.
*/
function pause () :void;
/**
* Get the duration of the media, in seconds, or NaN if not yet known.
*/
function getDuration () :Number;
/**
* Get the position of the media, in seconds, or NaN if not yet ready.
*/
function getPosition () :Number;
/**
* Seek to the specified position.
*/
function seek (position :Number) :void;
/**
* Set the volume, between 0-1.
*/
function setVolume (volume :Number) :void;
/**
* Get the volume, from 0 to 1.
*/
function getVolume () :Number;
/**
* Unload the media.
*/
function unload () :void;
}
}
@@ -3,7 +3,7 @@
package com.threerings.flash.media {
public class VideoPlayerCodes
public class MediaPlayerCodes
{
public static const STATE :String = "state";
@@ -11,6 +11,7 @@ public class VideoPlayerCodes
public static const POSITION :String = "position";
/** Only applicable for VideoPlayer. */
public static const SIZE :String = "size";
public static const ERROR :String = "error";
@@ -19,7 +19,7 @@ import com.threerings.util.ValueEvent;
/**
*
* @eventType com.threerings.flash.video.VideoPlayerCodes.SIZE
* @eventType com.threerings.flash.video.MediaPlayerCodes.SIZE
*/
[Event(name="size", type="com.threerings.util.ValueEvent")]
@@ -38,11 +38,11 @@ public class SimpleVideoDisplay extends Sprite
public function SimpleVideoDisplay (player :VideoPlayer)
{
_player = player;
_player.addEventListener(VideoPlayerCodes.STATE, handlePlayerState);
_player.addEventListener(VideoPlayerCodes.SIZE, handlePlayerSize);
_player.addEventListener(VideoPlayerCodes.DURATION, handlePlayerDuration);
_player.addEventListener(VideoPlayerCodes.POSITION, handlePlayerPosition);
_player.addEventListener(VideoPlayerCodes.ERROR, handlePlayerError);
_player.addEventListener(MediaPlayerCodes.STATE, handlePlayerState);
_player.addEventListener(MediaPlayerCodes.SIZE, handlePlayerSize);
_player.addEventListener(MediaPlayerCodes.DURATION, handlePlayerDuration);
_player.addEventListener(MediaPlayerCodes.POSITION, handlePlayerPosition);
_player.addEventListener(MediaPlayerCodes.ERROR, handlePlayerError);
addChild(_player.getDisplay());
@@ -132,12 +132,12 @@ public class SimpleVideoDisplay extends Sprite
event.stopImmediatePropagation();
switch (_player.getState()) {
case VideoPlayerCodes.STATE_READY:
case VideoPlayerCodes.STATE_PAUSED:
case MediaPlayerCodes.STATE_READY:
case MediaPlayerCodes.STATE_PAUSED:
_player.play();
break;
case VideoPlayerCodes.STATE_PLAYING:
case MediaPlayerCodes.STATE_PLAYING:
_player.pause();
break;
@@ -261,9 +261,9 @@ public class SimpleVideoDisplay extends Sprite
const g :Graphics = _hud.graphics;
g.clear();
if ((state != VideoPlayerCodes.STATE_READY) &&
(state != VideoPlayerCodes.STATE_PLAYING) &&
(state != VideoPlayerCodes.STATE_PAUSED)) {
if ((state != MediaPlayerCodes.STATE_READY) &&
(state != MediaPlayerCodes.STATE_PLAYING) &&
(state != MediaPlayerCodes.STATE_PAUSED)) {
// draw something loading-like
// TODO animated swf
g.beginFill(0x000033);
@@ -282,7 +282,7 @@ public class SimpleVideoDisplay extends Sprite
g.lineStyle(2, 0xFFFFFF);
g.drawCircle(0, 0, 20);
if (state == VideoPlayerCodes.STATE_PLAYING) {
if (state == MediaPlayerCodes.STATE_PLAYING) {
g.lineStyle(2, 0x00FF00);
g.moveTo(-4, -10);
g.lineTo(-4, 10);
@@ -5,111 +5,31 @@ package com.threerings.flash.media {
import flash.display.DisplayObject;
import flash.events.IEventDispatcher;
import flash.geom.Point;
import com.threerings.util.ValueEvent;
/**
* Dispatched when the state of the videoplayer changes, usually in response to commands
* such as play/pause, etc.
* <b>value</b>: an int state. @see VideoPlayerCodes
*
* @eventType com.threerings.flash.video.VideoPlayerCodes.STATE
*/
[Event(name="state", type="com.threerings.util.ValueEvent")]
/**
* Dispatched when the total duration of the video is known.
* <b>value</b>: a Number expressing the duration in seconds.
*
* @eventType com.threerings.flash.video.VideoPlayerCodes.DURATION
*/
[Event(name="duration", type="com.threerings.util.ValueEvent")]
/**
* Dispatched periodically as the position is updated, during playback.
* <b>value</b>: a Number expressing the position in seconds.
*
* @eventType com.threerings.flash.video.VideoPlayerCodes.POSITION
*/
[Event(name="position", type="com.threerings.util.ValueEvent")]
/**
* Disptached when the size of the video is known.
* <b>value</b>: a Point expressing the width/height.
*
* @eventType com.threerings.flash.video.VideoPlayerCodes.SIZE
* @eventType com.threerings.flash.media.MediaPlayerCodes.SIZE
*/
[Event(name="size", type="com.threerings.util.ValueEvent")]
/**
* Dispatched when there's a problem.
* <b>value</b>: a String error code/message.
*
* @eventType com.threerings.flash.video.VideoPlayerCodes.ERROR
* Implemented by video-playing backends.
*/
[Event(name="error", type="com.threerings.util.ValueEvent")]
/**
* Implemented by video playing backends.
*/
public interface VideoPlayer extends IEventDispatcher
public interface VideoPlayer extends MediaPlayer
{
/**
* Get the actual visualization of the video.
*/
function getDisplay () :DisplayObject;
/**
* @return a VideoPlayerCodes state constant.
*/
function getState () :int;
/**
* Get the size of the video, or null if not yet known.
*/
function getSize () :Point;
/**
* Play the video, if not already.
*/
function play () :void;
/**
* Pause the video, if not already.
*/
function pause () :void;
/**
* Get the duration of the video, in seconds, or NaN if not yet known.
*/
function getDuration () :Number;
/**
* Get the position of the video, in seconds, or NaN if not yet ready.
*/
function getPosition () :Number;
/**
* Seek to the specified position.
*/
function seek (position :Number) :void;
/**
* Set the volume, between 0-1.
*/
function setVolume (volume :Number) :void;
/**
* Get the volume, from 0 to 1.
*/
function getVolume () :Number;
/**
* Unload the video.
*/
function unload () :void;
}
}