[Pkg-javascript-commits] [jarisplayer] 34/80: New: javascript api as other changes thanks to Sascha Kluger from http://projekktor.com

Jonas Smedegaard dr at jones.dk
Tue May 10 08:45:33 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 32b092497ff1e13c65f39a62686c1901b29e97ea
Author: jgmylm <jgmylm at edf201c3-a14d-0410-a11e-aa85364efa9f>
Date:   Sat Nov 6 19:27:41 2010 +0000

    New: javascript api as other changes thanks to Sascha Kluger from http://projekktor.com
    
    git-svn-id: https://jaris.svn.sourceforge.net/svnroot/jaris/trunk@34 edf201c3-a14d-0410-a11e-aa85364efa9f
---
 bin/JarisFLVPlayer.swf           | Bin 21679 -> 23309 bytes
 changes.txt                      |   8 +-
 documentation.txt                |   6 +
 src/jaris/Main.hx                |  71 +++++++-----
 src/jaris/Version.hx             |   6 +-
 src/jaris/events/PlayerEvents.hx |   6 +
 src/jaris/player/JsApi.hx        | 232 +++++++++++++++++++++++++++++++++++++++
 src/jaris/player/Player.hx       |  57 +++++++---
 8 files changed, 341 insertions(+), 45 deletions(-)

diff --git a/bin/JarisFLVPlayer.swf b/bin/JarisFLVPlayer.swf
index 98e7f10..67caf3e 100644
Binary files a/bin/JarisFLVPlayer.swf and b/bin/JarisFLVPlayer.swf differ
diff --git a/changes.txt b/changes.txt
index d92a32f..1e48135 100644
--- a/changes.txt
+++ b/changes.txt
@@ -1,4 +1,10 @@
-Jaris FLV Player v2.0.11 beta - 03/10/2010
+Jaris FLV Player v2.0.12 beta - 06/11/2010
+
+	* Java Script Api to listen for events and control the player.
+	* More player events added to use on JSApi.
+	* All this changes thanks to Sascha Kluger from http://projekktor.com
+	
+Jaris FLV Player v2.0.11 beta - 03/10/2010
 
 	* Removed togglePlay of onFullscreen event since it seems that new flash versions doesnt emits 
 	  the space keydown anymore that affected playback on fullcreen switching.
diff --git a/documentation.txt b/documentation.txt
index 3656d7e..02e0822 100644
--- a/documentation.txt
+++ b/documentation.txt
@@ -86,6 +86,9 @@ Here is the list of variables that you can pass to the player.
     
 	* logoalpha:
       The transparency percent. values permitted 1 to 100
+	  
+	* controls:
+	  To disable the displaying of controls, values: false to hide otherwise defaults to show
     
 	* darkcolor:
       The darker color of player controls in html hexadecimal format
@@ -101,6 +104,9 @@ Here is the list of variables that you can pass to the player.
 	  
 	* aspectratio:
       To override original aspect ratio on first time player load. Allowable values: 1:1, 3:2, 4:3, 5:4, 14:9, 14:10, 16:9, 16:10
+	  
+	* jsapi:
+	  Expose events to javascript functions and enable controlling the player from the outside. Set to any value to enable.
 
 ==================	  
 Keyboard Shortcuts
diff --git a/src/jaris/Main.hx b/src/jaris/Main.hx
index 1f22a97..ecbeb4d 100644
--- a/src/jaris/Main.hx
+++ b/src/jaris/Main.hx
@@ -33,6 +33,7 @@ import jaris.display.Logo;
 import jaris.display.Menu;
 import jaris.display.Poster;
 import jaris.player.controls.Controls;
+import jaris.player.JsApi;
 import jaris.player.InputType;
 import jaris.player.Player;
 import jaris.player.StreamType;
@@ -130,39 +131,53 @@ class Main
 		}
 		
 		//Draw preview image
-		var poster:String = parameters.poster != null ? parameters.poster : "";
-		var posterImage = new Poster(poster);
-		posterImage.setPlayer(player);
-		movieClip.addChild(posterImage);
+		if (parameters.poster != null)
+		{
+			var poster:String = parameters.poster;
+			var posterImage = new Poster(poster);
+			posterImage.setPlayer(player);
+			movieClip.addChild(posterImage);
+		}
 		
 		//Modify Context Menu
 		var menu:Menu = new Menu(player);
 		
 		//Draw logo
