Handle Video: Flash/HTML5 video player

Requires getID3() and Jaris FLV Player
This commit is contained in:
velocity37
2012-09-23 14:18:12 -07:00
committed by Shish
parent 6cbf1b7865
commit c9bacdf56d
118 changed files with 44098 additions and 0 deletions

204
lib/Jaris/src/jaris/Main.hx Normal file
View File

@@ -0,0 +1,204 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.Lib;
import flash.system.Capabilities;
import jaris.display.Logo;
import jaris.display.Menu;
import jaris.display.Poster;
import jaris.player.controls.Controls;
import jaris.player.newcontrols.NewControls;
import jaris.player.JsApi;
import jaris.player.InputType;
import jaris.player.Player;
import jaris.player.StreamType;
import jaris.player.AspectRatio;
import jaris.player.UserSettings;
import jaris.player.Loop;
/**
* Main jaris player starting point
*/
class Main
{
static var stage:Stage;
static var movieClip:MovieClip;
static function main():Void
{
//Initialize stage and main movie clip
stage = Lib.current.stage;
movieClip = Lib.current;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//Retrieve user settings
var userSettings:UserSettings = new UserSettings();
//Reads flash vars
var parameters:Dynamic<String> = flash.Lib.current.loaderInfo.parameters;
//Initialize and draw player object
var player:Player = new Player();
if (Capabilities.playerType == "PlugIn" || Capabilities.playerType == "ActiveX")
{
var autoStart:Bool = parameters.autostart == "true" || parameters.autostart == "" || parameters.autostart == null? true: false;
var type:String = parameters.type != "" && parameters.type != null? parameters.type : InputType.VIDEO;
var streamType:String = parameters.streamtype != "" && parameters.streamtype != null? parameters.streamtype : StreamType.FILE;
var server:String = parameters.server != "" && parameters.server != null? parameters.server : "";
var aspectRatio:String = parameters.aspectratio != "" && parameters.aspectratio != null? parameters.aspectratio : "";
var bufferTime:Float = parameters.buffertime != "" && parameters.buffertime != null? Std.parseFloat(parameters.buffertime) : 0;
if (aspectRatio != "" && !userSettings.isSet("aspectratio"))
{
switch(aspectRatio)
{
case "1:1":
player.setAspectRatio(AspectRatio._1_1);
case "3:2":
player.setAspectRatio(AspectRatio._3_2);
case "4:3":
player.setAspectRatio(AspectRatio._4_3);
case "5:4":
player.setAspectRatio(AspectRatio._5_4);
case "14:9":
player.setAspectRatio(AspectRatio._14_9);
case "14:10":
player.setAspectRatio(AspectRatio._14_10);
case "16:9":
player.setAspectRatio(AspectRatio._16_9);
case "16:10":
player.setAspectRatio(AspectRatio._16_10);
}
}
else if(userSettings.isSet("aspectratio"))
{
player.setAspectRatio(userSettings.getAspectRatio());
}
player.setType(type);
player.setStreamType(streamType);
player.setServer(server);
player.setVolume(userSettings.getVolume());
player.setBufferTime(bufferTime);
if (autoStart)
{
player.load(parameters.source, type, streamType, server);
}
else
{
player.setSource(parameters.source);
}
player.setHardwareScaling(parameters.hardwarescaling=="true"?true:false);
}
else
{
//For development purposes
if(userSettings.isSet("aspectratio"))
{
player.setAspectRatio(userSettings.getAspectRatio());
}
player.setVolume(userSettings.getVolume());
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);
}
//Draw preview image
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
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
if (parameters.controls != "false")
{
var duration:String = parameters.duration != "" && parameters.duration != null? parameters.duration : "0";
var controlType:Int = parameters.controltype != "" && parameters.controltype != null? Std.parseInt(parameters.controltype) : 0;
var controlSize:Int = parameters.controlsize != "" && parameters.controlsize != null? Std.parseInt(parameters.controlsize) : 0;
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 : "";
controlColors[4] = parameters.seekcolor != null ? parameters.seekcolor : "";
if (controlType == 1) {
var controls:NewControls = new NewControls(player);
controls.setDurationLabel(duration);
controls.setControlColors(controlColors);
controls.setControlSize(controlSize);
movieClip.addChild(controls);
} else {
var controls:Controls = new Controls(player);
controls.setDurationLabel(duration);
controls.setControlColors(controlColors);
movieClip.addChild(controls);
}
}
//Loop the video
if (parameters.loop != null)
{
var loop:Loop = new Loop(player);
}
//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);
}
}
}

View File

@@ -0,0 +1,35 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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;
/**
* Actual jaris flv player version and date
*/
class Version
{
public static var NUMBER:String = "2.0.15";
public static var STATUS:String = "beta";
public static var DATE:String = "27";
public static var MONTH:String = "08";
public static var YEAR:String = "2011";
}

View File

@@ -0,0 +1,77 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.animation;
/**
* Gives quick access usage to jaris animations
*/
class Animation
{
/**
* Quick access to fade in effect
* @param object the object to animate
* @param seconds the duration of the animation
*/
public static function fadeIn(object:Dynamic, seconds:Float):Void
{
var animation:AnimationsBase = new AnimationsBase();
animation.fadeIn(object, seconds);
}
/**
* Quick access to fade out effect
* @param object the object to animate
* @param seconds the duration of the animation
*/
public static function fadeOut(object:Dynamic, seconds:Float):Void
{
var animation:AnimationsBase = new AnimationsBase();
animation.fadeOut(object, seconds);
}
/**
* Quick access to slide in effect
* @param object the object to animate
* @param position could be top, left, bottom or right
* @param seconds the duration of the animation
*/
public static function slideIn(object:Dynamic, position:String, seconds:Float):Void
{
var animation:AnimationsBase = new AnimationsBase();
animation.slideIn(object, position, seconds);
}
/**
* Quick access to slide out effect
* @param object the object to animate
* @param position could be top, left, bottom or right
* @param seconds the duration of the animation
*/
public static function slideOut(object:Dynamic, position:String, seconds:Float):Void
{
var animation:AnimationsBase = new AnimationsBase();
animation.slideOut(object, position, seconds);
}
}

View File

@@ -0,0 +1,306 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.animation;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.TimerEvent;
import flash.Lib;
import flash.utils.Timer;
/**
* Jaris main animations
*/
class AnimationsBase
{
private var _fadeInTimer:Timer;
private var _fadeOutTimer:Timer;
private var _slideInTimer:Timer;
private var _slideInOrigX:Float;
private var _slideInOrigY:Float;
private var _slideInPosition:String;
private var _slideInIncrements:Float;
private var _slideOutTimer:Timer;
private var _slideOutOrigX:Float;
private var _slideOutOrigY:Float;
private var _slideOutPosition:String;
private var _slideOutIncrements:Float;
private var _stage:Stage;
private var _movieClip:MovieClip;
private var _currentObject:Dynamic;
public function new()
{
_stage = Lib.current.stage;
_movieClip = Lib.current;
}
/**
* Moves an object until is shown
* @param event
*/
private function slideInTimer(event:TimerEvent):Void
{
var last:Bool = false;
switch(_slideInPosition)
{
case "top":
if (_currentObject.y >= _slideInOrigY) { last = true; }
_currentObject.y += _slideInIncrements;
case "left":
if (_currentObject.x >= _slideInOrigX) { last = true; }
_currentObject.x += _slideInIncrements;
case "bottom":
if (_currentObject.y <= _slideInOrigY) { last = true; }
_currentObject.y -= _slideInIncrements;
case "right":
if (_currentObject.x <= _slideInOrigX) { last = true; }
_currentObject.x -= _slideInIncrements;
}
if (last)
{
_currentObject.x = _slideInOrigX;
_currentObject.y = _slideInOrigY;
_slideInTimer.stop();
}
}
/**
* Moves an object until is hidden
* @param event
*/
private function slideOutTimer(event:TimerEvent):Void
{
if (((_currentObject.x + _currentObject.width) < 0) || (_currentObject.y + _currentObject.height < 0))
{
_currentObject.visible = false;
_currentObject.x = _slideOutOrigX;
_currentObject.y = _slideOutOrigY;
_slideOutTimer.stop();
}
else if (((_currentObject.x) > _stage.stageWidth) || (_currentObject.y > _stage.stageHeight))
{
_currentObject.visible = false;
_currentObject.x = _slideOutOrigX;
_currentObject.y = _slideOutOrigY;
_slideOutTimer.stop();
}
else
{
switch(_slideOutPosition)
{
case "top":
_currentObject.y -= _slideOutIncrements;
case "left":
_currentObject.x -= _slideOutIncrements;
case "bottom":
_currentObject.y += _slideOutIncrements;
case "right":
_currentObject.x += _slideOutIncrements;
}
}
}
/**
* Lower object transparency until not visible
* @param event
*/
private function fadeOutTimer(event:TimerEvent):Void
{
if (_currentObject.alpha > 0)
{
_currentObject.alpha -= 1 / 10;
}
else
{
_currentObject.visible = false;
_fadeOutTimer.stop();
}
}
/**
* Highers object transparency until visible
* @param event
*/
private function fadeInTimer(event:TimerEvent):Void
{
if (_currentObject.alpha < 1)
{
_currentObject.alpha += 1 / 10;
}
else
{
_fadeInTimer.stop();
}
}
/**
* Effect that moves an object into stage
* @param object the element to move
* @param slidePosition could be top, left bottom or right
* @param speed the time in seconds for duration of the animation
*/
public function slideIn(object:Dynamic, slidePosition:String, speed:Float=1000):Void
{
if (object.visible)
{
object.visible = false;
}
_slideInOrigX = object.x;
_slideInOrigY = object.y;
_slideInPosition = slidePosition;
var increments:Float = 0;
switch(slidePosition)
{
case "top":
object.y = 0 - object.height;
increments = object.height + _slideInOrigY;
case "left":
object.x = 0 - object.width;
increments = object.width + _slideInOrigX;
case "bottom":
object.y = _stage.stageHeight;
increments = _stage.stageHeight - _slideInOrigY;
case "right":
object.x = _stage.stageWidth;
increments = _stage.stageWidth - _slideInOrigX;
}
_slideInIncrements = increments / (speed / 100);
_currentObject = object;
_currentObject.visible = true;
_currentObject.alpha = 1;
_slideInTimer = new Timer(speed / 100);
_slideInTimer.addEventListener(TimerEvent.TIMER, slideInTimer);
_slideInTimer.start();
}
/**
* Effect that moves an object out of stage
* @param object the element to move
* @param slidePosition could be top, left bottom or right
* @param speed the time in seconds for duration of the animation
*/
public function slideOut(object:Dynamic, slidePosition:String, speed:Float=1000):Void
{
if (!object.visible)
{
object.visible = true;
}
_slideOutOrigX = object.x;
_slideOutOrigY = object.y;
_slideOutPosition = slidePosition;
var increments:Float = 0;
switch(slidePosition)
{
case "top":
increments = object.height + _slideOutOrigY;
case "left":
increments = object.width + _slideOutOrigX;
case "bottom":
increments = _stage.stageHeight - _slideOutOrigY;
case "right":
increments = _stage.stageWidth - _slideOutOrigX;
}
_slideOutIncrements = increments / (speed / 100);
_currentObject = object;
_currentObject.visible = true;
_currentObject.alpha = 1;
_slideOutTimer = new Timer(speed / 100);
_slideOutTimer.addEventListener(TimerEvent.TIMER, slideOutTimer);
_slideOutTimer.start();
}
/**
* Effect that dissapears an object from stage
* @param object the element to dissapear
* @param speed the time in seconds for the duration of the animation
*/
public function fadeOut(object:Dynamic, speed:Float=500):Void
{
if (!object.visible)
{
object.visible = true;
}
object.alpha = 1;
_currentObject = object;
_fadeOutTimer = new Timer(speed / 10);
_fadeOutTimer.addEventListener(TimerEvent.TIMER, fadeOutTimer);
_fadeOutTimer.start();
}
/**
* Effect that shows a hidden object an in stage
* @param object the element to show
* @param speed the time in seconds for the duration of the animation
*/
public function fadeIn(object:Dynamic, speed:Float=500):Void
{
if (object.visible)
{
object.visible = false;
}
object.alpha = 0;
_currentObject = object;
_currentObject.visible = true;
_fadeInTimer = new Timer(speed / 10);
_fadeInTimer.addEventListener(TimerEvent.TIMER, fadeInTimer);
_fadeInTimer.start();
}
}

View File

