[Pkg-javascript-commits] [jarisplayer] 06/80: Use event dispatcher instead of custom mechanism as some other improvements
Jonas Smedegaard
dr at jones.dk
Tue May 10 08:45:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository jarisplayer.
commit 1d48967380986c1b732172d34bc38e556c9e05f1
Author: jgmylm <jgmylm at edf201c3-a14d-0410-a11e-aa85364efa9f>
Date: Wed Mar 10 05:02:27 2010 +0000
Use event dispatcher instead of custom mechanism as some other improvements
git-svn-id: https://jaris.svn.sourceforge.net/svnroot/jaris/trunk@6 edf201c3-a14d-0410-a11e-aa85364efa9f
---
bin/JarisFLVPlayer.swf | Bin 18733 -> 18759 bytes
changes.txt | 9 ++-
src/jaris/Main.hx | 15 +++--
src/jaris/Version.hx | 4 +-
src/jaris/animation/Animation.hx | 2 +-
src/jaris/events/PlayerEvents.hx | 19 +++---
src/jaris/player/AspectRatio.hx | 2 +-
src/jaris/player/InputType.hx | 3 +
src/jaris/player/Player.hx | 115 +++++++++++++++++++---------------
src/jaris/player/StreamType.hx | 2 +-
src/jaris/player/controls/Controls.hx | 36 +++++------
11 files changed, 118 insertions(+), 89 deletions(-)
diff --git a/bin/JarisFLVPlayer.swf b/bin/JarisFLVPlayer.swf
index 52f863e..b29684a 100644
Binary files a/bin/JarisFLVPlayer.swf and b/bin/JarisFLVPlayer.swf differ
diff --git a/changes.txt b/changes.txt
index 060489f..00b5e21 100644
--- a/changes.txt
+++ b/changes.txt
@@ -1,4 +1,11 @@
-Jaris FLV Player v2.0.1 beta - 03/08/2010
+Jaris FLV Player v2.0.2 beta - 03/09/2010
+
+ * Implement EventDispatcher on Player class instead of using custom event mechanism
+ * Fixed not getting initial stage widht and height on IE when using swfobjects
+ * Some more improvements to controls on short heights
+ * Other improvements and code refactoring
+
+Jaris FLV Player v2.0.1 beta - 03/08/2010
* Toggle Quality on Context Menu
* Introduction of type parameter
diff --git a/src/jaris/Main.hx b/src/jaris/Main.hx
index ac3e7a3..d72c315 100644
--- a/src/jaris/Main.hx
+++ b/src/jaris/Main.hx
@@ -23,9 +23,11 @@
package jaris;
+import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
+import flash.events.Event;
import flash.Lib;
import flash.system.Capabilities;
import jaris.display.Logo;
@@ -41,11 +43,14 @@ import jaris.player.StreamType;
*/
class Main
{
- static function main()
+ static var stage:Stage;
+ static var movieClip:MovieClip;
+
+ static function main():Void
{
//Initialize stage and main movie clip
- var stage = Lib.current.stage;
- var movieClip = Lib.current;
+ stage = Lib.current.stage;
+ movieClip = Lib.current;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
@@ -84,8 +89,8 @@ class Main
else
{
//For development purposes
- player.load("http://jaris.sourceforge.net/files/jaris-intro.flv", InputType.VIDEO, StreamType.FILE);
- //player.load("http://jaris.sourceforge.net/files/audio.mp3", InputType.AUDIO, StreamType.FILE);
+ //player.load("http://jaris.sourceforge.net/files/jaris-intro.flv", InputType.VIDEO, StreamType.FILE);
+ player.load("http://jaris.sourceforge.net/files/audio.mp3", InputType.AUDIO, StreamType.FILE);
}
//Modify Context Menu
diff --git a/src/jaris/Version.hx b/src/jaris/Version.hx
index c7198d4..e55dda4 100644
--- a/src/jaris/Version.hx
+++ b/src/jaris/Version.hx
@@ -27,9 +27,9 @@ package jaris;
*/
class Version
{
- public static var NUMBER:String = "2.0.1";
+ public static var NUMBER:String = "2.0.2";
public static var STATUS:String = "beta";
- public static var DATE:String = "08";
+ public static var DATE:String = "09";
public static var MONTH:String = "03";
public static var YEAR:String = "2010";
}
\ No newline at end of file
diff --git a/src/jaris/animation/Animation.hx b/src/jaris/animation/Animation.hx
index 9494a4c..5edaa9d 100644
--- a/src/jaris/animation/Animation.hx
+++ b/src/jaris/animation/Animation.hx
@@ -23,7 +23,7 @@
package jaris.animation;
/**
- * Gives quick access usage to jaris effects
+ * Gives quick access usage to jaris animations
*/
class Animation
{
diff --git a/src/jaris/events/PlayerEvents.hx b/src/jaris/events/PlayerEvents.hx
index 1ca4799..c6ff26c 100644
--- a/src/jaris/events/PlayerEvents.hx
+++ b/src/jaris/events/PlayerEvents.hx
@@ -22,12 +22,14 @@
package jaris.events;
+import flash.events.Event;
+import flash.media.Sound;
import flash.net.NetStream;
/**
- * Stores constants of the player events
+ * Implements a player events
*/
-class PlayerEvents
+class PlayerEvents extends Event
{
public static var ASPECT_RATIO = "onAspectRatio";
public static var MOUSE_SHOW = "onMouseShow";
@@ -43,24 +45,26 @@ class PlayerEvents
public static var NOT_BUFFERING = "onNotBuffering";
public static var CONNECTION_FAILED = "onConnectionFailed";
public static var CONNECTION_SUCCESS = "onConnectionSuccess";
- public static var META_RECIEVED = "onMetaDataReceived";
+ public static var MEDIA_INITIALIZED = "onDataInitialized";
public static var PLAYBACK_FINISHED = "onPlaybackFinished";
public static var STOP_CLOSE = "onStopAndClose";
public static var RESIZE = "onResize";
public var aspectRatio:Float;
+ public var duration:Float;
public var fullscreen:Bool;
public var mute:Bool;
public var volume:Float;
- public var duration:Float;
public var width:Float;
public var height:Float;
public var stream:NetStream;
- public var time:Float;
+ public var sound:Sound;
+ public var time:Float;
-
- public function new()
+ public function new(type:String, bubbles:Bool=false, cancelable:Bool=false)
{
+ super(type, bubbles, cancelable);
+
fullscreen = false;
mute = false;
volume = 1.0;
@@ -69,5 +73,4 @@ class PlayerEvents
height = 0;
time = 0;
}
-
}
\ No newline at end of file
diff --git a/src/jaris/player/AspectRatio.hx b/src/jaris/player/AspectRatio.hx
index a26712f..3b4648b 100644
--- a/src/jaris/player/AspectRatio.hx
+++ b/src/jaris/player/AspectRatio.hx
@@ -23,7 +23,7 @@
package jaris.player;
/**
- * Stores the player used constants
+ * Stores the player used aspect ratio constants
*/
class AspectRatio
{
diff --git a/src/jaris/player/InputType.hx b/src/jaris/player/InputType.hx
index 6a8a2ae..e22e502 100644
--- a/src/jaris/player/InputType.hx
+++ b/src/jaris/player/InputType.hx
@@ -22,6 +22,9 @@
package jaris.player;
+/**
+ * Stores the identifiers for loaded media type
+ */
class InputType
{
public static var AUDIO = "audio";
diff --git a/src/jaris/player/Player.hx b/src/jaris/player/Player.hx
index 00201b2..e346322 100644
--- a/src/jaris/player/Player.hx
+++ b/src/jaris/player/Player.hx
@@ -27,6 +27,7 @@ import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.Event;
+import flash.events.EventDispatcher;
import flash.events.FullScreenEvent;
import flash.events.IOErrorEvent;
import flash.events.KeyboardEvent;
@@ -53,7 +54,7 @@ import jaris.events.PlayerEvents;
/**
* Jaris main video player
*/
-class Player
+class Player extends EventDispatcher
{
//{Member variables
private var _stage:Stage;
@@ -80,9 +81,6 @@ class Player
private var _videoQualityHigh:Bool;
private var _mediaDuration:Float;
private var _isPlaying:Bool;
- private var _eventListeners:Dynamic;
- private var _eventCount:UInt;
- private var _playerEvent:PlayerEvents;
private var _aspectRatio:Float;
private var _originalAspectRatio:Float;
private var _mediaEndReached:Bool;
@@ -99,6 +97,8 @@ class Player
//{Constructor
public function new()
{
+ super();
+
//{Main Variables Init
_stage = Lib.current.stage;
_movieClip = Lib.current;
@@ -109,9 +109,6 @@ class Player
_mediaLoaded = false;
_hideMouseTimer = new Timer(1500);
_checkAudioTimer = new Timer(100);
- _eventListeners = new Array();
- _eventCount = 0;
- _playerEvent = new PlayerEvents();
_seekPoints = new Array();
_downloadCompleted = false;
_startTime = 0;
@@ -155,6 +152,7 @@ class Player
_stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
_stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
_stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreen);
+ _stage.addEventListener(Event.RESIZE, onResize);
_hideMouseTimer.addEventListener(TimerEvent.TIMER, hideMouseTimer);
_checkAudioTimer.addEventListener(TimerEvent.TIMER, checkAudioTimer);
_stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
@@ -266,30 +264,30 @@ class Player
switch(event.keyCode)
{
case Keyboard.TAB:
- _playerEvent.aspectRatio = toggleAspectRatio();
+ toggleAspectRatio();
callEvents(PlayerEvents.ASPECT_RATIO);
case F_KEY:
toggleFullscreen();
case M_KEY:
- _playerEvent.mute = toggleMute();
+ toggleMute();
callEvents(PlayerEvents.MUTE);
case Keyboard.UP:
- _playerEvent.volume = volumeUp();
+ volumeUp();
callEvents(PlayerEvents.VOLUME_UP);
case Keyboard.DOWN:
- _playerEvent.volume = volumeDown();
+ volumeDown();
callEvents(PlayerEvents.VOLUME_DOWN);
case Keyboard.RIGHT:
- _playerEvent.time = forward();
+ forward();
callEvents(PlayerEvents.FORWARD);
case Keyboard.LEFT:
- _playerEvent.time = rewind();
+ rewind();
callEvents(PlayerEvents.REWIND);
case Keyboard.SPACE:
@@ -323,6 +321,15 @@ class Player
}
/**
+ * Resize video player
+ * @param event
+ */
+ private function onResize(event:Event):Void
+ {
+ resizeAndCenterPlayer();
+ }
+
+ /**
* Dispath a full screen event to listeners as redraw player an takes care of some other aspects
* @param event
*/
@@ -350,7 +357,6 @@ class Player
resizeAndCenterPlayer();
- _playerEvent.fullscreen = _fullscreen;
callEvents(PlayerEvents.FULLSCREEN);
}
@@ -412,12 +418,7 @@ class Player
_aspectRatio = AspectRatio.getAspectRatio(_videoWidth, _videoHeight);
_originalAspectRatio = _aspectRatio;
- _playerEvent.duration = _mediaDuration;
- _playerEvent.width = _videoWidth;
- _playerEvent.height = _videoHeight;
- _playerEvent.aspectRatio = _aspectRatio;
-
- callEvents(PlayerEvents.META_RECIEVED);
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
resizeAndCenterPlayer();
}
@@ -439,10 +440,9 @@ class Player
private function onSoundComplete(event:Event)
{
_mediaDuration = _sound.length / 1000;
- _playerEvent.duration = _sound.length / 1000;
_downloadCompleted = true;
- callEvents(PlayerEvents.META_RECIEVED);
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
}
/**
@@ -455,7 +455,7 @@ class Player
{
_soundChannel = _sound.play();
_checkAudioTimer.start();
-
+
_isPlaying = true;
if (_poster != null)
@@ -471,13 +471,8 @@ class Player
_aspectRatio = AspectRatio.getAspectRatio(_videoWidth, _videoHeight);
_originalAspectRatio = _aspectRatio;
- _playerEvent.duration = _mediaDuration;
- _playerEvent.width = _videoWidth;
- _playerEvent.height = _videoHeight;
- _playerEvent.aspectRatio = _aspectRatio;
-
callEvents(PlayerEvents.CONNECTION_SUCCESS);
- callEvents(PlayerEvents.META_RECIEVED);
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
resizeAndCenterPlayer();
}
@@ -508,8 +503,7 @@ class Player
}
_mediaDuration = ((_sound.bytesTotal / _sound.bytesLoaded) * _sound.length) / 1000;
- _playerEvent.duration = _mediaDuration;
- callEvents(PlayerEvents.META_RECIEVED);
+ callEvents(PlayerEvents.MEDIA_INITIALIZED);
}
//}
@@ -521,13 +515,20 @@ class Player
*/
private function callEvents(type:String):Void
{
- for (index in Reflect.fields(_eventListeners))
- {
- if (Reflect.field(_eventListeners, index)[0] == type)
- {
- Reflect.field(_eventListeners, index)[1](_playerEvent);
- }
- }
+ var playerEvent:PlayerEvents = new PlayerEvents(type, true);
+
+ playerEvent.aspectRatio = getAspectRatio();
+ playerEvent.duration = getDuration();
+ playerEvent.fullscreen = isFullscreen();
+ playerEvent.mute = getMute();
+ playerEvent.volume = getVolume();
+ playerEvent.width = _video.width;
+ playerEvent.height = _video.height;
+ playerEvent.stream = getNetStream();
+ playerEvent.sound = getSound();
+ playerEvent.time = getCurrentTime();
+
+ dispatchEvent(playerEvent);
}
/**
@@ -613,18 +614,6 @@ class Player
//{Public methods
/**
- * Adds a listener for player event calls
- * @param type a type from PlayerEvents class
- * @param listener a function
- */
- public function addEventListener(type:String, listener:Dynamic):Void
- {
- _eventListeners[_eventCount] = [type, listener];
-
- _eventCount++;
- }
-
- /**
* Loads a video and starts playing it
* @param video video url to load
*/
@@ -1338,5 +1327,31 @@ class Player
{
return _videoQualityHigh;
}
+
+ /**
+ * The current playing time
+ * @return current playing time in seconds
+ */
+ public function getCurrentTime():Float
+ {
+ var time:Float = 0;
+ if (_type == InputType.VIDEO)
+ {
+ time = _stream.time;
+ }
+ else if (_type == InputType.AUDIO)
+ {
+ if(_soundChannel != null)
+ {
+ time = _soundChannel.position / 1000;
+ }
+ else
+ {
+ time = 0;
+ }
+ }
+
+ return time;
+ }
//}
}
\ No newline at end of file
diff --git a/src/jaris/player/StreamType.hx b/src/jaris/player/StreamType.hx
index 00cd7d9..66f202c 100644
--- a/src/jaris/player/StreamType.hx
+++ b/src/jaris/player/StreamType.hx
@@ -23,7 +23,7 @@
package jaris.player;
/**
- * Some constants for the stream type
+ * Some constants for the stream types
*/
class StreamType
{
diff --git a/src/jaris/player/controls/Controls.hx b/src/jaris/player/controls/Controls.hx
index 0f8959d..739990d 100644
--- a/src/jaris/player/controls/Controls.hx
+++ b/src/jaris/player/controls/Controls.hx
@@ -217,7 +217,7 @@ class Controls extends MovieClip {
_player.addEventListener(PlayerEvents.FULLSCREEN, onPlayerFullScreen);
_player.addEventListener(PlayerEvents.MOUSE_HIDE, onPlayerMouseHide);
_player.addEventListener(PlayerEvents.MOUSE_SHOW, onPlayerMouseShow);
- _player.addEventListener(PlayerEvents.META_RECIEVED, onPlayerMetaData);
+ _player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerMediaInitialized);
_player.addEventListener(PlayerEvents.BUFFERING, onPlayerBuffering);
_player.addEventListener(PlayerEvents.NOT_BUFFERING, onPlayerNotBuffering);
_player.addEventListener(PlayerEvents.RESIZE, onPlayerResize);
@@ -352,7 +352,7 @@ class Controls extends MovieClip {
* Toggles between mute and unmute
* @param event
*/
- public function onVolumeIconClick(event: MouseEvent)
+ private function onVolumeIconClick(event: MouseEvent)
{
_player.toggleMute();
}
@@ -424,19 +424,6 @@ class Controls extends MovieClip {
private function onPlayerFullScreen(event:PlayerEvents)
{
redrawControls();
-
- //Need to check when hardware scaling enabled
- //Limit check to 3 in case of hanging (infinite loop)
- var count:UInt = 1;
- while (_seekBar.width != _stage.stageWidth && count <= 3)
- {
- redrawControls();
- if (_player.isPlaying())
- {
- hideControls();
- }
- count++;
- }
}
/**
@@ -452,13 +439,15 @@ class Controls extends MovieClip {
_player.getVideo().x = (_stage.stageWidth / 2) - (_player.getVideo().width / 2);
}
+
+ redrawControls();
}
/**
* Updates media total time duration.
* @param event
*/
- private function onPlayerMetaData(event:PlayerEvents):Void
+ private function onPlayerMediaInitialized(event:PlayerEvents):Void
{
_totalPlayTimeLabel.text = Utils.formatTime(event.duration);
_playControl.visible = !_player.isPlaying();
@@ -590,7 +579,7 @@ class Controls extends MovieClip {
* Clears all current graphics a draw new ones
*/
private function redrawControls():Void
- {
+ {
_seekBar.graphics.clear();
_trackBar.graphics.clear();
_track.graphics.clear();
@@ -598,6 +587,12 @@ class Controls extends MovieClip {
drawSeekControls();
drawPlayingControls();
+
+ //draw until seekbar width == stage width
+ if(_seekBar.width != _stage.stageWidth)
+ {
+ redrawControls();
+ }
}
/**
@@ -679,8 +674,9 @@ class Controls extends MovieClip {
//Draw controls bar
var barWidth = _stage.stageHeight < 330 ? 45 : 60;
+ var barMargin = _stage.stageHeight < 330 ? 5 : 25;
_controlsBar.x = (_stage.stageWidth - barWidth) + 20;
- _controlsBar.y = 25;
+ _controlsBar.y = barMargin;
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(barWidth, _stage.stageHeight - 75, Utils.degreesToRadians(0), 0, _stage.stageHeight-75);
@@ -689,10 +685,10 @@ class Controls extends MovieClip {
var ratios:Array<UInt> = [0, 255];
_controlsBar.graphics.lineStyle();
_controlsBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
- _controlsBar.graphics.drawRoundRect(0, 0, barWidth, _stage.stageHeight-75, 20, 20);
+ _controlsBar.graphics.drawRoundRect(0, 0, barWidth, _stage.stageHeight-_seekBar.height-(barMargin * 2), 20, 20);
_controlsBar.graphics.endFill();
_controlsBar.width = barWidth;
- _controlsBar.height = _stage.stageHeight - 75;
+ _controlsBar.height = _stage.stageHeight - _seekBar.height - (barMargin * 2);
var topMargin:Float = _stage.stageHeight < 330 ? 5 : 10;
var barCenter:Float = (_controlsBar.width - 20) / 2;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/jarisplayer.git
More information about the Pkg-javascript-commits
mailing list