-		var logoSource:String = parameters.logo != null ? parameters.logo : "logo.png";
-		var logoPosition:String = parameters.logoposition != null ? parameters.logoposition : "top left";
-		var logoAlpha:Float = parameters.logoalpha != null ? Std.parseFloat(parameters.logoalpha) / 100 : 0.3;
-		var logoWidth:Float = parameters.logowidth != null ? Std.parseFloat(parameters.logowidth) : 130;
-		var logoLink:String = parameters.logolink != null ? parameters.logolink : "http://jaris.sourceforge.net";
-		
-		var logo:Logo = new Logo(logoSource, logoPosition, logoAlpha, logoWidth);
-		logo.setLink(logoLink);
-		movieClip.addChild(logo);
-		
-		
+		if (parameters.logo!=null)
+		{
+			var logoSource:String = parameters.logo != null ? parameters.logo : "logo.png";
+			var logoPosition:String = parameters.logoposition != null ? parameters.logoposition : "top left";
+			var logoAlpha:Float = parameters.logoalpha != null ? Std.parseFloat(parameters.logoalpha) / 100 : 0.3;
+			var logoWidth:Float = parameters.logowidth != null ? Std.parseFloat(parameters.logowidth) : 130;
+			var logoLink:String = parameters.logolink != null ? parameters.logolink : "http://jaris.sourceforge.net";
+			
+			var logo:Logo = new Logo(logoSource, logoPosition, logoAlpha, logoWidth);
+			logo.setLink(logoLink);
+			movieClip.addChild(logo);
+		}
+	
 		//Draw Controls
-		var duration:String = parameters.duration != "" && parameters.duration != null? parameters.duration : "0";
-		var controls:Controls = new Controls(player);
-		
-		var controlColors:Array <String> = ["", "", "", ""];
-		controlColors[0] = parameters.darkcolor != null ? parameters.darkcolor : "";
-		controlColors[1] = parameters.brightcolor != null ? parameters.brightcolor : "";
-		controlColors[2] = parameters.controlcolor != null ? parameters.controlcolor : "";
-		controlColors[3] = parameters.hovercolor != null ? parameters.hovercolor : "";
-		
-		controls.setDurationLabel(duration);
-		controls.setControlColors(controlColors);
-		
-		movieClip.addChild(controls);
+		if (parameters.controls!="false")
+		{
+			var duration:String = parameters.duration != "" && parameters.duration != null? parameters.duration : "0";
+			var controls:Controls = new Controls(player);
+			
+			var controlColors:Array <String> = ["", "", "", ""];
+			controlColors[0] = parameters.darkcolor != null ? parameters.darkcolor : "";
+			controlColors[1] = parameters.brightcolor != null ? parameters.brightcolor : "";
+			controlColors[2] = parameters.controlcolor != null ? parameters.controlcolor : "";
+			controlColors[3] = parameters.hovercolor != null ? parameters.hovercolor : "";
+			
+			controls.setDurationLabel(duration);
+			controls.setControlColors(controlColors);
+			movieClip.addChild(controls);
+		}
+
+		//Expose events to javascript functions and enable controlling the player from the outside
+		if (parameters.jsapi != null)
+		{
+			var jsAPI:JsApi = new JsApi(player);
+			movieClip.addChild(jsAPI);
+		}
 	}
 }
\ No newline at end of file
diff --git a/src/jaris/Version.hx b/src/jaris/Version.hx
index 90ce59d..c914a5c 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.11";
+	public static var NUMBER:String = "2.0.12";
 	public static var STATUS:String = "beta";
-	public static var DATE:String = "05";
-	public static var MONTH:String = "10";
+	public static var DATE:String = "06";
+	public static var MONTH:String = "11";
 	public static var YEAR:String = "2010";
 }
\ No newline at end of file
diff --git a/src/jaris/events/PlayerEvents.hx b/src/jaris/events/PlayerEvents.hx
index 4e71e75..a2d1edf 100644
--- a/src/jaris/events/PlayerEvents.hx
+++ b/src/jaris/events/PlayerEvents.hx
@@ -38,10 +38,14 @@ class PlayerEvents extends Event
 	public static var FULLSCREEN = "onFullscreen";
 	public static var VOLUME_UP = "onVolumeUp";
 	public static var VOLUME_DOWN = "onVolumeDown";
+	public static var VOLUME_CHANGE= "onVolumeChange"; //Nuevo
 	public static var MUTE = "onMute";
 	public static var FORWARD = "onForward";
 	public static var REWIND = "onRewind";
 	public static var PLAY_PAUSE = "onPlayPause";
+	public static var SEEK = "onSeek";
+	public static var TIME = "onTimeUpdate";	
+	public static var PROGRESS = "onProgress";
 	public static var BUFFERING = "onBuffering";
 	public static var NOT_BUFFERING = "onNotBuffering";
 	public static var CONNECTION_FAILED = "onConnectionFailed";