@@ -0,0 +1,181 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.display;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.Lib;
/**
* Draws a loading bar
*/
class Loader extends Sprite
{
private var _stage:Stage;
private var _movieClip:MovieClip;
private var _background:Sprite;
private var _loaderTrack:Sprite;
private var _loaderThumb:Sprite;
private var _visible:Bool;
private var _brightColor:UInt;
private var _controlColor:UInt;
private var _forward:Bool;
public function new()
{
super();
_stage = Lib.current.stage;
_movieClip = Lib.current;
_background = new Sprite();
addChild(_background);
_loaderTrack = new Sprite();
addChild(_loaderTrack);
_loaderThumb = new Sprite();
addChild(_loaderThumb);
_brightColor = 0x4c4c4c;
_controlColor = 0xFFFFFF;
_forward = true;
_visible = true;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
_stage.addEventListener(Event.RESIZE, onResize);
drawLoader();
}
/**
* Animation of a thumb moving on the track
* @param event
*/
private function onEnterFrame(event:Event):Void
{
if (_visible)
{
if (_forward)
{
if ((_loaderThumb.x + _loaderThumb.width) >= (_loaderTrack.x + _loaderTrack.width))
{
_forward = false;
}
else
{
_loaderThumb.x += 10;
}
}
else
{
if (_loaderThumb.x <= _loaderTrack.x)
{
_forward = true;
}
else
{
_loaderThumb.x -= 10;
}
}
}
}
/**
* Redraws the loader to match new stage size
* @param event
*/
private function onResize(event:Event):Void
{
drawLoader();
}
/**
* Draw loader graphics
*/
private function drawLoader():Void
{
//Clear graphics
_background.graphics.clear();
_loaderTrack.graphics.clear();
_loaderThumb.graphics.clear();
//Draw background
var backgroundWidth:Float = (65 / 100) * _stage.stageWidth;
var backgroundHeight:Float = 30;
_background.x = (_stage.stageWidth / 2) - (backgroundWidth / 2);
_background.y = (_stage.stageHeight / 2) - (backgroundHeight / 2);
_background.graphics.lineStyle();
_background.graphics.beginFill(_brightColor, 0.5);
_background.graphics.drawRoundRect(0, 0, backgroundWidth, backgroundHeight, 6, 6);
_background.graphics.endFill();
//Draw track
var trackWidth:Float = (50 / 100) * _stage.stageWidth;
var trackHeight:Float = 15;
_loaderTrack.x = (_stage.stageWidth / 2) - (trackWidth / 2);
_loaderTrack.y = (_stage.stageHeight / 2) - (trackHeight / 2);
_loaderTrack.graphics.lineStyle(2, _controlColor);
_loaderTrack.graphics.drawRect(0, 0, trackWidth, trackHeight);
//Draw thumb
_loaderThumb.x = _loaderTrack.x;
_loaderThumb.y = _loaderTrack.y;
_loaderThumb.graphics.lineStyle();
_loaderThumb.graphics.beginFill(_controlColor, 1);
_loaderThumb.graphics.drawRect(0, 0, trackHeight, trackHeight);
}
/**
* Stops drawing the loader
*/
public function hide():Void
{
this.visible = false;
_visible = false;
}
/**
* Starts drawing the loader
*/
public function show():Void
{
this.visible = true;
_visible = true;
}
/**
* Set loader colors
* @param colors
*/
public function setColors(colors:Array<String>):Void
{
_brightColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x4c4c4c;
_controlColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0xFFFFFF;
drawLoader();
}
}

View File

@@ -0,0 +1,185 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.display;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.Lib;
import flash.net.URLRequest;
/**
* To display an image in jpg, png or gif format as logo
*/
class Logo extends Sprite
{
private var _stage:Stage;
private var _movieClip:MovieClip;
private var _loader:Loader;
private var _position:String;
private var _alpha:Float;
private var _source:String;
private var _width:Float;
private var _link:String;
private var _loading:Bool;
public function new(source:String, position:String, alpha:Float, width:Float=0.0)
{
super();
_stage = Lib.current.stage;
_movieClip = Lib.current;
_loader = new Loader();
_position = position;
_alpha = alpha;
_source = source;
_width = width;
_loading = true;
this.tabEnabled = false;
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onNotLoaded);
_loader.load(new URLRequest(source));
}
/**
* Triggers when the logo image could not be loaded
* @param event
*/
private function onNotLoaded(event:IOErrorEvent):Void
{
//Image not loaded
}
/**
* Triggers when the logo image finished loading.
* @param event
*/
private function onLoaderComplete(event:Event):Void
{
addChild(_loader);
setWidth(_width);
setPosition(_position);
setAlpha(_alpha);
_loading = false;
_stage.addEventListener(Event.RESIZE, onStageResize);
}
/**
* Recalculate logo position on stage resize
* @param event
*/
private function onStageResize(event:Event):Void
{
setPosition(_position);
}
/**
* Opens the an url when the logo is clicked
* @param event
*/
private function onLogoClick(event:MouseEvent):Void
{
Lib.getURL(new URLRequest(_link), "_blank");
}
/**
* Position where logo will be showing
* @param position values could be top left, top right, bottom left, bottom right
*/
public function setPosition(position:String):Void
{
switch(position)
{
case "top left":
this.x = 25;
this.y = 25;
case "top right":
this.x = _stage.stageWidth - this._width - 25;
this.y = 25;
case "bottom left":
this.x = 25;
this.y = _stage.stageHeight - this.height - 25;
case "bottom right":
this.x = _stage.stageWidth - this.width - 25;
this.y = _stage.stageHeight - this.height - 25;
default:
this.x = 25;
this.y = 25;
}
}
/**
* To set logo transparency
* @param alpha
*/
public function setAlpha(alpha:Float):Void
{
this.alpha = alpha;
}
/**
* Sets logo width and recalculates height keeping aspect ratio
* @param width
*/
public function setWidth(width:Float):Void
{
if (width > 0)
{
this.height = (this.height / this.width) * width;
this.width = width;
}
}
/**
* Link that opens when clicked the logo image is clicked
* @param link
*/
public function setLink(link:String):Void
{
_link = link;
this.buttonMode = true;
this.useHandCursor = true;
this.addEventListener(MouseEvent.CLICK, onLogoClick);
}
/**
* To check if the logo stills loading
* @return true if loading false otherwise
*/
public function isLoading():Bool
{
return _loading;
}
}

View File

@@ -0,0 +1,246 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.display;
import flash.display.MovieClip;
import flash.events.ContextMenuEvent;
import flash.Lib;
import flash.net.URLRequest;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import jaris.player.Player;
import jaris.player.AspectRatio;
import jaris.Version;
/**
* Modify original context menu
*/
class Menu
{
private var _movieClip:MovieClip;
public static var _player:Player;
private var _contextMenu:ContextMenu;
private var _jarisVersionMenuItem:ContextMenuItem;
private var _playMenuItem:ContextMenuItem;
private var _fullscreenMenuItem:ContextMenuItem;
private var _aspectRatioMenuItem:ContextMenuItem;
private var _muteMenuItem:ContextMenuItem;
private var _volumeUpMenuItem:ContextMenuItem;
private var _volumeDownMenuItem:ContextMenuItem;
private var _qualityContextMenu:ContextMenuItem;
public function new(player:Player)
{
_movieClip = Lib.current;
_player = player;
//Initialize context menu replacement
_contextMenu = new ContextMenu();
_contextMenu.hideBuiltInItems();
_contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, onMenuOpen);
//Initialize each menu item
_jarisVersionMenuItem = new ContextMenuItem("Jaris Player v" + Version.NUMBER + " " + Version.STATUS, true, true, true);
_jarisVersionMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onJarisVersion);
_playMenuItem = new ContextMenuItem("Play (SPACE)", true, true, true);
_playMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onPlay);
_fullscreenMenuItem = new ContextMenuItem("Fullscreen View (F)");
_fullscreenMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onFullscreen);
_aspectRatioMenuItem = new ContextMenuItem("Aspect Ratio (original) (TAB)");
_aspectRatioMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onAspectRatio);
_muteMenuItem = new ContextMenuItem("Mute (M)");
_muteMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMute);
_volumeUpMenuItem = new ContextMenuItem("Volume + (arrow UP)");
_volumeUpMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onVolumeUp);
_volumeDownMenuItem = new ContextMenuItem("Volume - (arrow DOWN)");
_volumeDownMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onVolumeDown);
_qualityContextMenu = new ContextMenuItem("Lower Quality", true, true, true);
_qualityContextMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onQuality);
//add all context menu items to context menu object
_contextMenu.customItems.push(_jarisVersionMenuItem);
_contextMenu.customItems.push(_playMenuItem);
_contextMenu.customItems.push(_fullscreenMenuItem);
_contextMenu.customItems.push(_aspectRatioMenuItem);
_contextMenu.customItems.push(_muteMenuItem);
_contextMenu.customItems.push(_volumeUpMenuItem);
_contextMenu.customItems.push(_volumeDownMenuItem);
_contextMenu.customItems.push(_qualityContextMenu);
//override default context menu
_movieClip.contextMenu = _contextMenu;
}
/**
* Update context menu item captions depending on player status before showing them
* @param event
*/
private function onMenuOpen(event:ContextMenuEvent):Void
{
if (_player.isPlaying())
{
_playMenuItem.caption = "Pause (SPACE)";
}
else
{
_playMenuItem.caption = "Play (SPACE)";
}
if (_player.isFullscreen())
{
_fullscreenMenuItem.caption = "Normal View";
}
else
{
_fullscreenMenuItem.caption = "Fullscreen View (F)";
}
if (_player.getMute())
{
_muteMenuItem.caption = _player.isFullscreen()?"Unmute":"Unmute (M)";
}
else
{
_muteMenuItem.caption = _player.isFullscreen()?"Mute":"Mute (M)";
}
switch(_player.getAspectRatioString())
{
case "original":
_aspectRatioMenuItem.caption = "Aspect Ratio (1:1) (TAB)";
case "1:1":
_aspectRatioMenuItem.caption = "Aspect Ratio (3:2) (TAB)";
case "3:2":
_aspectRatioMenuItem.caption = "Aspect Ratio (4:3) (TAB)";
case "4:3":
_aspectRatioMenuItem.caption = "Aspect Ratio (5:4) (TAB)";
case "5:4":
_aspectRatioMenuItem.caption = "Aspect Ratio (14:9) (TAB)";
case "14:9":
_aspectRatioMenuItem.caption = "Aspect Ratio (14:10) (TAB)";
case "14:10":
_aspectRatioMenuItem.caption = "Aspect Ratio (16:9) (TAB)";
case "16:9":
_aspectRatioMenuItem.caption = "Aspect Ratio (16:10) (TAB)";
case "16:10":
_aspectRatioMenuItem.caption = "Aspect Ratio (original) (TAB)";
}
if (_player.getQuality())
{
_qualityContextMenu.caption = "Lower Quality";
}
else
{
_qualityContextMenu.caption = "Higher Quality";
}
}
/**
* Open jaris player website
* @param event
*/
private function onJarisVersion(event:ContextMenuEvent)
{
Lib.getURL(new URLRequest("http://jaris.sourceforge.net"), "_blank");
}
/**
* Toggles playback
* @param event
*/
private function onPlay(event:ContextMenuEvent)
{
_player.togglePlay();
}
/**
* Toggles fullscreen
* @param event
*/
private function onFullscreen(event:ContextMenuEvent)
{
_player.toggleFullscreen();
}
/**
* Toggles aspect ratio
* @param event
*/
private function onAspectRatio(event:ContextMenuEvent)
{
_player.toggleAspectRatio();
}
/**
* Toggles mute
* @param event
*/
private function onMute(event:ContextMenuEvent)
{
_player.toggleMute();
}
/**
* Raise volume
* @param event
*/
private function onVolumeUp(event:ContextMenuEvent)
{
_player.volumeUp();
}
/**
* Lower volume
* @param event
*/
private function onVolumeDown(event:ContextMenuEvent)
{
_player.volumeDown();
}
/**
* Toggle video quality
* @param event
*/
private function onQuality(event:ContextMenuEvent)
{
_player.toggleQuality();
}
}

View File