@@ -51,6 +55,7 @@ class PlayerEvents extends Event
 	public static var STOP_CLOSE = "onStopAndClose";
 	public static var RESIZE = "onResize";
 	
+	public var name:String;
 	public var aspectRatio:Float;
 	public var duration:Float;
 	public var fullscreen:Bool;
@@ -74,5 +79,6 @@ class PlayerEvents extends Event
 		width = 0;
 		height = 0;
 		time = 0;
+		name = type;
 	}
 }
\ No newline at end of file
diff --git a/src/jaris/player/JsApi.hx b/src/jaris/player/JsApi.hx
new file mode 100644
index 0000000..59f7257
--- /dev/null
+++ b/src/jaris/player/JsApi.hx
@@ -0,0 +1,232 @@
+/**    
+ * @author Sascha Kluger
+ * @copyright 2010 Jefferson González, Sascha Kluger
+ *
+ * @license 
+ * This file is part of Jaris FLV Player.
+ *
+ * Jaris FLV Player is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License or GNU LESSER GENERAL 
+ * PUBLIC LICENSE as published by the Free Software Foundation, either version 
+ * 3 of the License, or (at your option) any later version.
+ *
+ * Jaris FLV Player is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License and 
+ * GNU LESSER GENERAL PUBLIC LICENSE along with Jaris FLV Player.  If not, 
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+package jaris.player;
+
+//{Libraries
+import flash.system.Capabilities;
+import flash.system.Security;
+import flash.external.ExternalInterface;
+import flash.display.GradientType;
+import flash.events.Event;
+import flash.events.TimerEvent;
+import flash.geom.Matrix;
+import flash.Lib;
+import flash.events.MouseEvent;
+import flash.display.MovieClip;
+import flash.net.NetStream;
+import flash.geom.Rectangle;
+import flash.net.ObjectEncoding;
+import flash.text.AntiAliasType;
+import flash.text.TextField;
+import flash.text.TextFieldAutoSize;
+import flash.text.TextFormat;
+import flash.utils.Timer;
+import jaris.animation.Animation;
+import jaris.display.Loader;
+import jaris.events.PlayerEvents;
+import jaris.player.controls.AspectRatioIcon;
+import jaris.player.controls.FullscreenIcon;
+import jaris.player.controls.PauseIcon;
+import jaris.player.controls.PlayIcon;
+import jaris.player.controls.VolumeIcon;
+import jaris.player.Player;
+import flash.display.Sprite;
+import flash.display.Stage;
+import jaris.utils.Utils;
+//}
+
+/**
+ * Default controls for jaris player
+ */
+class JsApi extends MovieClip {
+	
+	//{Member Variables
+	private var _stage:Stage;
+	private var _movieClip:MovieClip;
+	private var _player:Player;
+	private var _isBuffering:Bool;
+	private var _percentLoaded:Float;
+	private var _externalListeners:Hash<String>;
+	
+	//}
+	
+	
+	//{Constructor
+	public function new(player:Player)
+	{
+		super();
+		_externalListeners = new Hash<String>();
+
+		Security.allowDomain("*");
+		
+		//{Main variables
+		// _stage = Lib.current.stage;
+		// _movieClip = Lib.current;
+		_player = player;
+				
+		_player.addEventListener(PlayerEvents.MOUSE_HIDE, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.MOUSE_SHOW, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.BUFFERING, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.NOT_BUFFERING, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.RESIZE, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.CONNECTION_FAILED, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.ASPECT_RATIO, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.VOLUME_UP, onPlayerEvent);
+		_player.addEventListener(PlayerEvents.VOLUME_DOWN, onPlayerEvent);		
+		_player.addEventListener(PlayerEvents.VOLUME_CHANGE, onPlayerEvent);				
+		_player.addEventListener(PlayerEvents.MUTE, onPlayerEvent);		
+		_player.addEventListener(PlayerEvents.TIME, onPlayerEvent);		
+		_player.addEventListener(PlayerEvents.PROGRESS, onPlayerEvent);				
+		_player.addEventListener(PlayerEvents.SEEK, onPlayerEvent);			
+		
+		ExternalInterface.addCallback("api_get", getAttribute);
+		ExternalInterface.addCallback("api_addlistener", addJsListener);			
+		ExternalInterface.addCallback("api_removelistener", removeJsListener);			
+		ExternalInterface.addCallback("api_play", setPlay);		
+		ExternalInterface.addCallback("api_pause", setPause);
+		ExternalInterface.addCallback("api_seek", setSeek);
+		ExternalInterface.addCallback("api_volume", setVolume);
+	
+
+	}
+		
+	public function getAttribute(attribute:String):Float {
+			
+			switch (attribute) {
+				case 'isBuffering': 
+					return (_isBuffering) ? 1 : 0;
+					
+				case 'isPlaying': 
+					return (_player.isPlaying()) ? 1 : 0;
+				
+				case 'time': 
+					return Math.round(_player.getCurrentTime() * 10) / 10; 
+					
+				case 'loaded': 
+					return _player.getBytesLoaded();
+				
+				case 'volume': 
+					return (_player.getMute()==true) ? 0 : _player.getVolume();
+			}
+			
+			return 0;
+
+
+	}	
+	
+	public function addJsListener(attribute:String, parameter:String):Void {		
+		_externalListeners.set(attribute.toLowerCase(), parameter);
+	}
+		
+	public function removeJsListener(attribute:String):Void {		
+		if (attribute == '*') 
+		{
+			_externalListeners = new Hash<String>();
+			return;
+		}
+		_externalListeners.remove(attribute.toLowerCase());
+	}	
+	
+	public function onPlayerEvent(event:PlayerEvents):Void
+	{
+		var jsFunction = '';
+		var data = {
+				duration:		event.duration,
+				fullscreen:		event.fullscreen,
+				mute:			event.mute,
+				volume:			event.volume,
+				position:		event.time,
+				type:			event.name,
+				loaded:			_player.getBytesLoaded(),
+				total:			_player.getBytesTotal()
+		};
+		
+		if (_externalListeners.exists(event.name.toLowerCase()))
+		{		
+			ExternalInterface.call(_externalListeners.get(event.name.toLowerCase()), data);
+		} 
+		
+		if (_externalListeners.exists('on*'))
+		{		
+			ExternalInterface.call(_externalListeners.get('on*'), data);
+		} 
+	
+	}
+	
+	
+	/**
+	 * Toggles pause or play
+	 */
+	private function setPlay():Void
+	{
+		if (_player.isPlaying()!=true) {
+			_player.togglePlay();
+		}
+	}	
+	
+	/**
+	 * Toggles play or pause
+	 */
+	private function setPause():Void
+	{
+		if (_player.isPlaying()==true) {
+			_player.togglePlay();
+		}
+	}	
+	
+	/**
+	 * Set Seek
+	 */
+	private function setSeek(pos:Float):Void
+	{
+		_player.seek(pos);	
+	}	
+	
+	/**
+	 * Set Volume
+	 */
+	private function setVolume(vol:Float):Void
+	{
+		if (vol <= 0 && _player.getMute()!=true) {
+			_player.toggleMute();
+			_player.setVolume(0);
+			return;
+		}
+		
+		if (_player.getMute() == true) {
+			_player.toggleMute();			
+		}
+		
+		if (vol >= 1) {
+			_player.setVolume(1);
+			return;
+		}
+		
+		_player.setVolume(vol);
+	}	
+		
+	
+}
\ No newline at end of file
diff --git a/src/jaris/player/Player.hx b/src/jaris/player/Player.hx
index 29a12f4..8bc13c6 100644
--- a/src/jaris/player/Player.hx
+++ b/src/jaris/player/Player.hx
@@ -87,6 +87,8 @@ class Player extends EventDispatcher
 	private var _videoMask:Sprite;
 	private var _videoQualityHigh:Bool;
 	private var _mediaDuration:Float;