@@ -0,0 +1,170 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.display;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.Lib;
import flash.net.URLRequest;
import jaris.events.PlayerEvents;
import jaris.player.InputType;
import jaris.player.Player;
/**
* To display an png, jpg or gif as preview of video content
*/
class Poster extends Sprite
{
private var _stage:Stage;
private var _movieClip:MovieClip;
private var _loader:Loader;
private var _source:String;
private var _width:Float;
private var _height:Float;
private var _loading:Bool;
private var _loaderStatus:jaris.display.Loader;
private var _player:Player;
public function new(source:String)
{
super();
_stage = Lib.current.stage;
_movieClip = Lib.current;
_loader = new Loader();
_source = source;
_loading = true;
//Reads flash vars
var parameters:Dynamic<String> = flash.Lib.current.loaderInfo.parameters;
//Draw Loader status
var loaderColors:Array <String> = ["", "", "", ""];
loaderColors[0] = parameters.brightcolor != null ? parameters.brightcolor : "";
loaderColors[1] = parameters.controlcolor != null ? parameters.controlcolor : "";
_loaderStatus = new jaris.display.Loader();
_loaderStatus.show();
_loaderStatus.setColors(loaderColors);
addChild(_loaderStatus);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onNotLoaded);
_loader.load(new URLRequest(source));
}
/**
* Triggers when the poster image could not be loaded
* @param event
*/
private function onNotLoaded(event:IOErrorEvent):Void
{
_loaderStatus.hide();
removeChild(_loaderStatus);
}
/**
* Triggers when the poster image finalized loading
* @param event
*/
private function onLoaderComplete(event:Event):Void
{
_loaderStatus.hide();
removeChild(_loaderStatus);
addChild(_loader);
_width = this.width;
_height = this.height;
_loading = false;
_stage.addEventListener(Event.RESIZE, onStageResize);
resizeImage();
}
/**
* Triggers when the stage is resized to resize the poster image
* @param event
*/
private function onStageResize(event:Event):Void
{
resizeImage();
}
private function onPlayerMediaInitialized(event:PlayerEvents)
{
if (_player.getType() == InputType.VIDEO)
{
this.visible = false;
}
}
private function onPlayerPlay(event:PlayerEvents)
{
if (_player.getType() == InputType.VIDEO)
{
this.visible = false;
}
}
private function onPlayBackFinished(event:PlayerEvents)
{
this.visible = true;
}
/**
* Resizes the poster image to take all the stage
*/
private function resizeImage():Void
{
this.height = _stage.stageHeight;
this.width = ((_width / _height) * this.height);
this.x = (_stage.stageWidth / 2) - (this.width / 2);
}
/**
* To check if the poster image stills loading
* @return true if stills loading false if loaded
*/
public function isLoading():Bool
{
return _loading;
}
public function setPlayer(player:Player):Void
{
_player = player;
_player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerMediaInitialized);
_player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayBackFinished);
_player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerPlay);
}
}

View File

@@ -0,0 +1,84 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.events;
import flash.events.Event;
import flash.media.ID3Info;
import flash.media.Sound;
import flash.net.NetStream;
/**
* Implements the player events
*/
class PlayerEvents extends Event
{
public static var ASPECT_RATIO = "onAspectRatio";
public static var MOUSE_SHOW = "onMouseShow";
public static var MOUSE_HIDE = "onMouseHide";
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";
public static var CONNECTION_SUCCESS = "onConnectionSuccess";
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 name:String;
public var aspectRatio:Float;
public var duration:Float;
public var fullscreen:Bool;
public var mute:Bool;
public var volume:Float;
public var width:Float;
public var height:Float;
public var stream:NetStream;
public var sound:Sound;
public var time:Float;
public var id3Info:ID3Info;
public function new(type:String, bubbles:Bool=false, cancelable:Bool=false)
{
super(type, bubbles, cancelable);
fullscreen = false;
mute = false;
volume = 1.0;
duration = 0;
width = 0;
height = 0;
time = 0;
name = type;
}
}

View File

@@ -0,0 +1,49 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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;
/**
* Stores the player used aspect ratio constants
*/
class AspectRatio
{
public static var _1_1:Float = 1 / 1;
public static var _3_2:Float = 3 / 2;
public static var _4_3:Float = 4 / 3;
public static var _5_4:Float = 5 / 4;
public static var _14_9:Float = 14 / 9;
public static var _14_10:Float = 14 / 10;
public static var _16_9:Float = 16 / 9;
public static var _16_10:Float = 16 / 10;
/**
* Calculates the ratio for a given width and height
* @param width
* @param height
* @return aspect ratio
*/
public static function getAspectRatio(width:Float, height:Float):Float
{
return width / height;
}
}

View File