+	private var _lastTime:Float;	
+	private var _lastProgress:Float;
 	private var _isPlaying:Bool;
 	private var _aspectRatio:Float;
 	private var _currentAspectRatio:String;
@@ -130,6 +132,8 @@ class Player extends EventDispatcher
 		_server = "";
 		_currentAspectRatio = "original";
 		_aspectRatio = 0;
+		_lastTime = 0;
+		_lastProgress = 0;
 		_userSettings = new UserSettings();
 		//}
 		
@@ -161,6 +165,7 @@ class Player extends EventDispatcher
 		toggleQuality();
 		
 		//{Initialize system event listeners
+		_movieClip.addEventListener(Event.ENTER_FRAME, onEnterFrame);
 		_stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
 		_stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
 		_stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreen);
@@ -320,27 +325,21 @@ class Player extends EventDispatcher
 				
 			case M_KEY:
 				toggleMute();
-				callEvents(PlayerEvents.MUTE);
 				
 			case Keyboard.UP:
 				volumeUp();
-				callEvents(PlayerEvents.VOLUME_UP);
 				
 			case Keyboard.DOWN:
 				volumeDown();
-				callEvents(PlayerEvents.VOLUME_DOWN);
 				
 			case Keyboard.RIGHT:
 				forward();
-				callEvents(PlayerEvents.FORWARD);
 				
 			case Keyboard.LEFT:
 				rewind();
-				callEvents(PlayerEvents.REWIND);
 				
 			case Keyboard.SPACE:
 				togglePlay();
-				callEvents(PlayerEvents.PLAY_PAUSE);
 				
 			case X_KEY:
 				stopAndClose();
@@ -477,6 +476,26 @@ class Player extends EventDispatcher
 	}
 	
 	/**
+	 * Broadcast Timeupdate and Duration	 
+	 */	
+	private function onEnterFrame(event:Event):Void
+	{
+		if (getDuration() > 0 && _lastTime != getCurrentTime()) 
+		{
+			_lastTime = getCurrentTime();
+			callEvents(PlayerEvents.TIME);
+		}
+		
+		if (getBytesLoaded() > 0 && _lastProgress < getBytesLoaded()) 
+		{
+			_lastProgress = getBytesLoaded();
+			callEvents(PlayerEvents.PROGRESS);
+		}
+		
+	}		
+	
+	
+	/**
 	 * Triggers when playbacks end on rtmp streaming server
 	 */
 	private function onPlayStatus(info:Dynamic):Void
@@ -946,7 +965,7 @@ class Player extends EventDispatcher
 		}
 		else if(_seekPoints.length > 0 && _streamType == StreamType.PSEUDOSTREAM)
 		{
-			//seekTime = getBestSeekPoint(seekTime);
+			seekTime = getBestSeekPoint(seekTime);
 			
 			if (canSeek(seekTime))
 			{
@@ -983,13 +1002,13 @@ class Player extends EventDispatcher
 		}
 		else if (_streamType == StreamType.RTMP)
 		{
+			// seekTime = getBestSeekPoint(seekTime); //Not Needed?
 			_stream.seek(seekTime);
 		}
 		else if(canSeek(seekTime))
 		{
 			if (_type == InputType.VIDEO || _streamType == StreamType.RTMP)
 			{
-				seekTime = getBestSeekPoint(seekTime);
 				_stream.seek(seekTime);
 			}
 			else if (_type == InputType.AUDIO)
@@ -1004,7 +1023,7 @@ class Player extends EventDispatcher
 				setVolume(_userSettings.getVolume());
 			}
 		}
-		
+		callEvents(PlayerEvents.SEEK);
 		return seekTime;
 	}
 	
@@ -1156,16 +1175,16 @@ class Player extends EventDispatcher
 			}
 			
 			_isPlaying = !_isPlaying;
-			
+			callEvents(PlayerEvents.PLAY_PAUSE);
 			return _isPlaying;
 		}
 		else if(_mediaSource != "")
 		{
 			load(_mediaSource, _type, _streamType, _server);
-			
+			callEvents(PlayerEvents.BUFFERING);
 			return true;
 		}
-		
+		callEvents(PlayerEvents.PLAY_PAUSE);
 		return false;
 	}
 	
@@ -1275,7 +1294,7 @@ class Player extends EventDispatcher
 			setVolume(_userSettings.getVolume());
 		}
 		
-		
+		callEvents(PlayerEvents.MUTE);
 		return isMute;
 	}
 	
@@ -1332,6 +1351,7 @@ class Player extends EventDispatcher
 		//Store volume into user settings
 		_userSettings.setVolume(_volume);
 		
+		callEvents(PlayerEvents.VOLUME_UP);
 		return _volume;
 	}
 	
@@ -1375,6 +1395,7 @@ class Player extends EventDispatcher
 		//Store volume into user settings
 		_userSettings.setVolume(_volume);
 		
+		callEvents(PlayerEvents.VOLUME_DOWN);
 		return _volume;
 	}
 	//}
@@ -1426,6 +1447,14 @@ class Player extends EventDispatcher
 	{
 		var soundTransform:SoundTransform = new SoundTransform();
 		
+		if (volume > _volume) {
+			callEvents(PlayerEvents.VOLUME_UP);
+		}
+
+		if (volume < _volume) {
+			callEvents(PlayerEvents.VOLUME_DOWN);
+		}
+
 		if (volume > 0)
 		{
 			_soundMuted = false;
@@ -1457,6 +1486,8 @@ class Player extends EventDispatcher
 		
 		//Store volume into user settings
 		_userSettings.setVolume(_volume);
+
+		callEvents(PlayerEvents.VOLUME_CHANGE);
 	}
 	
 	/**

-- 
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