@@ -0,0 +1,32 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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;
/**
* Stores the identifiers for loaded media type
*/
class InputType
{
public static var AUDIO = "audio";
public static var VIDEO = "video";
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,50 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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 jaris.events.PlayerEvents;
//}
/**
* Implements a loop mechanism on the player
*/
class Loop
{
private var _player:Player;
public function new(player:Player)
{
_player = player;
_player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerStop);
}
/**
* Everytime the player stops, the playback is restarted
* @param event
*/
private function onPlayerStop(event:PlayerEvents):Void
{
_player.togglePlay();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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;
/**
* Some constants for the stream types
*/
class StreamType
{
public static var FILE:String = "file";
public static var PSEUDOSTREAM:String = "http";
public static var RTMP:String = "rtmp";
public static var YOUTUBE = "youtube";
}

View File

@@ -0,0 +1,112 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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;
import flash.net.SharedObject;
/**
* To store and retrieve user settings so the player can load them next time it loads.
* In this way player can remember user selected aspect ratio and volume.
*/
class UserSettings
{
private var _settings:SharedObject;
public function new()
{
_settings = SharedObject.getLocal("JarisPlayerUserSettings");
}
//{Methods
/**
* Deletes all user settings
*/
public function deleteSettings():Void
{
_settings.clear();
}
/**
* Checks if a user setting is available
* @param field The name of the setting
* @return true if is set false otherwise
*/
public function isSet(field:String):Bool
{
return Reflect.hasField(_settings.data, field);
}
//}
//{Properties Setters
/**
* Stores the volume value
* @param level
*/
public function setVolume(level:Float):Void
{
_settings.data.volume = level;
_settings.flush();
}
/**
* Stores the aspect ratio value
* @param aspect
*/
public function setAspectRatio(aspectratio:Float):Void
{
_settings.data.aspectratio = aspectratio;
_settings.flush();
}
//}
//{Properties Getters
/**
* The last user selected volume value
* @return Last user selected volume value or default if not set.
*/
public function getVolume():Float
{
if (!isSet("volume"))
{
return 1.0; //The maximum volume value
}
return _settings.data.volume;
}
/**
* The last user selected aspect ratio value
* @return Last user selected aspect ratio value or default if not set.
*/
public function getAspectRatio():Float
{
if (!isSet("aspectratio"))
{
return 0.0; //Equivalent to original
}
return _settings.data.aspectratio;
}
//}
}

View File

@@ -0,0 +1,119 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.controls;
import flash.display.Sprite;
import flash.events.MouseEvent;
class AspectRatioIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle(2, color);
graphics.drawRect(0, 0, _width, _height);
var innerWidth:Float = (60 / 100) * width;
var innerHeight:Float = (60 / 100) * height;
var innerX:Float = (width / 2) - (innerWidth / 2) - 1;
var innerY:Float = (height / 2) - (innerHeight / 2) - 1;
graphics.lineStyle();
graphics.beginFill(color, 1);
graphics.drawRect(innerX, innerY, innerWidth, innerHeight);
graphics.endFill();
graphics.lineStyle();
graphics.beginFill(0, 0);
graphics.drawRect(0, 0, width, height);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,912 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.controls;
//{Libraries
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.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 Controls extends MovieClip {
//{Member Variables
private var _thumb:Sprite;
private var _track:Sprite;
private var _trackDownloaded:Sprite;
private var _scrubbing:Bool;
private var _stage:Stage;
private var _movieClip:MovieClip;
private var _player:Player;
private var _darkColor:UInt;
private var _brightColor:UInt;
private var _controlColor:UInt;
private var _hoverColor:UInt;
private var _hideControlsTimer:Timer;
private var _hideAspectRatioLabelTimer:Timer;
private var _currentPlayTimeLabel:TextField;
private var _totalPlayTimeLabel:TextField;
private var _seekPlayTimeLabel:TextField;
private var _percentLoaded:Float;
private var _controlsVisible:Bool;
private var _seekBar:Sprite;
private var _controlsBar:Sprite;
private var _playControl:PlayIcon;
private var _pauseControl:PauseIcon;
private var _aspectRatioControl:AspectRatioIcon;
private var _fullscreenControl:FullscreenIcon;
private var _volumeIcon:VolumeIcon;
private var _volumeTrack:Sprite;
private var _volumeSlider:Sprite;
private var _loader:Loader;
private var _aspectRatioLabelContainer:Sprite;
private var _aspectRatioLabel:TextField;
private var _textFormat:TextFormat;
//}
//{Constructor
public function new(player:Player)
{
super();
//{Main variables
_stage = Lib.current.stage;
_movieClip = Lib.current;
_player = player;
_darkColor = 0x000000;
_brightColor = 0x4c4c4c;
_controlColor = 0xFFFFFF;
_hoverColor = 0x67A8C1;
_percentLoaded = 0.0;
_hideControlsTimer = new Timer(500);
_hideAspectRatioLabelTimer = new Timer(500);
_controlsVisible = false;
_textFormat = new TextFormat();
_textFormat.font = "arial";
_textFormat.color = _controlColor;
_textFormat.size = 14;
//}
//{Seeking Controls initialization
_seekBar = new Sprite();
addChild(_seekBar);
_trackDownloaded = new Sprite( );
_trackDownloaded.tabEnabled = false;
_seekBar.addChild(_trackDownloaded);
_track = new Sprite( );
_track.tabEnabled = false;
_track.buttonMode = true;
_track.useHandCursor = true;
_seekBar.addChild(_track);
_thumb = new Sprite( );
_thumb.buttonMode = true;
_thumb.useHandCursor = true;
_thumb.tabEnabled = false;
_seekBar.addChild(_thumb);
_currentPlayTimeLabel = new TextField();
_currentPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
_currentPlayTimeLabel.text = "00:00:00";
_currentPlayTimeLabel.tabEnabled = false;
_currentPlayTimeLabel.setTextFormat(_textFormat);
_seekBar.addChild(_currentPlayTimeLabel);
_totalPlayTimeLabel = new TextField();
_totalPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
_totalPlayTimeLabel.text = "00:00:00";
_totalPlayTimeLabel.tabEnabled = false;
_totalPlayTimeLabel.setTextFormat(_textFormat);
_seekBar.addChild(_totalPlayTimeLabel);
_seekPlayTimeLabel = new TextField();
_seekPlayTimeLabel.visible = false;
_seekPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
_seekPlayTimeLabel.text = "00:00:00";
_seekPlayTimeLabel.tabEnabled = false;
_seekPlayTimeLabel.setTextFormat(_textFormat);
addChild(_seekPlayTimeLabel);
//}
//{Playing controls initialization
_controlsBar = new Sprite();
_controlsBar.visible = true;
addChild(_controlsBar);
_playControl = new PlayIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_playControl);
_pauseControl = new PauseIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_pauseControl.visible = false;
_controlsBar.addChild(_pauseControl);
_aspectRatioControl = new AspectRatioIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_aspectRatioControl);
_fullscreenControl = new FullscreenIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_fullscreenControl);
_volumeIcon = new VolumeIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_volumeIcon);
_volumeSlider = new Sprite();
_controlsBar.addChild(_volumeSlider);
_volumeTrack = new Sprite();
_volumeTrack.buttonMode = true;
_volumeTrack.useHandCursor = true;
_volumeTrack.tabEnabled = false;
_controlsBar.addChild(_volumeTrack);
//}
//{Aspect ratio label
_aspectRatioLabelContainer = new Sprite();
addChild(_aspectRatioLabelContainer);
_aspectRatioLabel = new TextField();
_aspectRatioLabel.autoSize = TextFieldAutoSize.CENTER;
_aspectRatioLabel.text = "original";
_aspectRatioLabel.tabEnabled = false;
_aspectRatioLabelContainer.addChild(_aspectRatioLabel);
//}
redrawControls();
//{Loader bar
_loader = new Loader();
_loader.hide();
var loaderColors:Array <String> = ["", "", "", ""];
loaderColors[0] = Std.string(_brightColor);
loaderColors[1] = Std.string(_controlColor);
_loader.setColors(loaderColors);
addChild(_loader);
//}
//{event Listeners
_movieClip.addEventListener(Event.ENTER_FRAME, onEnterFrame);
_thumb.addEventListener(MouseEvent.MOUSE_DOWN, onThumbMouseDown);
_thumb.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
_thumb.addEventListener(MouseEvent.MOUSE_OVER, onThumbHover);
_thumb.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseOut);
_thumb.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
_thumb.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
_track.addEventListener(MouseEvent.CLICK, onTrackClick);
_track.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
_track.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
_playControl.addEventListener(MouseEvent.CLICK, onPlayClick);
_pauseControl.addEventListener(MouseEvent.CLICK, onPauseClick);
_aspectRatioControl.addEventListener(MouseEvent.CLICK, onAspectRatioClick);
_fullscreenControl.addEventListener(MouseEvent.CLICK, onFullscreenClick);
_volumeIcon.addEventListener(MouseEvent.CLICK, onVolumeIconClick);
_volumeTrack.addEventListener(MouseEvent.CLICK, onVolumeTrackClick);
_player.addEventListener(PlayerEvents.MOUSE_HIDE, onPlayerMouseHide);
_player.addEventListener(PlayerEvents.MOUSE_SHOW, onPlayerMouseShow);
_player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerMediaInitialized);
_player.addEventListener(PlayerEvents.BUFFERING, onPlayerBuffering);
_player.addEventListener(PlayerEvents.NOT_BUFFERING, onPlayerNotBuffering);
_player.addEventListener(PlayerEvents.RESIZE, onPlayerResize);
_player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerPlayPause);
_player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerPlaybackFinished);
_player.addEventListener(PlayerEvents.CONNECTION_FAILED, onPlayerStreamNotFound);
_player.addEventListener(PlayerEvents.ASPECT_RATIO, onPlayerAspectRatio);
_stage.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
_stage.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseUp);
_stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
_stage.addEventListener(Event.RESIZE, onStageResize);
_hideControlsTimer.addEventListener(TimerEvent.TIMER, hideControlsTimer);
_hideAspectRatioLabelTimer.addEventListener(TimerEvent.TIMER, hideAspectRatioLabelTimer);
_hideControlsTimer.start();
//}
}
//}
//{Timers
/**
* Hides the playing controls when not moving mouse.
* @param event The timer event associated
*/
private function hideControlsTimer(event:TimerEvent):Void
{
if (_player.isPlaying())
{
if (_controlsVisible)
{
if (_stage.mouseX < _controlsBar.x ||
_stage.mouseX >= _stage.stageWidth - 1 ||
_stage.mouseY >= _stage.stageHeight - 1 ||
_stage.mouseY <= 1
)
{
_controlsVisible = false;
}
}
else
{
hideControls();
_hideControlsTimer.stop();
}
}
}
/**
* Hides aspect ratio label
* @param event
*/
private function hideAspectRatioLabelTimer(event:TimerEvent):Void
{
//wait till fade in effect finish
if (_aspectRatioLabelContainer.alpha >= 1)
{
Animation.fadeOut(_aspectRatioLabelContainer, 300);
_hideAspectRatioLabelTimer.stop();
}
}
//}
//{Events
/**
* Keeps syncronized various elements of the controls like the thumb and download track bar
* @param event
*/
private function onEnterFrame(event:Event):Void
{
if(_player.getDuration() > 0) {
if (_scrubbing)
{
_player.seek(((_thumb.x - _track.x) / _track.width) * _player.getDuration());
}
else
{
_currentPlayTimeLabel.text = Utils.formatTime(_player.getCurrentTime());
_currentPlayTimeLabel.setTextFormat(_textFormat);
_thumb.x = _player.getCurrentTime() / _player.getDuration() * (_track.width-_thumb.width) + _track.x;
}
}
_volumeSlider.height = _volumeTrack.height * (_player.getVolume() / 1.0);
_volumeSlider.y = (_volumeTrack.y + _volumeTrack.height) - _volumeSlider.height;
drawDownloadProgress();
}
/**
* Show playing controls on mouse movement.
* @param event
*/
private function onMouseMove(event:MouseEvent):Void
{
if (_stage.mouseX >= _controlsBar.x)
{
if (!_hideControlsTimer.running)
{
_hideControlsTimer.start();
}
_controlsVisible = true;
showControls();
}
}
/**
* Function fired by a stage resize eventthat redraws the player controls
* @param event
*/
private function onStageResize(event:Event):Void
{
redrawControls();
}
/**
* Toggles pause or play
* @param event
*/
private function onPlayClick(event:MouseEvent):Void
{
_player.togglePlay();
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Toggles pause or play
* @param event
*/
private function onPauseClick(event:MouseEvent):Void
{
_player.togglePlay();
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Toggles betewen aspect ratios
* @param event
*/
private function onAspectRatioClick(event:MouseEvent):Void
{
_player.toggleAspectRatio();
}
/**
* Toggles between window and fullscreen mode
* @param event
*/
private function onFullscreenClick(event:MouseEvent):Void
{
_player.toggleFullscreen();
}
/**
* Toggles between mute and unmute
* @param event
*/
private function onVolumeIconClick(event: MouseEvent):Void
{
_player.toggleMute();
}
/**
* Detect user click on volume track control and change volume according
* @param event
*/
private function onVolumeTrackClick(event:MouseEvent):Void
{
var percent:Float = _volumeTrack.height - _volumeTrack.mouseY;
var volume:Float = 1.0 * (percent / _volumeTrack.height);
_player.setVolume(volume);
}
/**
* Display not found message
* @param event
*/
private function onPlayerStreamNotFound(event:PlayerEvents):Void
{
//todo: to work on this
}
/**
* Shows the loader bar when buffering
* @param event
*/
private function onPlayerBuffering(event:PlayerEvents):Void
{
_loader.show();
}
/**
* Hides loader bar when not buffering
* @param event
*/
private function onPlayerNotBuffering(event:PlayerEvents):Void
{
_loader.hide();
}
/**
* Show the selected aspect ratio
* @param event
*/
private function onPlayerAspectRatio(event:PlayerEvents):Void
{
_hideAspectRatioLabelTimer.stop();
_aspectRatioLabel.text = _player.getAspectRatioString();
drawAspectRatioLabel();
while (_aspectRatioLabelContainer.visible)
{
//wait till fade out finishes
}
Animation.fadeIn(_aspectRatioLabelContainer, 300);
_hideAspectRatioLabelTimer.start();
}
/**
* Monitors playbeack when finishes tu update controls
* @param event
*/
private function onPlayerPlaybackFinished(event:PlayerEvents):Void
{
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
showControls();
}
/**
* Monitors keyboard play pause actions to update icons
* @param event
*/
private function onPlayerPlayPause(event:PlayerEvents):Void
{
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Resizes the video player on windowed mode substracting the seekbar height
* @param event
*/
private function onPlayerResize(event:PlayerEvents):Void
{
if (!_player.isFullscreen())
{
if (_player.getVideo().y + _player.getVideo().height >= _stage.stageHeight)
{
_player.getVideo().height = _stage.stageHeight - _seekBar.height;
_player.getVideo().width = _player.getVideo().height * _player.getAspectRatio();
_player.getVideo().x = (_stage.stageWidth / 2) - (_player.getVideo().width / 2);
}
}
}
/**
* Updates media total time duration.
* @param event
*/
private function onPlayerMediaInitialized(event:PlayerEvents):Void
{
_totalPlayTimeLabel.text = Utils.formatTime(event.duration);
_totalPlayTimeLabel.setTextFormat(_textFormat);
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Hides seekbar if on fullscreen.
* @param event
*/
private function onPlayerMouseHide(event:PlayerEvents):Void
{
if (_seekBar.visible && _player.isFullscreen())
{
Animation.slideOut(_seekBar, "bottom", 1000);
}
}
/**
* Shows seekbar
* @param event
*/
private function onPlayerMouseShow(event:PlayerEvents):Void
{
//Only use slidein effect on fullscreen since switching to windowed mode on
//hardware scaling causes a bug by a slow response on stage height changes
if (_player.isFullscreen() && !_seekBar.visible)
{
Animation.slideIn(_seekBar, "bottom",1000);
}
else
{
_seekBar.visible = true;
}
}
/**
* Translates a user click in to time and seeks to it
* @param event
*/
private function onTrackClick(event:MouseEvent):Void
{
var clickPosition:Float = _track.mouseX;
_player.seek(_player.getDuration() * (clickPosition / _track.width));
}
/**
* Shows a small tooltip showing the time calculated by mouse position
* @param event
*/
private function onTrackMouseMove(event:MouseEvent):Void
{
var clickPosition:Float = _track.mouseX;
_seekPlayTimeLabel.text = Utils.formatTime(_player.getDuration() * (clickPosition / _track.width));
_seekPlayTimeLabel.setTextFormat(_textFormat);
_seekPlayTimeLabel.y = _stage.stageHeight - _seekBar.height - _seekPlayTimeLabel.height - 1;
_seekPlayTimeLabel.x = clickPosition + (_seekPlayTimeLabel.width / 2);
_seekPlayTimeLabel.backgroundColor = _brightColor;
_seekPlayTimeLabel.background = true;
_seekPlayTimeLabel.textColor = _controlColor;
_seekPlayTimeLabel.borderColor = _darkColor;
_seekPlayTimeLabel.border = true;
if (!_seekPlayTimeLabel.visible)
{
Animation.fadeIn(_seekPlayTimeLabel, 300);
}
}
/**
* Hides the tooltip that shows the time calculated by mouse position
* @param event
*/
private function onTrackMouseOut(event:MouseEvent):Void
{
Animation.fadeOut(_seekPlayTimeLabel, 300);
}
/**
* Enables dragging of thumb for seeking media
* @param event
*/
private function onThumbMouseDown(event:MouseEvent):Void
{
_scrubbing = true;
var rectangle:Rectangle = new Rectangle(_track.x, _track.y, _track.width-_thumb.width, 0);
_thumb.startDrag(false, rectangle);
}
/**
* Changes thumb seek control to hover color
* @param event
*/
private function onThumbHover(event:MouseEvent):Void
{
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(_hoverColor);
_thumb.graphics.drawRect(0, (_seekBar.height/2)-(10/2), 10, 10);
_thumb.graphics.endFill();
}
/**
* Changes thumb seek control to control color
* @param event
*/
private function onThumbMouseOut(event:MouseEvent):Void
{
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(_controlColor);
_thumb.graphics.drawRect(0, (_seekBar.height/2)-(10/2), 10, 10);
_thumb.graphics.endFill();
}
/**
* Disables dragging of thumb
* @param event
*/
private function onThumbMouseUp(event:MouseEvent):Void
{
_scrubbing = false;
_thumb.stopDrag( );
}
//}
//{Drawing functions
/**
* Clears all current graphics a draw new ones
*/
private function redrawControls():Void
{
drawSeekControls();
drawPlayingControls();
drawAspectRatioLabel();
}
/**
* Draws the download progress track bar
*/
private function drawDownloadProgress():Void
{
if (_player.getBytesTotal() > 0)
{
var bytesLoaded:Float = _player.getBytesLoaded();
var bytesTotal:Float = _player.getBytesTotal();
_percentLoaded = bytesLoaded / bytesTotal;
}
var position:Float = _player.getStartTime() / _player.getDuration();
//var startPosition:Float = (position * _track.width) + _track.x; //Old way
var startPosition:Float = (position > 0?(position * _track.width):0) + _track.x;
_trackDownloaded.graphics.clear();
_trackDownloaded.graphics.lineStyle();
_trackDownloaded.x = startPosition;
_trackDownloaded.graphics.beginFill(_brightColor, 0xFFFFFF);
_trackDownloaded.graphics.drawRect(0, (_seekBar.height / 2) - (10 / 2), ((_track.width + _track.x) - _trackDownloaded.x) * _percentLoaded, 10);
_trackDownloaded.graphics.endFill();
}
/**
* Draws all seekbar controls
*/
private function drawSeekControls()
{
//Reset sprites for redraw
_seekBar.graphics.clear();
_track.graphics.clear();
_thumb.graphics.clear();
//Draw seek bar
var _seekBarWidth:UInt = _stage.stageWidth;
var _seekBarHeight:UInt = 25;
_seekBar.x = 0;
_seekBar.y = _stage.stageHeight - _seekBarHeight;
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(_seekBarWidth, _seekBarHeight, Utils.degreesToRadians(90), 0, 0);
var colors:Array<UInt> = [_brightColor, _darkColor];
var alphas:Array<UInt> = [1, 1];
var ratios:Array<UInt> = [0, 255];
_seekBar.graphics.lineStyle();
_seekBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
_seekBar.graphics.drawRect(0, 0, _seekBarWidth, _seekBarHeight);
_seekBar.graphics.endFill();
_textFormat.color = _controlColor;
//Draw current play time label
_currentPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_currentPlayTimeLabel.height / 2);
_currentPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
_currentPlayTimeLabel.setTextFormat(_textFormat);
//Draw total play time label
_totalPlayTimeLabel.x = _seekBarWidth - _totalPlayTimeLabel.width;
_totalPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_totalPlayTimeLabel.height / 2);
_totalPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
_totalPlayTimeLabel.setTextFormat(_textFormat);
//Draw download progress
drawDownloadProgress();
//Draw track place holder for drag
_track.x = _currentPlayTimeLabel.width;
_track.graphics.lineStyle(1, _controlColor);
_track.graphics.beginFill(_darkColor, 0);
_track.graphics.drawRect(0, (_seekBarHeight / 2) - (10 / 2), _seekBarWidth - _currentPlayTimeLabel.width - _totalPlayTimeLabel.width, 10);
_track.graphics.endFill();
//Draw thumb
_thumb.x = _currentPlayTimeLabel.width;
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(_controlColor);
_thumb.graphics.drawRect(0, (_seekBarHeight/2)-(10/2), 10, 10);
_thumb.graphics.endFill();
}
/**
* Draws control bar player controls
*/
private function drawPlayingControls():Void
{
//Reset sprites for redraw
_controlsBar.graphics.clear();
_volumeTrack.graphics.clear();
_volumeSlider.graphics.clear();
//Draw controls bar
var barMargin = _stage.stageHeight < 330 ? 5 : 25;
var barHeight = _stage.stageHeight - _seekBar.height - (barMargin * 2);
var barWidth = _stage.stageHeight < 330 ? 45 : 60;
_controlsBar.x = (_stage.stageWidth - barWidth) + 20;
_controlsBar.y = barMargin;
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(barWidth, barHeight, Utils.degreesToRadians(0), 0, barHeight);
var colors:Array<UInt> = [_brightColor, _darkColor];
var alphas:Array<Float> = [0.75, 0.75];
var ratios:Array<UInt> = [0, 255];
_controlsBar.graphics.lineStyle();
_controlsBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
_controlsBar.graphics.drawRoundRect(0, 0, barWidth, barHeight, 20, 20);
_controlsBar.graphics.endFill();
var topMargin:Float = _stage.stageHeight < 330 ? 5 : 10;
var barCenter:Float = (barWidth - 20) / 2;
var buttonSize:Float = ((80 / 100) * (barWidth - 20));
var buttonX:Float = buttonSize / 2;
//Draw playbutton
_playControl.setNormalColor(_controlColor);
_playControl.setHoverColor(_hoverColor);
_playControl.setPosition(barCenter - buttonX, topMargin);
_playControl.setSize(buttonSize, buttonSize);
//Draw pausebutton
_pauseControl.setNormalColor(_controlColor);
_pauseControl.setHoverColor(_hoverColor);
_pauseControl.setPosition(_playControl.x, topMargin);
_pauseControl.setSize(buttonSize, buttonSize);
//Draw aspec ratio button
_aspectRatioControl.setNormalColor(_controlColor);
_aspectRatioControl.setHoverColor(_hoverColor);
_aspectRatioControl.setPosition(_playControl.x, (_playControl.y + buttonSize) + topMargin);
_aspectRatioControl.setSize(buttonSize, buttonSize);
//Draw fullscreen button
_fullscreenControl.setNormalColor(_controlColor);
_fullscreenControl.setHoverColor(_hoverColor);
_fullscreenControl.setPosition(_playControl.x, (_aspectRatioControl.y + _aspectRatioControl.height) + topMargin);
_fullscreenControl.setSize(buttonSize, buttonSize);
//Draw volume icon
_volumeIcon.setNormalColor(_controlColor);
_volumeIcon.setHoverColor(_hoverColor);
_volumeIcon.setPosition(_playControl.x, barHeight - _playControl.height - topMargin);
_volumeIcon.setSize(buttonSize, buttonSize);
//Draw volume track
_volumeTrack.x = _playControl.x;
_volumeTrack.y = (_fullscreenControl.y + _fullscreenControl.height) + topMargin;
_volumeTrack.graphics.lineStyle(1, _controlColor);
_volumeTrack.graphics.beginFill(0x000000, 0);
_volumeTrack.graphics.drawRect(0, 0, _playControl.width / 2, _volumeIcon.y - (_fullscreenControl.y + _fullscreenControl.height) - (topMargin*2));
_volumeTrack.graphics.endFill();
_volumeTrack.x = barCenter - (_volumeTrack.width / 2);
//Draw volume slider
_volumeSlider.x = _volumeTrack.x;
_volumeSlider.y = _volumeTrack.y;
_volumeSlider.graphics.lineStyle();
_volumeSlider.graphics.beginFill(_controlColor, 1);
_volumeSlider.graphics.drawRect(0, 0, _volumeTrack.width, _volumeTrack.height);
_volumeSlider.graphics.endFill();
}
private function drawAspectRatioLabel():Void
{
_aspectRatioLabelContainer.graphics.clear();
_aspectRatioLabelContainer.visible = false;
//Update aspect ratio label
var textFormat:TextFormat = new TextFormat();
textFormat.font = "arial";
textFormat.bold = true;
textFormat.size = 40;
textFormat.color = _controlColor;
_aspectRatioLabel.setTextFormat(textFormat);
_aspectRatioLabel.x = (_stage.stageWidth / 2) - (_aspectRatioLabel.width / 2);
_aspectRatioLabel.y = (_stage.stageHeight / 2) - (_aspectRatioLabel.height / 2);
//Draw aspect ratio label container
_aspectRatioLabelContainer.x = _aspectRatioLabel.x - 10;
_aspectRatioLabelContainer.y = _aspectRatioLabel.y - 10;
_aspectRatioLabelContainer.graphics.lineStyle(3, _controlColor);
_aspectRatioLabelContainer.graphics.beginFill(_brightColor, 1);
_aspectRatioLabelContainer.graphics.drawRoundRect(0, 0, _aspectRatioLabel.width + 20, _aspectRatioLabel.height + 20, 15, 15);
_aspectRatioLabelContainer.graphics.endFill();
_aspectRatioLabel.x = 10;
_aspectRatioLabel.y = 10;
}
//}
//{Private Methods
/**
* Hide the play controls bar
*/
private function hideControls():Void
{
if(_controlsBar.visible)
{
drawPlayingControls();
Animation.slideOut(_controlsBar, "right", 800);
}
}
/**
* Shows play controls bar
*/
private function showControls():Void
{
if(!_controlsBar.visible)
{
drawPlayingControls();
Animation.slideIn(_controlsBar, "right", 800);
}
}
//}
//{Setters
/**
* Sets the player colors and redraw them
* @param colors Array of colors in the following order: darkColor, brightColor, controlColor, hoverColor
*/
public function setControlColors(colors:Array<String>):Void
{
_darkColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x000000;
_brightColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0x4c4c4c;
_controlColor = colors[2].length > 0? Std.parseInt("0x" + colors[2]) : 0xFFFFFF;
_hoverColor = colors[3].length > 0? Std.parseInt("0x" + colors[3]) : 0x67A8C1;
var loaderColors:Array <String> = ["", ""];
loaderColors[0] = colors[1];
loaderColors[1] = colors[2];
_loader.setColors(loaderColors);
redrawControls();
}
/**
* To set the duration label when autostart parameter is false
* @param duration in seconds or formatted string in format hh:mm:ss
*/
public function setDurationLabel(duration:String):Void
{
//Person passed time already formatted
if (duration.indexOf(":") != -1)
{
_totalPlayTimeLabel.text = duration;
}
//Time passed in seconds
else
{
_totalPlayTimeLabel.text = Std.string(Utils.formatTime(Std.parseFloat(duration)));
}
_totalPlayTimeLabel.setTextFormat(_textFormat);
}
//}
}

View File

@@ -0,0 +1,114 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.controls;
import flash.display.Sprite;
import flash.events.MouseEvent;
class FullscreenIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle(2, color);
graphics.beginFill(0x000000, 0);
graphics.drawRoundRect(0, 0, _width, _height, 6, 6);
graphics.endFill();
graphics.lineStyle();
graphics.beginFill(color, 1);
graphics.drawRoundRect(3, 3, 4, 4, 2, 2);
graphics.drawRoundRect(width - 9, 3, 4, 4, 2, 2);
graphics.drawRoundRect(3, height - 9, 4, 4, 2, 2);
graphics.drawRoundRect(width - 9, height - 9, 4, 4, 2, 2);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,112 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.controls;
import flash.display.Sprite;
import flash.events.MouseEvent;
class PauseIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle();
graphics.beginFill(color);
graphics.drawRoundRect(0, 0, (33 / 100) * _width, _height, 6, 6);
graphics.drawRoundRect(_width - ((33 / 100) * _width), 0, (33 / 100) * _width, _height, 6, 6);
graphics.endFill();
graphics.lineStyle();
graphics.beginFill(color, 0);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,107 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.controls;
import flash.display.Sprite;
import flash.events.MouseEvent;
class PlayIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle();
graphics.beginFill(color);
graphics.lineTo(0, _height);
graphics.lineTo(_width, _height / 2);
graphics.lineTo(0, 0);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,110 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.controls;
import flash.display.Sprite;
import flash.events.MouseEvent;
class VolumeIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle();
graphics.beginFill(color, 1);
graphics.drawRect(0, ((50 / 100) * _height) / 2, _width / 2, ((50 / 100) * _height));
graphics.moveTo(_width / 2, ((50 / 100) * _height)/2);
graphics.lineTo(_width, 0);
graphics.lineTo(_width, _height);
graphics.lineTo(_width / 2, ((50 / 100) * _height) + (((50 / 100) * _height) / 2));
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,130 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.newcontrols;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import jaris.utils.Utils;
import flash.display.GradientType;
class AspectRatioIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle(0, color, 0.0);
graphics.beginFill(color, 0);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
var colors:Array<UInt> = [color, color];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
var innerWidth:Float = (70 / 100) * width;
var innerHeight:Float = (40 / 100) * height;
var innerX:Float = (width / 2) - (innerWidth / 2) + 1 ;
var innerY:Float = (height / 2) - (innerHeight / 2) + 1;
graphics.lineStyle();
graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//graphics.beginFill(color, 1);
graphics.drawRect(0, 0, 1, _height+1);
graphics.drawRect(0, 0, _width+1, 1);
graphics.drawRect(_width+1, 0, 1, _height+1);
graphics.drawRect(0, _height+1, _width+1, 1);
graphics.drawRect(innerX, innerY, innerWidth, innerHeight);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,130 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.newcontrols;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import jaris.utils.Utils;
import flash.display.GradientType;
class FullscreenIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle(0, color, 0.0);
graphics.beginFill(color, 0);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
var arrowWidth = Std.int(_width / 2 * 0.8);
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
var colors:Array<UInt> = [color, color];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
graphics.lineStyle(0, color, 0, true);
graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//graphics.beginFill(color, 0);
graphics.drawRect(0, 0, arrowWidth, 2);
graphics.drawRect(0, 2, 2, arrowWidth-2);
graphics.drawRect(_width-arrowWidth+1, 0, arrowWidth, 2);
graphics.drawRect(_width-1, 2, 2, arrowWidth-2);
graphics.drawRect(0, _height-arrowWidth+2, 2, arrowWidth);
graphics.drawRect(2, _height, arrowWidth-2, 2);
graphics.drawRect(_width-1, _height-arrowWidth+2, 2, arrowWidth-2);
graphics.drawRect(_width-arrowWidth+1, _height, arrowWidth, 2);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,195 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.newcontrols;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.Lib;
import flash.geom.Matrix;
import jaris.utils.Utils;
import flash.display.GradientType;
/**
* Draws a loading bar
*/
class Loader extends Sprite
{
private var _stage:Stage;
private var _movieClip:MovieClip;
private var _background:Sprite;
private var _loaderTrack:Sprite;
private var _loaderThumb:Sprite;
private var _visible:Bool;
private var _darkColor:UInt;
private var _controlColor:UInt;
private var _seekColor:UInt;
private var _forward:Bool;
public function new()
{
super();
_stage = Lib.current.stage;
_movieClip = Lib.current;
_background = new Sprite();
addChild(_background);
_loaderTrack = new Sprite();
addChild(_loaderTrack);
_loaderThumb = new Sprite();
addChild(_loaderThumb);
_darkColor = 0x000000;
_controlColor = 0xFFFFFF;
_seekColor = 0x747474;
_forward = true;
_visible = true;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
_stage.addEventListener(Event.RESIZE, onResize);
drawLoader();
}
/**
* Animation of a thumb moving on the track
* @param event
*/
private function onEnterFrame(event:Event):Void
{
if (_visible)
{
if (_forward)
{
if ((_loaderThumb.x + _loaderThumb.width) >= (_loaderTrack.x + _loaderTrack.width))
{
_forward = false;
}
else
{
_loaderThumb.x += 10;
}
}
else
{
if (_loaderThumb.x <= _loaderTrack.x)
{
_forward = true;
}
else
{
_loaderThumb.x -= 10;
}
}
}
}
/**
* Redraws the loader to match new stage size
* @param event
*/
private function onResize(event:Event):Void
{
drawLoader();
}
/**
* Draw loader graphics
*/
private function drawLoader():Void
{
//Clear graphics
_background.graphics.clear();
_loaderTrack.graphics.clear();
_loaderThumb.graphics.clear();
//Draw background
var backgroundWidth:Float = (65 / 100) * _stage.stageWidth;
var backgroundHeight:Float = 30;
_background.x = (_stage.stageWidth / 2) - (backgroundWidth / 2);
_background.y = (_stage.stageHeight / 2) - (backgroundHeight / 2);
_background.graphics.lineStyle();
_background.graphics.beginFill(_darkColor, 0.75);
_background.graphics.drawRoundRect(0, 0, backgroundWidth, backgroundHeight, 6, 6);
_background.graphics.endFill();
//Draw track
var trackWidth:Float = (50 / 100) * _stage.stageWidth;
var trackHeight:Float = 11;
_loaderTrack.x = (_stage.stageWidth / 2) - (trackWidth / 2);
_loaderTrack.y = (_stage.stageHeight / 2) - (trackHeight / 2);
_loaderTrack.graphics.lineStyle();
_loaderTrack.graphics.beginFill(_seekColor, 0.3);
_loaderTrack.graphics.drawRoundRect(0, trackHeight/2/2, trackWidth, trackHeight/2, 5, 5);
//Draw thumb
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(trackHeight*3, trackHeight, Utils.degreesToRadians(-90), trackHeight*3, 0);
var colors:Array<UInt> = [_controlColor, _controlColor];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
_loaderThumb.x = _loaderTrack.x;
_loaderThumb.y = _loaderTrack.y;
_loaderThumb.graphics.lineStyle();
_loaderThumb.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//_loaderThumb.graphics.beginFill(_controlColor, 1);
_loaderThumb.graphics.drawRoundRect(0, 0, trackHeight*3, trackHeight, 10, 10);
}
/**
* Stops drawing the loader
*/
public function hide():Void
{
this.visible = false;
_visible = false;
}
/**
* Starts drawing the loader
*/
public function show():Void
{
this.visible = true;
_visible = true;
}
/**
* Set loader colors
* @param colors
*/
public function setColors(colors:Array<String>):Void
{
_darkColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x000000;
_controlColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0xFFFFFF;
_seekColor = colors[2].length > 0? Std.parseInt("0x" + colors[2]) : 0x747474;
drawLoader();
}
}

View File

@@ -0,0 +1,945 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.newcontrols;
//{Libraries
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.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.Timer;
import jaris.animation.Animation;
import jaris.events.PlayerEvents;
import jaris.player.newcontrols.Loader;
import jaris.player.newcontrols.AspectRatioIcon;
import jaris.player.newcontrols.FullscreenIcon;
import jaris.player.newcontrols.PauseIcon;
import jaris.player.newcontrols.PlayIcon;
import jaris.player.newcontrols.VolumeIcon;
import jaris.player.Player;
import flash.display.Sprite;
import flash.display.Stage;
import jaris.utils.Utils;
//}
/**
* Default controls for jaris player
*/
class NewControls extends MovieClip {
//{Member Variables
private var _thumb:Sprite;
private var _track:Sprite;
private var _trackDownloaded:Sprite;
private var _scrubbing:Bool;
private var _stage:Stage;
private var _movieClip:MovieClip;
private var _player:Player;
private var _darkColor:UInt;
private var _brightColor:UInt;
private var _seekColor:UInt;
private var _controlColor:UInt;
private var _controlSize:Int;
private var _hoverColor:UInt;
private var _hideControlsTimer:Timer;
private var _hideAspectRatioLabelTimer:Timer;
private var _currentPlayTimeLabel:TextField;
private var _totalPlayTimeLabel:TextField;
private var _seekPlayTimeLabel:TextField;
private var _percentLoaded:Float;
private var _controlsVisible:Bool;
private var _seekBar:Sprite;
private var _controlsBar:Sprite;
private var _playControl:PlayIcon;
private var _pauseControl:PauseIcon;
private var _aspectRatioControl:AspectRatioIcon;
private var _fullscreenControl:FullscreenIcon;
private var _volumeIcon:VolumeIcon;
private var _volumeTrack:Sprite;
private var _volumeSlider:Sprite;
private var _loader:Loader;
private var _aspectRatioLabelContainer:Sprite;
private var _aspectRatioLabel:TextField;
private var _textFormat:TextFormat;
//}
//{Constructor
public function new(player:Player)
{
super();
//{Main variables
_stage = Lib.current.stage;
_movieClip = Lib.current;
_player = player;
_darkColor = 0x000000;
_brightColor = 0x4c4c4c;
_controlColor = 0xFFFFFF;
_hoverColor = 0x67A8C1;
_seekColor = 0x7c7c7c;
_controlSize = 40;
_percentLoaded = 0.0;
_hideControlsTimer = new Timer(500);
_hideAspectRatioLabelTimer = new Timer(500);
_controlsVisible = false;
_textFormat = new TextFormat();
_textFormat.font = "arial";
_textFormat.color = _controlColor;
_textFormat.size = 14;
//}
//{Playing controls initialization
_controlsBar = new Sprite();
_controlsBar.visible = true;
addChild(_controlsBar);
_playControl = new PlayIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_playControl);
_pauseControl = new PauseIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_pauseControl.visible = false;
_controlsBar.addChild(_pauseControl);
_aspectRatioControl = new AspectRatioIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_aspectRatioControl);
_fullscreenControl = new FullscreenIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_fullscreenControl);
_volumeIcon = new VolumeIcon(0, 0, 0, 0, _controlColor, _hoverColor);
_controlsBar.addChild(_volumeIcon);
_volumeSlider = new Sprite();
_volumeSlider.visible = false;
_controlsBar.addChild(_volumeSlider);
_volumeTrack = new Sprite();
_volumeTrack.visible = false;
_volumeTrack.buttonMode = true;
_volumeTrack.useHandCursor = true;
_volumeTrack.tabEnabled = false;
_controlsBar.addChild(_volumeTrack);
//}
//{Seeking Controls initialization
_seekBar = new Sprite();
_controlsBar.addChild(_seekBar);
_trackDownloaded = new Sprite( );
_trackDownloaded.tabEnabled = false;
_seekBar.addChild(_trackDownloaded);
_track = new Sprite( );
_track.tabEnabled = false;
_track.buttonMode = true;
_track.useHandCursor = true;
_seekBar.addChild(_track);
_thumb = new Sprite( );
_thumb.buttonMode = true;
_thumb.useHandCursor = true;
_thumb.tabEnabled = false;
_seekBar.addChild(_thumb);
_currentPlayTimeLabel = new TextField();
_currentPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
_currentPlayTimeLabel.text = "00:00:00";
_currentPlayTimeLabel.tabEnabled = false;
_currentPlayTimeLabel.setTextFormat(_textFormat);
_seekBar.addChild(_currentPlayTimeLabel);
_totalPlayTimeLabel = new TextField();
_totalPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
_totalPlayTimeLabel.text = "00:00:00";
_totalPlayTimeLabel.tabEnabled = false;
_totalPlayTimeLabel.setTextFormat(_textFormat);
_seekBar.addChild(_totalPlayTimeLabel);
_seekPlayTimeLabel = new TextField();
_seekPlayTimeLabel.visible = false;
_seekPlayTimeLabel.autoSize = TextFieldAutoSize.LEFT;
_seekPlayTimeLabel.text = "00:00:00";
_seekPlayTimeLabel.tabEnabled = false;
_seekPlayTimeLabel.setTextFormat(_textFormat);
addChild(_seekPlayTimeLabel);
//}
//{Aspect ratio label
_aspectRatioLabelContainer = new Sprite();
addChild(_aspectRatioLabelContainer);
_aspectRatioLabel = new TextField();
_aspectRatioLabel.autoSize = TextFieldAutoSize.CENTER;
_aspectRatioLabel.text = "original";
_aspectRatioLabel.tabEnabled = false;
_aspectRatioLabelContainer.addChild(_aspectRatioLabel);
//}
redrawControls();
//{Loader bar
_loader = new Loader();
_loader.hide();
var loaderColors:Array <String> = ["", "", "", ""];
loaderColors[0] = Std.string(_darkColor);
loaderColors[1] = Std.string(_controlColor);
loaderColors[2] = Std.string(_seekColor);
_loader.setColors(loaderColors);
addChild(_loader);
//}
//{event Listeners
_movieClip.addEventListener(Event.ENTER_FRAME, onEnterFrame);
_thumb.addEventListener(MouseEvent.MOUSE_DOWN, onThumbMouseDown);
_thumb.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
_thumb.addEventListener(MouseEvent.MOUSE_OVER, onThumbHover);
_thumb.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseOut);
_thumb.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
_thumb.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
_track.addEventListener(MouseEvent.CLICK, onTrackClick);
_track.addEventListener(MouseEvent.MOUSE_MOVE, onTrackMouseMove);
_track.addEventListener(MouseEvent.MOUSE_OUT, onTrackMouseOut);
_playControl.addEventListener(MouseEvent.CLICK, onPlayClick);
_pauseControl.addEventListener(MouseEvent.CLICK, onPauseClick);
_aspectRatioControl.addEventListener(MouseEvent.CLICK, onAspectRatioClick);
_fullscreenControl.addEventListener(MouseEvent.CLICK, onFullscreenClick);
_volumeIcon.addEventListener(MouseEvent.CLICK, onVolumeIconClick);
_volumeTrack.addEventListener(MouseEvent.CLICK, onVolumeTrackClick);
_player.addEventListener(PlayerEvents.MOUSE_HIDE, onPlayerMouseHide);
_player.addEventListener(PlayerEvents.MOUSE_SHOW, onPlayerMouseShow);
_player.addEventListener(PlayerEvents.MEDIA_INITIALIZED, onPlayerMediaInitialized);
_player.addEventListener(PlayerEvents.BUFFERING, onPlayerBuffering);
_player.addEventListener(PlayerEvents.NOT_BUFFERING, onPlayerNotBuffering);
_player.addEventListener(PlayerEvents.RESIZE, onPlayerResize);
_player.addEventListener(PlayerEvents.PLAY_PAUSE, onPlayerPlayPause);
_player.addEventListener(PlayerEvents.PLAYBACK_FINISHED, onPlayerPlaybackFinished);
_player.addEventListener(PlayerEvents.CONNECTION_FAILED, onPlayerStreamNotFound);
_player.addEventListener(PlayerEvents.ASPECT_RATIO, onPlayerAspectRatio);
_stage.addEventListener(MouseEvent.MOUSE_UP, onThumbMouseUp);
_stage.addEventListener(MouseEvent.MOUSE_OUT, onThumbMouseUp);
_stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
_stage.addEventListener(Event.RESIZE, onStageResize);
_hideControlsTimer.addEventListener(TimerEvent.TIMER, hideControlsTimer);
_hideAspectRatioLabelTimer.addEventListener(TimerEvent.TIMER, hideAspectRatioLabelTimer);
_hideControlsTimer.start();
//}
}
//}
//{Timers
/**
* Hides the playing controls when not moving mouse.
* @param event The timer event associated
*/
private function hideControlsTimer(event:TimerEvent):Void
{
if (_player.isPlaying())
{
if (_controlsVisible)
{
if (_stage.mouseX < _controlsBar.x ||
_stage.mouseX >= _stage.stageWidth - 1 ||
_stage.mouseY >= _stage.stageHeight - 1 ||
_stage.mouseY <= 1
)
{
_controlsVisible = false;
}
}
else
{
hideControls();
_hideControlsTimer.stop();
}
}
}
/**
* Hides aspect ratio label
* @param event
*/
private function hideAspectRatioLabelTimer(event:TimerEvent):Void
{
//wait till fade in effect finish
if (_aspectRatioLabelContainer.alpha >= 1)
{
Animation.fadeOut(_aspectRatioLabelContainer, 300);
_hideAspectRatioLabelTimer.stop();
}
}
//}
//{Events
/**
* Keeps syncronized various elements of the controls like the thumb and download track bar
* @param event
*/
private function onEnterFrame(event:Event):Void
{
if(_player.getDuration() > 0) {
if (_scrubbing)
{
_player.seek(((_thumb.x - _track.x) / _track.width) * _player.getDuration());
}
else
{
_currentPlayTimeLabel.text = Utils.formatTime(_player.getCurrentTime());
_currentPlayTimeLabel.setTextFormat(_textFormat);
_thumb.x = _player.getCurrentTime() / _player.getDuration() * (_track.width-_thumb.width) + _track.x;
}
}
_volumeSlider.height = _volumeTrack.height * (_player.getVolume() / 1.0);
_volumeSlider.y = (_volumeTrack.y + _volumeTrack.height) - _volumeSlider.height;
drawDownloadProgress();
}
/**
* Show playing controls on mouse movement.
* @param event
*/
private function onMouseMove(event:MouseEvent):Void
{
if (_stage.mouseX >= _controlsBar.x)
{
if (!_hideControlsTimer.running)
{
_hideControlsTimer.start();
}
_controlsVisible = true;
showControls();
}
}
/**
* Function fired by a stage resize eventthat redraws the player controls
* @param event
*/
private function onStageResize(event:Event):Void
{
redrawControls();
}
/**
* Toggles pause or play
* @param event
*/
private function onPlayClick(event:MouseEvent):Void
{
_player.togglePlay();
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Toggles pause or play
* @param event
*/
private function onPauseClick(event:MouseEvent):Void
{
_player.togglePlay();
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Toggles betewen aspect ratios
* @param event
*/
private function onAspectRatioClick(event:MouseEvent):Void
{
_player.toggleAspectRatio();
}
/**
* Toggles between window and fullscreen mode
* @param event
*/
private function onFullscreenClick(event:MouseEvent):Void
{
_player.toggleFullscreen();
}
/**
* Toggles between mute and unmute
* @param event
*/
private function onVolumeIconClick(event: MouseEvent):Void
{
if (_volumeSlider.visible) {
_volumeSlider.visible = false;
_volumeTrack.visible = false;
} else {
_volumeSlider.visible = true;
_volumeTrack.visible = true;
}
}
/**
* Detect user click on volume track control and change volume according
* @param event
*/
private function onVolumeTrackClick(event:MouseEvent):Void
{
var percent:Float = _volumeTrack.height - _volumeTrack.mouseY;
var volume:Float = 1.0 * (percent / _volumeTrack.height);
_player.setVolume(volume);
}
/**
* Display not found message
* @param event
*/
private function onPlayerStreamNotFound(event:PlayerEvents):Void
{
//todo: to work on this
}
/**
* Shows the loader bar when buffering
* @param event
*/
private function onPlayerBuffering(event:PlayerEvents):Void
{
_loader.show();
}
/**
* Hides loader bar when not buffering
* @param event
*/
private function onPlayerNotBuffering(event:PlayerEvents):Void
{
_loader.hide();
}
/**
* Show the selected aspect ratio
* @param event
*/
private function onPlayerAspectRatio(event:PlayerEvents):Void
{
_hideAspectRatioLabelTimer.stop();
_aspectRatioLabel.text = _player.getAspectRatioString();
drawAspectRatioLabel();
while (_aspectRatioLabelContainer.visible)
{
//wait till fade out finishes
}
Animation.fadeIn(_aspectRatioLabelContainer, 1);
_hideAspectRatioLabelTimer.start();
}
/**
* Monitors playbeack when finishes tu update controls
* @param event
*/
private function onPlayerPlaybackFinished(event:PlayerEvents):Void
{
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
showControls();
}
/**
* Monitors keyboard play pause actions to update icons
* @param event
*/
private function onPlayerPlayPause(event:PlayerEvents):Void
{
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Resizes the video player on windowed mode substracting the seekbar height
* @param event
*/
private function onPlayerResize(event:PlayerEvents):Void
{
}
/**
* Updates media total time duration.
* @param event
*/
private function onPlayerMediaInitialized(event:PlayerEvents):Void
{
_totalPlayTimeLabel.text = Utils.formatTime(event.duration);
_totalPlayTimeLabel.setTextFormat(_textFormat);
_playControl.visible = !_player.isPlaying();
_pauseControl.visible = _player.isPlaying();
}
/**
* Hides seekbar if on fullscreen.
* @param event
*/
private function onPlayerMouseHide(event:PlayerEvents):Void
{
if (_controlsBar.visible && _player.isFullscreen())
{
hideControls();
}
}
/**
* Shows seekbar
* @param event
*/
private function onPlayerMouseShow(event:PlayerEvents):Void
{
//Only use slidein effect on fullscreen since switching to windowed mode on
//hardware scaling causes a bug by a slow response on stage height changes
if (_player.isFullscreen() && !_controlsBar.visible)
{
_controlsBar.visible = true;
}
else if (!_controlsBar.visible)
{
_controlsBar.visible = true;
}
}
/**
* Translates a user click in to time and seeks to it
* @param event
*/
private function onTrackClick(event:MouseEvent):Void
{
var clickPosition:Float = _track.mouseX;
_player.seek(_player.getDuration() * (clickPosition / _track.width));
}
/**
* Shows a small tooltip showing the time calculated by mouse position
* @param event
*/
private function onTrackMouseMove(event:MouseEvent):Void
{
var clickPosition:Float = _track.mouseX;
_seekPlayTimeLabel.text = Utils.formatTime(_player.getDuration() * (clickPosition / _track.width));
_seekPlayTimeLabel.setTextFormat(_textFormat);
_seekPlayTimeLabel.y = _stage.stageHeight - _seekBar.height - _seekPlayTimeLabel.height - 1;
_seekPlayTimeLabel.x = clickPosition + (_seekPlayTimeLabel.width / 2) + (_playControl.width + 10) * 2;
_seekPlayTimeLabel.backgroundColor = _darkColor;
_seekPlayTimeLabel.background = true;
_seekPlayTimeLabel.textColor = _controlColor;
_seekPlayTimeLabel.borderColor = _darkColor;
_seekPlayTimeLabel.border = true;
if (!_seekPlayTimeLabel.visible)
{
_seekPlayTimeLabel.visible = true;
}
}
/**
* Hides the tooltip that shows the time calculated by mouse position
* @param event
*/
private function onTrackMouseOut(event:MouseEvent):Void
{
_seekPlayTimeLabel.visible = false;
}
/**
* Enables dragging of thumb for seeking media
* @param event
*/
private function onThumbMouseDown(event:MouseEvent):Void
{
_scrubbing = true;
var rectangle:Rectangle = new Rectangle(_track.x, _track.y, _track.width-_thumb.width, 0);
_thumb.startDrag(false, rectangle);
}
/**
* Changes thumb seek control to hover color
* @param event
*/
private function onThumbHover(event:MouseEvent):Void
{
_thumb.graphics.lineStyle();
_thumb.graphics.beginFill(_hoverColor);
_thumb.graphics.drawRoundRect(0, (_seekBar.height/2)-(11/2), 11, 11, 10, 10);
_thumb.graphics.endFill();
}
/**
* Changes thumb seek control to control color
* @param event
*/
private function onThumbMouseOut(event:MouseEvent):Void
{
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(11, 11, Utils.degreesToRadians(-90), 11, 0);
var colors:Array<UInt> = [_controlColor, _controlColor];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
_thumb.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
_thumb.graphics.drawRoundRect(0, (_seekBar.height / 2) - (11 / 2), 11, 11, 10, 10);
_thumb.graphics.endFill();
}
/**
* Disables dragging of thumb
* @param event
*/
private function onThumbMouseUp(event:MouseEvent):Void
{
_scrubbing = false;
_thumb.stopDrag( );
}
//}
//{Drawing functions
/**
* Clears all current graphics a draw new ones
*/
private function redrawControls():Void
{
drawControls();
drawAspectRatioLabel();
}
/**
* Draws the download progress track bar
*/
private function drawDownloadProgress():Void
{
if (_player.getBytesTotal() > 0)
{
var bytesLoaded:Float = _player.getBytesLoaded();
var bytesTotal:Float = _player.getBytesTotal();
_percentLoaded = bytesLoaded / bytesTotal;
}
var position:Float = _player.getStartTime() / _player.getDuration();
var startPosition:Float = (position > 0?(position * _track.width):0) + _track.x;
_trackDownloaded.graphics.clear();
_trackDownloaded.graphics.lineStyle();
_trackDownloaded.x = startPosition;
_trackDownloaded.graphics.beginFill(_seekColor, 0.5);
_trackDownloaded.graphics.drawRoundRect(0, (_seekBar.height / 2) - (5 / 2), ((_track.width + _track.x) - _trackDownloaded.x) * _percentLoaded, 5, 3, 3);
_trackDownloaded.graphics.endFill();
}
/**
* Draws NEW control bar player/seek controls
*/
private function drawControls():Void
{
//Reset sprites for redraw
_controlsBar.graphics.clear();
_volumeTrack.graphics.clear();
_volumeSlider.graphics.clear();
_volumeSlider.visible = false;
_volumeTrack.visible = false;
//Reset sprites for redraw
_seekBar.graphics.clear();
_track.graphics.clear();
_thumb.graphics.clear();
//Draw controls bar
var barMargin = 10;
var barWidth = _stage.stageWidth;
var barHeight = _controlSize;
var barCenter = barWidth / 2;
var buttonSize = Std.int(((80 / 100) * (barHeight - (barMargin*2))));
_controlsBar.x = 0;
_controlsBar.y = (_stage.stageHeight - barHeight);
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(barWidth, barHeight, Utils.degreesToRadians(-90), barWidth, 0);
var colors:Array<UInt> = [_brightColor, _darkColor];
var alphas:Array<Float> = [1.0, 1];
var ratios:Array<UInt> = [0, 255];
_controlsBar.graphics.lineStyle();
_controlsBar.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
_controlsBar.graphics.drawRect(0, 2, barWidth, barHeight-2);
_controlsBar.graphics.endFill();
_controlsBar.graphics.beginFill(_darkColor, 1);
_controlsBar.graphics.drawRect(0, 0, barWidth, 1);
_controlsBar.graphics.endFill();
_controlsBar.graphics.beginFill(_brightColor, 1);
_controlsBar.graphics.drawRect(0, 1, barWidth, 1);
_controlsBar.graphics.endFill();
//Draw seek bar
var _seekBarWidth = barWidth - (buttonSize+barMargin)*3 - (_playControl.x + _playControl.width + barMargin) - barMargin;
var _seekBarHeight = barHeight;
_seekBar.x = _playControl.x + _playControl.width + barMargin;
_seekBar.y = 0;
_seekBar.graphics.lineStyle();
_seekBar.graphics.beginFill(_darkColor, 0);
_seekBar.graphics.drawRect(0, 0, _seekBarWidth, _seekBarHeight);
_seekBar.graphics.endFill();
//Draw playbutton
_playControl.setNormalColor(_controlColor);
_playControl.setHoverColor(_hoverColor);
_playControl.setPosition(barMargin, barMargin);
_playControl.setSize(buttonSize+5, buttonSize+5);
//Draw pausebutton
_pauseControl.setNormalColor(_controlColor);
_pauseControl.setHoverColor(_hoverColor);
_pauseControl.setPosition(_playControl.x, _playControl.y);
_pauseControl.setSize(buttonSize+5, buttonSize+5);
//Draw current play time label
_textFormat.color = _seekColor;
_currentPlayTimeLabel.x = 0;
_currentPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_currentPlayTimeLabel.height / 2);
_currentPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
_currentPlayTimeLabel.setTextFormat(_textFormat);
//Draw total play time label
_totalPlayTimeLabel.x = _seekBarWidth - _totalPlayTimeLabel.width;
_totalPlayTimeLabel.y = _seekBarHeight - (_seekBarHeight / 2) - (_totalPlayTimeLabel.height / 2);
_totalPlayTimeLabel.antiAliasType = AntiAliasType.ADVANCED;
_totalPlayTimeLabel.setTextFormat(_textFormat);
//Draw download progress
drawDownloadProgress();
//Draw track place holder for drag
_track.x = _currentPlayTimeLabel.x + _currentPlayTimeLabel.width + barMargin;
_track.graphics.lineStyle();
_track.graphics.beginFill(_seekColor, 0);
_track.graphics.drawRect(0, (_seekBarHeight / 2) - ((buttonSize+barMargin) / 2), _totalPlayTimeLabel.x - _totalPlayTimeLabel.width - barMargin - barMargin, buttonSize + barMargin);
_track.graphics.endFill();
_track.graphics.lineStyle();
_track.graphics.beginFill(_seekColor, 0.3);
_track.graphics.drawRoundRect(0, (_seekBarHeight / 2) - (5 / 2), _totalPlayTimeLabel.x - _totalPlayTimeLabel.width - barMargin - barMargin, 5, 3, 3);
_track.graphics.endFill();
//Draw thumb
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(11, 11, Utils.degreesToRadians(-90), 11, 0);
var colors:Array<UInt> = [_controlColor, _controlColor];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
_thumb.x = _currentPlayTimeLabel.width + _currentPlayTimeLabel.x + barMargin;
_thumb.graphics.lineStyle();
_thumb.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//_thumb.graphics.beginFill(_controlColor);
_thumb.graphics.drawRoundRect(0, (_seekBarHeight/2)-(11/2), 11, 11, 10, 10);
_thumb.graphics.endFill();
//Draw volume icon
_volumeIcon.setNormalColor(_controlColor);
_volumeIcon.setHoverColor(_hoverColor);
_volumeIcon.setPosition(_seekBar.x + _seekBar.width + barMargin, _playControl.y+1);
_volumeIcon.setSize(buttonSize, buttonSize);
//Draw aspec ratio button
_aspectRatioControl.setNormalColor(_controlColor);
_aspectRatioControl.setHoverColor(_hoverColor);
_aspectRatioControl.setPosition(_volumeIcon.x + _volumeIcon.width + barMargin, _playControl.y+1);
_aspectRatioControl.setSize(buttonSize, buttonSize);
//Draw fullscreen button
_fullscreenControl.setNormalColor(_controlColor);
_fullscreenControl.setHoverColor(_hoverColor);
_fullscreenControl.setPosition(_aspectRatioControl.x + _aspectRatioControl.width + barMargin, _playControl.y+1);
_fullscreenControl.setSize(buttonSize, buttonSize);
//Draw volume track
_volumeTrack.x = _controlsBar.width-(buttonSize+barMargin)*3;
_volumeTrack.y = -_controlsBar.height-2;
_volumeTrack.graphics.lineStyle(1, _controlColor);
_volumeTrack.graphics.beginFill(0x000000, 0);
_volumeTrack.graphics.drawRect(0, 0, buttonSize, _controlsBar.height);
_volumeTrack.graphics.endFill();
//Draw volume slider
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(_volumeTrack.width, _volumeTrack.height, Utils.degreesToRadians(-90), _volumeTrack.width, 0);
var colors:Array<UInt> = [_hoverColor, _hoverColor];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
_volumeSlider.x = _volumeTrack.x;
_volumeSlider.y = _volumeTrack.y;
_volumeSlider.graphics.lineStyle();
_volumeSlider.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//_volumeSlider.graphics.beginFill(_hoverColor, 1);
_volumeSlider.graphics.drawRect(0, 0, _volumeTrack.width, _volumeTrack.height);
_volumeSlider.graphics.endFill();
}
private function drawAspectRatioLabel():Void
{
_aspectRatioLabelContainer.graphics.clear();
_aspectRatioLabelContainer.visible = false;
//Update aspect ratio label
var textFormat:TextFormat = new TextFormat();
textFormat.font = "arial";
textFormat.bold = true;
textFormat.size = 40;
textFormat.color = _controlColor;
_aspectRatioLabel.setTextFormat(textFormat);
_aspectRatioLabel.x = (_stage.stageWidth / 2) - (_aspectRatioLabel.width / 2);
_aspectRatioLabel.y = (_stage.stageHeight / 2) - (_aspectRatioLabel.height / 2);
//Draw aspect ratio label container
_aspectRatioLabelContainer.x = _aspectRatioLabel.x - 10;
_aspectRatioLabelContainer.y = _aspectRatioLabel.y - 10;
_aspectRatioLabelContainer.graphics.lineStyle(0, _darkColor);
_aspectRatioLabelContainer.graphics.beginFill(_darkColor, 1);
_aspectRatioLabelContainer.graphics.drawRoundRect(0, 0, _aspectRatioLabel.width + 20, _aspectRatioLabel.height + 20, 15, 15);
_aspectRatioLabelContainer.graphics.endFill();
_aspectRatioLabel.x = 10;
_aspectRatioLabel.y = 10;
}
//}
//{Private Methods
/**
* Hide the play controls bar
*/
private function hideControls():Void
{
if(_controlsBar.visible)
{
drawControls();
Animation.slideOut(_controlsBar, "bottom", 800);
}
}
/**
* Shows play controls bar
*/
private function showControls():Void
{
if(!_controlsBar.visible)
{
drawControls();
_controlsBar.visible = true;
}
}
//}
//{Setters
/**
* Sets the player colors and redraw them
* @param colors Array of colors in the following order: darkColor, brightColor, controlColor, hoverColor
*/
public function setControlColors(colors:Array<String>):Void
{
_darkColor = colors[0].length > 0? Std.parseInt("0x" + colors[0]) : 0x000000;
_brightColor = colors[1].length > 0? Std.parseInt("0x" + colors[1]) : 0x4c4c4c;
_controlColor = colors[2].length > 0? Std.parseInt("0x" + colors[2]) : 0xFFFFFF;
_hoverColor = colors[3].length > 0? Std.parseInt("0x" + colors[3]) : 0x67A8C1;
_seekColor = colors[4].length > 0? Std.parseInt("0x" + colors[4]) : 0x7c7c7c;
var loaderColors:Array <String> = ["", ""];
loaderColors[0] = colors[0];
loaderColors[1] = colors[2];
loaderColors[2] = colors[4];
_loader.setColors(loaderColors);
redrawControls();
}
/**
* Sets the player controls size (height)
* @param size int: for e.g. 50
*/
public function setControlSize(size:Int):Void
{
if (size == 0)
return;
_controlSize = size;
redrawControls();
}
/**
* To set the duration label when autostart parameter is false
* @param duration in seconds or formatted string in format hh:mm:ss
*/
public function setDurationLabel(duration:String):Void
{
//Person passed time already formatted
if (duration.indexOf(":") != -1)
{
_totalPlayTimeLabel.text = duration;
}
//Time passed in seconds
else
{
_totalPlayTimeLabel.text = Std.string(Utils.formatTime(Std.parseFloat(duration)));
}
_totalPlayTimeLabel.setTextFormat(_textFormat);
}
//}
}

View File

@@ -0,0 +1,127 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.newcontrols;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import jaris.utils.Utils;
import flash.display.GradientType;
class PauseIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle(0, color, 0.0);
graphics.beginFill(color, 0);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
var colors:Array<UInt> = [color, color];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
graphics.lineStyle();
graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//graphics.beginFill(color);
graphics.drawRoundRect(0, 0, (33 / 100) * _width, _height, 6, 6);
graphics.drawRoundRect(_width - ((33 / 100) * _width), 0, (33 / 100) * _width, _height, 6, 6);
graphics.endFill();
graphics.lineStyle();
graphics.beginFill(color, 0);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,122 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.newcontrols;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import jaris.utils.Utils;
import flash.display.GradientType;
class PlayIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle(0, color, 0.0);
graphics.beginFill(color, 0);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
var colors:Array<UInt> = [color, color];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
graphics.lineStyle();
graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//graphics.beginFill(color);
graphics.lineTo(0, _height);
graphics.lineTo(_width, _height / 2);
graphics.lineTo(0, 0);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,125 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.newcontrols;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import jaris.utils.Utils;
import flash.display.GradientType;
class VolumeIcon extends Sprite
{
private var _width:Float;
private var _height:Float;
private var _normalColor:UInt;
private var _hoverColor:UInt;
public function new(x:Float, y:Float, width:Float, height:Float, normalColor:UInt, hoverColor:UInt)
{
super();
this.x = x;
this.y = y;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
_width = width;
_height = height;
_normalColor = normalColor;
_hoverColor = hoverColor;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
draw(_normalColor);
}
private function onMouseOver(event:MouseEvent):Void
{
draw(_hoverColor);
}
private function onMouseOut(event:MouseEvent):Void
{
draw(_normalColor);
}
//{Private Methods
private function draw(color:UInt):Void
{
graphics.clear();
graphics.lineStyle(0, color, 0.0);
graphics.beginFill(color, 0);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
var matrix:Matrix = new Matrix( );
matrix.createGradientBox(_width, _height, Utils.degreesToRadians(-90), _width, 0);
var colors:Array<UInt> = [color, color];
var alphas:Array<Float> = [0.75, 1];
var ratios:Array<UInt> = [0, 255];
graphics.lineStyle();
graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
//graphics.beginFill(color, 1);
graphics.drawRect(0, ((50 / 100) * _height) / 2+1, _width / 2-1, ((50 / 100) * _height));
graphics.moveTo(_width / 2 -1, ((50 / 100) * _height)/2+1);
graphics.lineTo(_width, 0);
graphics.lineTo(_width, _height+2);
graphics.lineTo(_width / 2 -1, ((50 / 100) * _height) + (((50 / 100) * _height) / 2)+1);
graphics.endFill();
}
//}
//{Setters
public function setNormalColor(color:UInt):Void
{
_normalColor = color;
draw(_normalColor);
}
public function setHoverColor(color:UInt):Void
{
_hoverColor = color;
draw(_hoverColor);
}
public function setPosition(x:Float, y:Float):Void
{
this.x = x;
this.y = y;
draw(_normalColor);
}
public function setSize(width:Float, height:Float):Void
{
_width = width;
_height = height;
draw(_normalColor);
}
//}
}

View File

@@ -0,0 +1,161 @@
/**
* @author Jefferson González
* @copyright 2010 Jefferson González
*
* @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.utils;
/**
* Some utility functions
*/
class Utils
{
/**
* Converts degrees to radians for easy rotation where applicable
* @param value A radian value to convert
* @return conversion of degree to radian
*/
public static function degreesToRadians(value:Float):Float
{
return (Math.PI / 180) * value;
}
/**
* Converts a float value representing seconds to a readale string
* @param time A given time in seconds
* @return A string in the format 00:00:00
*/
public static function formatTime(time:Float):String
{
var seconds:String = "";
var minutes:String = "";
var hours:String = "";
var timeString:String = "";
if (((time / 60) / 60) >= 1)
{
if (Math.floor((time / 60)) / 60 < 10)
{
hours = "0" + Math.floor((time / 60) / 60) + ":";
}
else
{
hours = Math.floor((time / 60) / 60) + ":";
}
if (Math.floor((time / 60) % 60) < 10)
{
minutes = "0" + Math.floor((time / 60) % 60) + ":";
}
else
{
minutes = Math.floor((time / 60) % 60) + ":";
}
if (Math.floor(time % 60) < 10)
{
seconds = "0" + Math.floor(time % 60);
}
else
{
seconds = Std.string(Math.floor(time % 60));
}
}
else if((time / 60) >= 1)
{
hours = "00:";
if (Math.floor(time / 60) < 10)
{
minutes = "0" + Math.floor(time / 60) + ":";
}
else
{
minutes = Math.floor(time / 60) + ":";
}
if (Math.floor(time % 60) < 10)
{
seconds = "0" + Math.floor(time % 60);
}
else
{
seconds = Std.string(Math.floor(time % 60));
}
}
else
{
hours = "00:";
minutes = "00:";
if (Math.floor(time) < 10)
{
seconds = "0" + Math.floor(time);
}
else
{
seconds = Std.string(Math.floor(time));
}
}
timeString += hours + minutes + seconds;
return timeString;
}
/**
* Converts a given rtmp source to a valid format for NetStream
* @param source
* @return
*/
public static function rtmpSourceParser(source:String):String
{
if (source.indexOf(".flv") != -1)
{
return source.split(".flv").join("");
}
else if (source.indexOf(".mp3") != -1)
{
return "mp3:" + source.split(".mp3").join("");
}
else if (source.indexOf(".mp4") != -1)
{
return "mp4:" + source;
}
else if (source.indexOf(".f4v") != -1)
{
return "mp4:" + source;
}
return source;
}
/**
* Changes a youtube url to the format youtube.com/v/video_id
* @param source
* @return
*/
public static function youtubeSourceParse(source:String):String
{
return source.split("watch?v=").join("v/");
}
}