first commit
This commit is contained in:
638
libraries/filemanager-9.12.1/js/jPlayer/actionscript/Jplayer.as
Normal file
638
libraries/filemanager-9.12.1/js/jPlayer/actionscript/Jplayer.as
Normal file
@@ -0,0 +1,638 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Mark J Panaghiston
|
||||
* Version: 2.4.0
|
||||
* Date: 5th June 2013
|
||||
*
|
||||
* FlashVars expected: (AS3 property of: loaderInfo.parameters)
|
||||
* id: (URL Encoded: String) Id of jPlayer instance
|
||||
* vol: (Number) Sets the initial volume
|
||||
* muted: (Boolean in a String) Sets the initial muted state
|
||||
* jQuery: (URL Encoded: String) Sets the jQuery var name. Used with: someVar = jQuery.noConflict(true); The someVar name must contain jQuery in it.
|
||||
*
|
||||
* Compiled using: Adobe Flex Compiler (mxmlc) Version 4.5.1 build 21328
|
||||
*/
|
||||
|
||||
package {
|
||||
import flash.system.Security;
|
||||
import flash.external.ExternalInterface;
|
||||
|
||||
import flash.utils.Timer;
|
||||
import flash.events.TimerEvent;
|
||||
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormat;
|
||||
|
||||
import flash.events.KeyboardEvent;
|
||||
|
||||
import flash.display.Sprite;
|
||||
import happyworm.jPlayer.*;
|
||||
|
||||
import flash.display.StageAlign;
|
||||
import flash.display.StageScaleMode;
|
||||
import flash.events.Event;
|
||||
import flash.net.LocalConnection;
|
||||
import flash.events.StatusEvent;
|
||||
|
||||
import flash.events.MouseEvent;
|
||||
|
||||
import flash.ui.ContextMenu;
|
||||
import flash.ui.ContextMenuItem;
|
||||
import flash.events.ContextMenuEvent;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.navigateToURL;
|
||||
import flash.media.Video;
|
||||
|
||||
public class Jplayer extends Sprite {
|
||||
private var jQuery:String;
|
||||
private var sentNumberFractionDigits:uint = 2;
|
||||
|
||||
public var commonStatus:JplayerStatus = new JplayerStatus(); // Used for inital ready event so volume is correct.
|
||||
|
||||
private var myInitTimer:Timer = new Timer(100, 0);
|
||||
|
||||
private var myMp3Player:JplayerMp3;
|
||||
private var myMp4Player:JplayerMp4;
|
||||
|
||||
private var myRtmpPlayer:JplayerRtmp;
|
||||
|
||||
private var isRtmp:Boolean = false;
|
||||
private var isMp4:Boolean = false;
|
||||
|
||||
private var isMp3:Boolean = false;
|
||||
private var isVideo:Boolean = false;
|
||||
|
||||
private var securityIssue:Boolean = false; // On direct access and when SWF parameters contain illegal characters
|
||||
|
||||
private var contextMenuFix:Sprite = new Sprite(); // A sprite that will be on top and fix the content menu over video bug. (A Flash plugin bug.)
|
||||
|
||||
private var txLog:TextField;
|
||||
private var debug:Boolean = false; // Set debug to false for release compile!
|
||||
private var localAIRDebug:Boolean = false; // This is autodetermined by AIR app - leave false!
|
||||
|
||||
private var traceOut:TraceOut;
|
||||
|
||||
public function Jplayer() {
|
||||
|
||||
flash.system.Security.allowDomain("*");
|
||||
traceOut = new TraceOut();
|
||||
|
||||
// Fix to the security exploit reported by Jason Calvert http://appsec.ws/
|
||||
checkFlashVars(loaderInfo.parameters);
|
||||
|
||||
stage.scaleMode = StageScaleMode.NO_SCALE;
|
||||
stage.align = StageAlign.TOP_LEFT;
|
||||
|
||||
if(!securityIssue) {
|
||||
// The jQuery param is the primary cause of security concerns.
|
||||
jQuery = loaderInfo.parameters.jQuery + "('#" + loaderInfo.parameters.id + "').jPlayer";
|
||||
commonStatus.volume = Number(loaderInfo.parameters.vol);
|
||||
commonStatus.muted = loaderInfo.parameters.muted == "true";
|
||||
|
||||
stage.addEventListener(Event.RESIZE, resizeHandler);
|
||||
stage.addEventListener(MouseEvent.CLICK, clickHandler);
|
||||
|
||||
var initialVolume:Number = commonStatus.volume;
|
||||
if(commonStatus.muted) {
|
||||
initialVolume = 0;
|
||||
}
|
||||
|
||||
myMp3Player = new JplayerMp3(initialVolume);
|
||||
addChild(myMp3Player);
|
||||
|
||||
myMp4Player = new JplayerMp4(initialVolume);
|
||||
addChild(myMp4Player);
|
||||
|
||||
myRtmpPlayer = new JplayerRtmp(initialVolume);
|
||||
addChild(myRtmpPlayer);
|
||||
|
||||
switchType("mp3"); // set default state to mp3
|
||||
}
|
||||
|
||||
// The ContextMenu only partially works. The menu select events never occur.
|
||||
// Investigated and it is something to do with the way jPlayer inserts the Flash on the page.
|
||||
// A simple test inserting the Jplayer.swf on a page using: 1) SWFObject 2.2 works. 2) AC_FL_RunContent() works.
|
||||
// jPlayer Flash insertion is based on SWFObject 2.2 and the resaon behind this failure is not clear. The Flash insertion HTML on the page looks similar.
|
||||
var myContextMenu:ContextMenu = new ContextMenu();
|
||||
myContextMenu.hideBuiltInItems();
|
||||
var menuItem_jPlayer:ContextMenuItem = new ContextMenuItem("jPlayer " + JplayerStatus.VERSION);
|
||||
var menuItem_happyworm:ContextMenuItem = new ContextMenuItem("© 2009-2013 Happyworm Ltd", true);
|
||||
menuItem_jPlayer.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuSelectHandler_jPlayer);
|
||||
menuItem_happyworm.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuSelectHandler_happyworm);
|
||||
myContextMenu.customItems.push(menuItem_jPlayer, menuItem_happyworm);
|
||||
contextMenu = myContextMenu;
|
||||
|
||||
// Log console for dev compile option: debug
|
||||
if(debug || securityIssue) {
|
||||
txLog = new TextField();
|
||||
txLog.x = 5;
|
||||
txLog.y = 5;
|
||||
txLog.width = stage.stageWidth - 10;
|
||||
txLog.height = stage.stageHeight - 10;
|
||||
txLog.backgroundColor = 0xEEEEFF;
|
||||
txLog.border = true;
|
||||
txLog.background = true;
|
||||
txLog.multiline = true;
|
||||
txLog.text = "jPlayer " + JplayerStatus.VERSION;
|
||||
|
||||
if(securityIssue) {
|
||||
txLog.visible = true;
|
||||
} else if(debug) {
|
||||
txLog.visible = false;
|
||||
}
|
||||
|
||||
this.addChild(txLog);
|
||||
|
||||
if(debug && !securityIssue) {
|
||||
this.stage.addEventListener(KeyboardEvent.KEY_UP, keyboardHandler);
|
||||
|
||||
myMp3Player.addEventListener(JplayerEvent.DEBUG_MSG, debugMsgHandler);
|
||||
myMp4Player.addEventListener(JplayerEvent.DEBUG_MSG, debugMsgHandler);
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.DEBUG_MSG, debugMsgHandler);
|
||||
}
|
||||
}
|
||||
|
||||
// Known Flash problem with contextMenu over video player.
|
||||
// Add a transparent rectangle into the sprite.
|
||||
contextMenuFix.graphics.beginFill(0x000000, 0); // Transparent black
|
||||
contextMenuFix.graphics.drawRect(0, 0, 10, 10); // Arbitary rectangle
|
||||
contextMenuFix.graphics.endFill();
|
||||
addChild(contextMenuFix); // Put the sprite on the top layer.
|
||||
|
||||
if(!securityIssue) {
|
||||
// Delay init() because Firefox 3.5.7+ developed a bug with local testing in Firebug.
|
||||
myInitTimer.addEventListener(TimerEvent.TIMER, init);
|
||||
myInitTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
private function switchType(playType:String):void {
|
||||
switch(playType) {
|
||||
case "rtmpa":
|
||||
isRtmp=true;
|
||||
isMp3=false;
|
||||
isMp4=false;
|
||||
isVideo=false;
|
||||
break;
|
||||
case "rtmpv":
|
||||
isRtmp=true;
|
||||
isMp3=false;
|
||||
isMp4=false;
|
||||
isVideo=true;
|
||||
break;
|
||||
case "mp3":
|
||||
isRtmp=false;
|
||||
isMp3=true;
|
||||
isMp4=false;
|
||||
isVideo=false;
|
||||
break;
|
||||
case "mp4":
|
||||
isRtmp=false;
|
||||
isMp3=false;
|
||||
isMp4=true;
|
||||
isVideo=false;
|
||||
break;
|
||||
case "m4v":
|
||||
isRtmp=false;
|
||||
isMp3=false;
|
||||
isMp4=true;
|
||||
isVideo=true;
|
||||
break;
|
||||
}
|
||||
|
||||
listenToMp3(isMp3);
|
||||
listenToMp4(isMp4);
|
||||
listenToRtmp(isRtmp);
|
||||
}
|
||||
|
||||
private function init(e:TimerEvent):void {
|
||||
myInitTimer.stop();
|
||||
if(ExternalInterface.available && !securityIssue) {
|
||||
ExternalInterface.addCallback("fl_setAudio_mp3", fl_setAudio_mp3);
|
||||
ExternalInterface.addCallback("fl_setAudio_m4a", fl_setAudio_m4a);
|
||||
ExternalInterface.addCallback("fl_setVideo_m4v", fl_setVideo_m4v);
|
||||
ExternalInterface.addCallback("fl_setAudio_rtmp", fl_setAudio_rtmp);
|
||||
ExternalInterface.addCallback("fl_setVideo_rtmp", fl_setVideo_rtmp);
|
||||
ExternalInterface.addCallback("fl_clearMedia", fl_clearMedia);
|
||||
ExternalInterface.addCallback("fl_load", fl_load);
|
||||
ExternalInterface.addCallback("fl_play", fl_play);
|
||||
ExternalInterface.addCallback("fl_pause", fl_pause);
|
||||
ExternalInterface.addCallback("fl_play_head", fl_play_head);
|
||||
ExternalInterface.addCallback("fl_volume", fl_volume);
|
||||
ExternalInterface.addCallback("fl_mute", fl_mute);
|
||||
|
||||
ExternalInterface.call(jQuery, "jPlayerFlashEvent", JplayerEvent.JPLAYER_READY, extractStatusData(commonStatus)); // See JplayerStatus() class for version number.
|
||||
}
|
||||
}
|
||||
private function checkFlashVars(p:Object):void {
|
||||
// Check for direct access. Inspired by mediaelement.js - Also added name to HTML object for non-IE browsers.
|
||||
if(ExternalInterface.objectID != null && ExternalInterface.objectID.toString() != "") {
|
||||
for each (var s:String in p) {
|
||||
if(illegalChar(s)) {
|
||||
securityIssue = true; // Found a security concern.
|
||||
}
|
||||
}
|
||||
if(!securityIssue) {
|
||||
if(jQueryIllegal(p.jQuery)) {
|
||||
securityIssue = true; // Found a security concern.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
securityIssue = true; // Direct access disables the callbacks, which were a security concern.
|
||||
}
|
||||
}
|
||||
private function illegalChar(s:String):Boolean {
|
||||
// A whitelist of accepted chars.
|
||||
var validParam:RegExp = /^[-A-Za-z0-9_.]+$/;
|
||||
return !validParam.test(s);
|
||||
}
|
||||
private function jQueryIllegal(s:String):Boolean {
|
||||
// Check param contains the term jQuery.
|
||||
var validParam:RegExp = /(jQuery)/;
|
||||
return !validParam.test(s);
|
||||
}
|
||||
// switchType() here
|
||||
private function listenToMp3(active:Boolean):void {
|
||||
if(active) {
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_ERROR, jPlayerFlashEvent);
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_PROGRESS, jPlayerFlashEvent);
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_TIMEUPDATE, jPlayerFlashEvent);
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_ENDED, jPlayerFlashEvent);
|
||||
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_PLAY, jPlayerFlashEvent);
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_PAUSE, jPlayerFlashEvent);
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_LOADSTART, jPlayerFlashEvent);
|
||||
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_SEEKING, jPlayerFlashEvent);
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_SEEKED, jPlayerFlashEvent);
|
||||
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_WAITING, jPlayerFlashEvent); // only MP3 atm
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_PLAYING, jPlayerFlashEvent); // only MP3 atm
|
||||
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_CANPLAY, jPlayerFlashEvent); // only MP3 atm
|
||||
myMp3Player.addEventListener(JplayerEvent.JPLAYER_CANPLAYTHROUGH, jPlayerFlashEvent); // only MP3 atm
|
||||
} else {
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_ERROR, jPlayerFlashEvent);
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_PROGRESS, jPlayerFlashEvent);
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_TIMEUPDATE, jPlayerFlashEvent);
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_ENDED, jPlayerFlashEvent);
|
||||
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_PLAY, jPlayerFlashEvent);
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_PAUSE, jPlayerFlashEvent);
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_LOADSTART, jPlayerFlashEvent);
|
||||
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_SEEKING, jPlayerFlashEvent);
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_SEEKED, jPlayerFlashEvent);
|
||||
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_WAITING, jPlayerFlashEvent); // only MP3 atm
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_PLAYING, jPlayerFlashEvent); // only MP3 atm
|
||||
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_CANPLAY, jPlayerFlashEvent); // only MP3 atm
|
||||
myMp3Player.removeEventListener(JplayerEvent.JPLAYER_CANPLAYTHROUGH, jPlayerFlashEvent); // only MP3 atm
|
||||
}
|
||||
}
|
||||
private function listenToMp4(active:Boolean):void {
|
||||
if(active) {
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_ERROR, jPlayerFlashEvent);
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_PROGRESS, jPlayerFlashEvent);
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_TIMEUPDATE, jPlayerFlashEvent);
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_ENDED, jPlayerFlashEvent);
|
||||
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_PLAY, jPlayerFlashEvent);
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_PAUSE, jPlayerFlashEvent);
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_LOADSTART, jPlayerFlashEvent);
|
||||
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_SEEKING, jPlayerFlashEvent);
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_SEEKED, jPlayerFlashEvent);
|
||||
|
||||
myMp4Player.addEventListener(JplayerEvent.JPLAYER_LOADEDMETADATA, jPlayerMetaDataHandler); // Note the unique handler
|
||||
} else {
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_ERROR, jPlayerFlashEvent);
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_PROGRESS, jPlayerFlashEvent);
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_TIMEUPDATE, jPlayerFlashEvent);
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_ENDED, jPlayerFlashEvent);
|
||||
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_PLAY, jPlayerFlashEvent);
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_PAUSE, jPlayerFlashEvent);
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_LOADSTART, jPlayerFlashEvent);
|
||||
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_SEEKING, jPlayerFlashEvent);
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_SEEKED, jPlayerFlashEvent);
|
||||
|
||||
myMp4Player.removeEventListener(JplayerEvent.JPLAYER_LOADEDMETADATA, jPlayerMetaDataHandler); // Note the unique handler
|
||||
}
|
||||
}
|
||||
|
||||
private function listenToRtmp(active:Boolean):void {
|
||||
if(active) {
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_ERROR, jPlayerFlashEvent);
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_PROGRESS, jPlayerFlashEvent);
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_TIMEUPDATE, jPlayerFlashEvent);
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_ENDED, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_PLAY, jPlayerFlashEvent);
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_PAUSE, jPlayerFlashEvent);
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_LOADSTART, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_CANPLAY, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_SEEKING, jPlayerFlashEvent);
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_SEEKED, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_LOADEDMETADATA, jPlayerMetaDataHandler); // Note the unique handler
|
||||
} else {
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_ERROR, jPlayerFlashEvent);
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_PROGRESS, jPlayerFlashEvent);
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_TIMEUPDATE, jPlayerFlashEvent);
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_ENDED, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_PLAY, jPlayerFlashEvent);
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_PAUSE, jPlayerFlashEvent);
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_LOADSTART, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.addEventListener(JplayerEvent.JPLAYER_CANPLAY, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_SEEKING, jPlayerFlashEvent);
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_SEEKED, jPlayerFlashEvent);
|
||||
|
||||
myRtmpPlayer.removeEventListener(JplayerEvent.JPLAYER_LOADEDMETADATA, jPlayerMetaDataHandler); // Note the unique handler
|
||||
}
|
||||
}
|
||||
|
||||
private function fl_setAudio_mp3(src:String):Boolean {
|
||||
if (src != null) {
|
||||
log("fl_setAudio_mp3: "+src);
|
||||
switchType("mp3");
|
||||
myMp4Player.clearFile();
|
||||
myRtmpPlayer.clearFile();
|
||||
myMp3Player.setFile(src);
|
||||
return true;
|
||||
} else {
|
||||
log("fl_setAudio_mp3: null");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private function fl_setAudio_rtmp(src:String):Boolean {
|
||||
tracer("SET RTMP: "+src);
|
||||
if (src != null) {
|
||||
log("fl_setAudio_rtmp: "+src);
|
||||
switchType("rtmpa");
|
||||
myMp4Player.clearFile();
|
||||
myMp3Player.clearFile();
|
||||
myRtmpPlayer.setFile(src,false);
|
||||
return true;
|
||||
} else {
|
||||
log("fl_setAudio_rtmp: null");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function fl_setVideo_rtmp(src:String):Boolean {
|
||||
tracer("SET RTMP: "+src);
|
||||
if (src != null) {
|
||||
log("fl_setVideo_rtmp: "+src);
|
||||
switchType("rtmpv");
|
||||
myMp4Player.clearFile();
|
||||
myMp3Player.clearFile();
|
||||
myRtmpPlayer.setFile(src,true);
|
||||
return true;
|
||||
} else {
|
||||
log("fl_setVideo_rtmp: null");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private function fl_setAudio_m4a(src:String):Boolean {
|
||||
if (src != null) {
|
||||
log("fl_setAudio_m4a: "+src);
|
||||
switchType("mp4")
|
||||
myMp3Player.clearFile();
|
||||
myRtmpPlayer.clearFile();
|
||||
myMp4Player.setFile(src);
|
||||
return true;
|
||||
} else {
|
||||
log("fl_setAudio_m4a: null");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private function fl_setVideo_m4v(src:String):Boolean {
|
||||
if (src != null) {
|
||||
log("fl_setVideo_m4v: "+src);
|
||||
switchType("m4v");
|
||||
myMp3Player.clearFile();
|
||||
myRtmpPlayer.clearFile();
|
||||
myMp4Player.setFile(src);
|
||||
return true;
|
||||
} else {
|
||||
log("fl_setVideo_m4v: null");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private function fl_clearMedia():void {
|
||||
log("clearMedia.");
|
||||
myMp3Player.clearFile();
|
||||
myMp4Player.clearFile();
|
||||
myRtmpPlayer.clearFile();
|
||||
}
|
||||
|
||||
private function getType():Object {
|
||||
var returnType:Object;
|
||||
if(isMp3) {
|
||||
returnType=myMp3Player;
|
||||
}
|
||||
if(isRtmp) {
|
||||
returnType=myRtmpPlayer;
|
||||
}
|
||||
if(isMp4) {
|
||||
returnType=myMp4Player;
|
||||
}
|
||||
return returnType;
|
||||
}
|
||||
|
||||
private function fl_load():Boolean {
|
||||
log("load.");
|
||||
var returnType:Object = getType();
|
||||
return returnType.load();
|
||||
}
|
||||
private function fl_play(time:Number = NaN):Boolean {
|
||||
log("play: time = " + time);
|
||||
var returnType:Object = getType();
|
||||
return returnType.play(time * 1000); // Flash uses milliseconds
|
||||
}
|
||||
private function fl_pause(time:Number = NaN):Boolean {
|
||||
log("pause: time = " + time);
|
||||
var returnType:Object = getType();
|
||||
return returnType.pause(time * 1000); // Flash uses milliseconds
|
||||
}
|
||||
private function fl_play_head(percent:Number):Boolean {
|
||||
log("play_head: "+percent+"%");
|
||||
var returnType:Object = getType();
|
||||
return returnType.playHead(percent);
|
||||
}
|
||||
private function fl_volume(v:Number):void {
|
||||
log("volume: "+v);
|
||||
commonStatus.volume = v;
|
||||
if(!commonStatus.muted) {
|
||||
myMp3Player.setVolume(v);
|
||||
myMp4Player.setVolume(v);
|
||||
myRtmpPlayer.setVolume(v);
|
||||
}
|
||||
}
|
||||
private function fl_mute(mute:Boolean):void {
|
||||
log("mute: "+mute);
|
||||
commonStatus.muted = mute;
|
||||
if(mute) {
|
||||
myMp3Player.setVolume(0);
|
||||
myMp4Player.setVolume(0);
|
||||
myRtmpPlayer.setVolume(0);
|
||||
} else {
|
||||
myMp3Player.setVolume(commonStatus.volume);
|
||||
myMp4Player.setVolume(commonStatus.volume);
|
||||
myRtmpPlayer.setVolume(commonStatus.volume);
|
||||
}
|
||||
}
|
||||
private function jPlayerFlashEvent(e:JplayerEvent):void {
|
||||
log("jPlayer Flash Event: " + e.type + ": " + e.target);
|
||||
//tracer("jPlayer Flash Event: " + e.type + ": " + e.target);
|
||||
if(ExternalInterface.available && !securityIssue) {
|
||||
ExternalInterface.call(jQuery, "jPlayerFlashEvent", e.type, extractStatusData(e.data));
|
||||
}
|
||||
}
|
||||
|
||||
private function tracer(msg:String):void {
|
||||
traceOut.tracer(msg);
|
||||
}
|
||||
|
||||
private function extractStatusData(data:JplayerStatus):Object {
|
||||
var myStatus:Object = {
|
||||
version: JplayerStatus.VERSION,
|
||||
src: data.src,
|
||||
paused: !data.isPlaying, // Changing this name requires inverting all assignments and conditional statements.
|
||||
srcSet: data.srcSet,
|
||||
seekPercent: data.seekPercent,
|
||||
currentPercentRelative: data.currentPercentRelative,
|
||||
currentPercentAbsolute: data.currentPercentAbsolute,
|
||||
currentTime: data.currentTime / 1000, // JavaScript uses seconds
|
||||
duration: data.duration / 1000, // JavaScript uses seconds
|
||||
videoWidth: data.videoWidth,
|
||||
videoHeight: data.videoHeight,
|
||||
volume: commonStatus.volume,
|
||||
muted: commonStatus.muted
|
||||
};
|
||||
log("extractStatusData: sp="+myStatus.seekPercent+" cpr="+myStatus.currentPercentRelative+" cpa="+myStatus.currentPercentAbsolute+" ct="+myStatus.currentTime+" d="+myStatus.duration);
|
||||
return myStatus;
|
||||
}
|
||||
private function jPlayerMetaDataHandler(e:JplayerEvent):void {
|
||||
log("jPlayerMetaDataHandler:" + e.target);
|
||||
if(ExternalInterface.available && !securityIssue) {
|
||||
resizeHandler(new Event(Event.RESIZE));
|
||||
ExternalInterface.call(jQuery, "jPlayerFlashEvent", e.type, extractStatusData(e.data));
|
||||
}
|
||||
}
|
||||
private function resizeHandler(e:Event):void {
|
||||
log("resizeHandler: stageWidth = " + stage.stageWidth + " | stageHeight = " + stage.stageHeight);
|
||||
|
||||
var mediaX:Number = 0;
|
||||
var mediaY:Number = 0;
|
||||
var mediaWidth:Number = 0;
|
||||
var mediaHeight:Number = 0;
|
||||
|
||||
var aspectRatioStage:Number = 0;
|
||||
var aspectRatioVideo:Number = 0;
|
||||
|
||||
var videoItem:*;
|
||||
|
||||
if(isRtmp) {
|
||||
videoItem = myRtmpPlayer;
|
||||
}
|
||||
if(isMp4) {
|
||||
videoItem = myMp4Player;
|
||||
}
|
||||
|
||||
if(videoItem) {
|
||||
if(stage.stageWidth > 0 && stage.stageHeight > 0 && videoItem.myVideo.width > 0 && videoItem.myVideo.height > 0) {
|
||||
aspectRatioStage = stage.stageWidth / stage.stageHeight;
|
||||
aspectRatioVideo = videoItem.myVideo.width / videoItem.myVideo.height;
|
||||
if(aspectRatioStage < aspectRatioVideo) {
|
||||
mediaWidth = stage.stageWidth;
|
||||
mediaHeight = stage.stageWidth / aspectRatioVideo;
|
||||
mediaX = 0;
|
||||
mediaY = (stage.stageHeight - mediaHeight) / 2;
|
||||
} else {
|
||||
mediaWidth = stage.stageHeight * aspectRatioVideo;
|
||||
mediaHeight = stage.stageHeight;
|
||||
mediaX = (stage.stageWidth - mediaWidth) / 2;
|
||||
mediaY = 0;
|
||||
}
|
||||
resizeEntity(videoItem, mediaX, mediaY, mediaWidth, mediaHeight);
|
||||
}
|
||||
}
|
||||
if((debug || securityIssue) && stage.stageWidth > 20 && stage.stageHeight > 20) {
|
||||
txLog.width = stage.stageWidth - 10;
|
||||
txLog.height = stage.stageHeight - 10;
|
||||
}
|
||||
// Resize the sprite so it covers the entire stage area
|
||||
contextMenuFix.x = 0;
|
||||
contextMenuFix.y = 0;
|
||||
contextMenuFix.width = stage.stageWidth;
|
||||
contextMenuFix.height = stage.stageHeight;
|
||||
}
|
||||
private function resizeEntity(entity:Sprite, mediaX:Number, mediaY:Number, mediaWidth:Number, mediaHeight:Number):void {
|
||||
entity.x = mediaX;
|
||||
entity.y = mediaY;
|
||||
entity.width = mediaWidth;
|
||||
entity.height = mediaHeight;
|
||||
}
|
||||
private function clickHandler(e:MouseEvent):void {
|
||||
// This needs to work with RTMP format too!
|
||||
if(isMp3) {
|
||||
jPlayerFlashEvent(new JplayerEvent(JplayerEvent.JPLAYER_CLICK, myMp3Player.myStatus, "click"))
|
||||
} else {
|
||||
jPlayerFlashEvent(new JplayerEvent(JplayerEvent.JPLAYER_CLICK, myMp4Player.myStatus, "click"))
|
||||
}
|
||||
}
|
||||
// This event is never called. See comments in class constructor.
|
||||
private function menuSelectHandler_jPlayer(e:ContextMenuEvent):void {
|
||||
navigateToURL(new URLRequest("http://jplayer.org/"), "_blank");
|
||||
}
|
||||
// This event is never called. See comments in class constructor.
|
||||
private function menuSelectHandler_happyworm(e:ContextMenuEvent):void {
|
||||
navigateToURL(new URLRequest("http://happyworm.com/"), "_blank");
|
||||
}
|
||||
private function log(t:String):void {
|
||||
if(debug) {
|
||||
txLog.text = t + "\n" + txLog.text;
|
||||
localAIRDebug = traceOut.localAIRDebug();
|
||||
if(localAIRDebug) {
|
||||
tracer(t);
|
||||
}
|
||||
|
||||
if(ExternalInterface.available && !securityIssue) {
|
||||
ExternalInterface.call("console.log", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
private function debugMsgHandler(e:JplayerEvent):void {
|
||||
log(e.msg);
|
||||
}
|
||||
private function keyboardHandler(e:KeyboardEvent):void {
|
||||
log("keyboardHandler: e.keyCode = " + e.keyCode);
|
||||
switch(e.keyCode) {
|
||||
case 68 : // d
|
||||
txLog.visible = !txLog.visible;
|
||||
log("Toggled log display: " + txLog.visible);
|
||||
break;
|
||||
case 76 : // l
|
||||
if(e.ctrlKey && e.shiftKey) {
|
||||
txLog.text = "Cleared log.";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
libraries/filemanager-9.12.1/js/jPlayer/actionscript/Jplayer.fla
Normal file
BIN
libraries/filemanager-9.12.1/js/jPlayer/actionscript/Jplayer.fla
Normal file
Binary file not shown.
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT license.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Robert M. Hall
|
||||
* Date: 7th August 2012
|
||||
* Custom NetConnection Manager for more robust RTMP support
|
||||
* Based in part on work by Will Law for the old Akamai NCManager.as
|
||||
* and some of Will's new work in the OVP base classes (Open Video Player)
|
||||
* as well as similar approaches by many other NetConnection managers
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
TODO LIST 08/18/2011:
|
||||
1. Wired up errors to dispatch events to Jplayer events to allow them to bubble up to JS
|
||||
2. Rework event dispatch to handoff netconnection instead of a passed in reference
|
||||
3. Allow a customizeable list of protocols and ports to be used instead of entire list
|
||||
4. Allow a specific port/protocol (1 connect type) to be used first, and then optionally fallback on a custom list or the default list
|
||||
5. Remove some traces and check a few other items below where I've made notes
|
||||
*/
|
||||
|
||||
package happyworm.jPlayer {
|
||||
|
||||
import flash.events.*;
|
||||
import flash.net.*;
|
||||
|
||||
import flash.utils.Timer;
|
||||
import flash.utils.getTimer;
|
||||
import flash.utils.clearInterval;
|
||||
import flash.utils.setInterval;
|
||||
|
||||
public class ConnectManager extends Object {
|
||||
|
||||
private var protocols_arr:Array = new Array("rtmp","rtmpt","rtmpe","rtmpte","rtmps");
|
||||
private var ports_arr:Array = new Array("",":1935",":80",":443");
|
||||
private const protCount:Number = 5;
|
||||
private const portCount:Number = 4;
|
||||
|
||||
private var _ncRef:Object;
|
||||
|
||||
private var _aNC:Array;
|
||||
|
||||
private var k_TIMEOUT:Number = 30000;
|
||||
private var k_startConns:Number;
|
||||
private var m_connList:Array = [];
|
||||
private var m_serverName:String;
|
||||
private var m_appName:String;
|
||||
private var m_streamName:String;
|
||||
private var m_connListCounter:Number;
|
||||
private var m_flashComConnectTimeOut:Number;
|
||||
private var m_validNetConnection:NetConnection;
|
||||
|
||||
private var connectSuccess:Boolean=false;
|
||||
|
||||
private var negotiating:Boolean=false;
|
||||
private var idleTimeOut:Boolean=false;
|
||||
|
||||
public function ConnectManager() {
|
||||
trace ("ConnectManager Initialized Version: 1.00 DT");
|
||||
createPortsProtocolsArray();
|
||||
}
|
||||
|
||||
private function createPortsProtocolsArray():void {
|
||||
var outerLoop:Number=0;
|
||||
var innerLoop:Number=0;
|
||||
for (outerLoop=0; outerLoop<protocols_arr.length; outerLoop++) {
|
||||
|
||||
for (innerLoop=0; innerLoop<ports_arr.length; innerLoop++) {
|
||||
m_connList.push( { protocol: protocols_arr[outerLoop], port: ports_arr[innerLoop] } );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function negotiateConnect(ncRef:Object,p_serverName:String,p_appName:String):void
|
||||
{
|
||||
negotiating=true;
|
||||
_ncRef=ncRef;
|
||||
trace("*** SERVER NAME: "+p_serverName);
|
||||
trace("*** APP NAME: "+p_serverName);
|
||||
k_startConns = getTimer();
|
||||
m_serverName = p_serverName;
|
||||
m_appName = p_appName;
|
||||
|
||||
// Set a timeout function, just in case we never connect successfully
|
||||
clearInterval(m_flashComConnectTimeOut);
|
||||
m_flashComConnectTimeOut = setInterval(onFlashComConnectTimeOut,k_TIMEOUT,k_TIMEOUT);
|
||||
|
||||
// Createe a NetConnection for each of the protocols/ports listed in the m_connList list.
|
||||
// Connection attempts occur at intervals of 1.5 seconds.
|
||||
// The first connection to succeed will be used, all the others will be closed.
|
||||
_aNC = new Array();
|
||||
for (var i:uint = 0; i < m_connList.length; i++)
|
||||
{
|
||||
_aNC[i] = new NetConnection();
|
||||
_aNC[i].addEventListener(NetStatusEvent.NET_STATUS,netStatus);
|
||||
_aNC[i].addEventListener(SecurityErrorEvent.SECURITY_ERROR,netSecurityError);
|
||||
_aNC[i].addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncError);
|
||||
_aNC[i].client = new Object;
|
||||
_aNC[i].client.owner = this;
|
||||
_aNC[i].client.connIndex = i;
|
||||
_aNC[i].client.id = i;
|
||||
_aNC[i].client.pending = true;
|
||||
|
||||
/* Revisit this chunk - not needed at the moment as NC is handed off and this
|
||||
// is handled elsewhere
|
||||
// Need to put in some event dispatching as a more elegant solution and leave it here
|
||||
|
||||
_aNC[i].client.onBWDone = function (p_bw, deltaDown, deltaTime, latency) {
|
||||
//this.owner.dispatchEvent ({type:"ncBandWidth", kbps:p_bw, latency:latency});
|
||||
};
|
||||
|
||||
_aNC[i].client.onBWCheck = function (counter) {
|
||||
return ++counter;
|
||||
};
|
||||
|
||||
_aNC[i].client.onStatus = function (info) {
|
||||
//
|
||||
};
|
||||
*/
|
||||
|
||||
}
|
||||
m_connListCounter = 0;
|
||||
nextConnect ();
|
||||
}
|
||||
|
||||
private function nextConnect():void
|
||||
{
|
||||
trace("*** Connection: "+ m_connListCounter + ": "+m_connList[m_connListCounter].protocol + "://" + m_serverName + m_connList[m_connListCounter].port + "/" + m_appName);
|
||||
|
||||
try {
|
||||
_aNC[m_connListCounter].connect(m_connList[m_connListCounter].protocol + "://" + m_serverName + m_connList[m_connListCounter].port + "/" + m_appName);
|
||||
|
||||
} catch (error:Error) {
|
||||
// statements
|
||||
trace("*** Caught an error condition: "+error);
|
||||
m_connListCounter = m_connList.length+1;
|
||||
}
|
||||
// statements
|
||||
clearInterval(_aNC["ncInt" + m_connListCounter]);
|
||||
|
||||
if ((m_connListCounter < m_connList.length - 1))
|
||||
{
|
||||
m_connListCounter++;
|
||||
_aNC["ncInt" + m_connListCounter] = setInterval(nextConnect,1500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Cleans up all connections if none have succeeded by the timeout interval
|
||||
private function onFlashComConnectTimeOut(timeout:Number):void
|
||||
{
|
||||
stopAll();
|
||||
}
|
||||
|
||||
private function handleGoodConnect(_nc:NetConnection):void {
|
||||
negotiating=false;
|
||||
trace("Handing OFF NetConnection");
|
||||
clearInterval(m_flashComConnectTimeOut);
|
||||
_ncRef.connectStream();
|
||||
_ncRef.onBWDone(null,_nc);
|
||||
//dispatchEvent(event);
|
||||
// Need to enable and pass to Jplayer event system- revisit
|
||||
// right now handing back a hardcoded reference that is passed in
|
||||
// Should come up with a more loosely coupled way via event dispatch
|
||||
|
||||
}
|
||||
|
||||
public function getNegotiating():Boolean {
|
||||
return negotiating;
|
||||
}
|
||||
|
||||
public function setNegotiating(bool:Boolean):void {
|
||||
negotiating=bool;
|
||||
}
|
||||
|
||||
|
||||
public function stopAll(bool:Boolean=false):void {
|
||||
|
||||
//this.dispatchEvent ({type:"ncFailedToConnect", timeout:timeout});
|
||||
// Need to enable and pass to Jplayer event system- revisit
|
||||
// trace(_aNC+":"+m_flashComConnectTimeOut+":"+m_connList.length)
|
||||
if(_aNC!=null && !isNaN(m_flashComConnectTimeOut) ) {
|
||||
clearInterval(m_flashComConnectTimeOut);
|
||||
for (var i:uint = 0; i < m_connList.length; i++)
|
||||
{
|
||||
if (_aNC[i]!=null)
|
||||
{
|
||||
clearInterval(_aNC["ncInt" + i]);
|
||||
_aNC[i].close();
|
||||
if(bool==false) {
|
||||
_aNC[i].client = null;
|
||||
}
|
||||
_aNC[i] = null;
|
||||
delete _aNC[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function netStatus(event:NetStatusEvent):void {
|
||||
|
||||
trace(event.info.code);
|
||||
if(event.info.description != undefined) {
|
||||
trace(event.info.description);
|
||||
}
|
||||
_aNC[event.target.client.id].client.pending = true;
|
||||
|
||||
// this.owner.m_validNetConnection = this.client.owner[this.client.connIndex];
|
||||
// if (info.description == "[ License.Limit.Exceeded ]") {
|
||||
|
||||
switch (event.info.code) {
|
||||
case "NetConnection.Connect.IdleTimeOut":
|
||||
trace("IDLE TIMEOUT OCCURRED!")
|
||||
negotiating=true;
|
||||
idleTimeOut=true;
|
||||
_ncRef.shutDownNcNs();
|
||||
break;
|
||||
case "NetConnection.Connect.Closed":
|
||||
if(!negotiating && !idleTimeOut) {
|
||||
idleTimeOut = false;
|
||||
_ncRef.doneYet();
|
||||
}
|
||||
break;
|
||||
case "NetConnection.Connect.InvalidApp":
|
||||
case "NetConnection.Connect.Rejected":
|
||||
//handleRejectedOrInvalid(event)
|
||||
break;
|
||||
case "NetConnection.Call.Failed":
|
||||
/*
|
||||
if (event.info.description.indexOf("_checkbw") != -1) {
|
||||
event.target.expectBWDone = true;
|
||||
event.target.call("checkBandwidth",null);
|
||||
}
|
||||
*/
|
||||
break;
|
||||
case "NetConnection.Connect.Success":
|
||||
var i:uint=0;
|
||||
for ( i = 0; i<_aNC.length; i++) {
|
||||
if (_aNC[i] && (i != event.target.client.id)) {
|
||||
_aNC[i].close();
|
||||
_aNC[i] = null;
|
||||
}
|
||||
}
|
||||
var _nc:NetConnection = NetConnection(event.target);
|
||||
var connID:Number = event.target.client.id;
|
||||
var _actualPort:String = m_connList[m_connListCounter].port;
|
||||
var _actualProtocol:String = m_connList[m_connListCounter].protocol;
|
||||
|
||||
// See if we have version info
|
||||
var _serverVersion:String = "UNKNOWN";
|
||||
if (event.info.data && event.info.data.version) {
|
||||
_serverVersion = event.info.data.version;
|
||||
}
|
||||
trace("Connect ID: "+connID+" - PORT: "+_actualPort+" - PROTOCOL: "+_actualProtocol+" - FMS Version: "+_serverVersion);
|
||||
|
||||
clearInterval(_aNC["ncInt" + connID]);
|
||||
clearInterval(_aNC["ncInt" + m_connListCounter]);
|
||||
|
||||
handleGoodConnect(_nc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Catches any netconnection net security errors
|
||||
* @private
|
||||
*/
|
||||
private function netSecurityError(event:SecurityErrorEvent):void {
|
||||
trace("SECURITY ERROR:"+event);
|
||||
//dispatchEvent(event);
|
||||
// Need to enable and pass to Jplayer event system- revisit
|
||||
}
|
||||
|
||||
/** Catches any async errors
|
||||
* @private
|
||||
*/
|
||||
private function asyncError(event:AsyncErrorEvent):void {
|
||||
trace("ASYNC ERROR:"+event.error);
|
||||
//dispatchEvent(event);
|
||||
// Need to enable and pass to Jplayer event system- revisit
|
||||
}
|
||||
|
||||
|
||||
|
||||
}// class
|
||||
|
||||
} //package
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT license.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Mark J Panaghiston
|
||||
* Date: 20th May 2013
|
||||
*/
|
||||
|
||||
package happyworm.jPlayer {
|
||||
import flash.events.Event;
|
||||
|
||||
public class JplayerEvent extends Event {
|
||||
|
||||
// The event strings must match those in the JavaScript's $.jPlayer.event object
|
||||
|
||||
public static const JPLAYER_READY:String = "jPlayer_ready";
|
||||
public static const JPLAYER_FLASHRESET:String = "jPlayer_flashreset"; // Handled in JavaScript
|
||||
public static const JPLAYER_RESIZE:String = "jPlayer_resize"; // Handled in JavaScript
|
||||
public static const JPLAYER_REPEAT:String = "jPlayer_repeat"; // Handled in JavaScript
|
||||
public static const JPLAYER_CLICK:String = "jPlayer_click";
|
||||
public static const JPLAYER_ERROR:String = "jPlayer_error";
|
||||
public static const JPLAYER_WARNING:String = "jPlayer_warning"; // Currently not used by the flash solution
|
||||
|
||||
public static const JPLAYER_LOADSTART:String = "jPlayer_loadstart";
|
||||
public static const JPLAYER_PROGRESS:String = "jPlayer_progress";
|
||||
public static const JPLAYER_SUSPEND:String = "jPlayer_suspend"; // Not implemented
|
||||
public static const JPLAYER_ABORT:String = "jPlayer_abort"; // Not implemented
|
||||
public static const JPLAYER_EMPTIED:String = "jPlayer_emptied"; // Not implemented
|
||||
public static const JPLAYER_STALLED:String = "jPlayer_stalled"; // Not implemented
|
||||
public static const JPLAYER_PLAY:String = "jPlayer_play";
|
||||
public static const JPLAYER_PAUSE:String = "jPlayer_pause";
|
||||
public static const JPLAYER_LOADEDMETADATA:String = "jPlayer_loadedmetadata"; // MP3 has no equivilent
|
||||
public static const JPLAYER_LOADEDDATA:String = "jPlayer_loadeddata"; // Not implemented
|
||||
public static const JPLAYER_WAITING:String = "jPlayer_waiting"; // Not implemented (Done in: MP3)
|
||||
public static const JPLAYER_PLAYING:String = "jPlayer_playing"; // Not implemented (Done in: MP3)
|
||||
public static const JPLAYER_CANPLAY:String = "jPlayer_canplay"; // Not implemented (Done in: MP3)
|
||||
public static const JPLAYER_CANPLAYTHROUGH:String = "jPlayer_canplaythrough"; // Not implemented (Done in: MP3)
|
||||
public static const JPLAYER_SEEKING:String = "jPlayer_seeking";
|
||||
public static const JPLAYER_SEEKED:String = "jPlayer_seeked";
|
||||
public static const JPLAYER_TIMEUPDATE:String = "jPlayer_timeupdate";
|
||||
public static const JPLAYER_ENDED:String = "jPlayer_ended";
|
||||
public static const JPLAYER_RATECHANGE:String = "jPlayer_ratechange"; // Not implemented
|
||||
public static const JPLAYER_DURATIONCHANGE:String = "jPlayer_durationchange"; // Not implemented
|
||||
public static const JPLAYER_VOLUMECHANGE:String = "jPlayer_volumechange"; // See JavaScript
|
||||
|
||||
// Events used internal to jPlayer's Flash.
|
||||
public static const DEBUG_MSG:String = "debug_msg";
|
||||
|
||||
public var data:JplayerStatus;
|
||||
public var msg:String = "";
|
||||
|
||||
public function JplayerEvent(type:String, data:JplayerStatus, msg:String = "", bubbles:Boolean = false, cancelable:Boolean = false) {
|
||||
super(type, bubbles, cancelable);
|
||||
this.data = data;
|
||||
this.msg = msg;
|
||||
}
|
||||
public override function clone():Event {
|
||||
return new JplayerEvent(type, data, msg, bubbles, cancelable);
|
||||
}
|
||||
public override function toString():String {
|
||||
return formatToString("JplayerEvent", "type", "bubbles", "cancelable", "eventPhase", "data", "msg");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT license.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Mark J Panaghiston
|
||||
* Date: 28th May 2013
|
||||
*/
|
||||
|
||||
package happyworm.jPlayer {
|
||||
import flash.display.Sprite;
|
||||
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundLoaderContext;
|
||||
import flash.media.SoundTransform;
|
||||
import flash.net.URLRequest;
|
||||
import flash.utils.Timer;
|
||||
import flash.errors.IOError;
|
||||
import flash.events.*;
|
||||
|
||||
public class JplayerMp3 extends Sprite {
|
||||
private var mySound:Sound = new Sound();
|
||||
private var myChannel:SoundChannel = new SoundChannel();
|
||||
private var myContext:SoundLoaderContext = new SoundLoaderContext(3000, false);
|
||||
private var myTransform:SoundTransform = new SoundTransform();
|
||||
private var myRequest:URLRequest = new URLRequest();
|
||||
|
||||
private var timeUpdateTimer:Timer = new Timer(250, 0); // Matched to HTML event freq
|
||||
private var progressTimer:Timer = new Timer(250, 0); // Matched to HTML event freq
|
||||
private var seekingTimer:Timer = new Timer(100, 0); // Internal: How often seeking is checked to see if it is over.
|
||||
private var playingTimer:Timer = new Timer(100, 0); // Internal: How often waiting/playing is checked.
|
||||
private var waitingTimer:Timer = new Timer(3000, 0); // Internal: Check from loadstart to loadOpen. Generates a waiting event.
|
||||
|
||||
public var myStatus:JplayerStatus = new JplayerStatus();
|
||||
|
||||
public function JplayerMp3(volume:Number) {
|
||||
timeUpdateTimer.addEventListener(TimerEvent.TIMER, timeUpdateHandler);
|
||||
progressTimer.addEventListener(TimerEvent.TIMER, progressHandler);
|
||||
seekingTimer.addEventListener(TimerEvent.TIMER, seekingHandler);
|
||||
playingTimer.addEventListener(TimerEvent.TIMER, playingHandler);
|
||||
waitingTimer.addEventListener(TimerEvent.TIMER, waitingHandler);
|
||||
setVolume(volume);
|
||||
}
|
||||
public function setFile(src:String):void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "setFile: " + src));
|
||||
if(myStatus.isPlaying) {
|
||||
myChannel.stop();
|
||||
}
|
||||
progressUpdates(false);
|
||||
timeUpdates(false);
|
||||
waitingTimer.stop();
|
||||
try {
|
||||
mySound.close();
|
||||
} catch (err:IOError) {
|
||||
// Occurs if the file is either yet to be opened or has finished downloading.
|
||||
}
|
||||
mySound = null;
|
||||
mySound = new Sound();
|
||||
mySound.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
|
||||
mySound.addEventListener(Event.OPEN, loadOpen);
|
||||
mySound.addEventListener(Event.COMPLETE, loadComplete);
|
||||
myRequest = new URLRequest(src);
|
||||
myStatus.reset();
|
||||
myStatus.src = src;
|
||||
myStatus.srcSet = true;
|
||||
timeUpdateEvent();
|
||||
}
|
||||
public function clearFile():void {
|
||||
setFile("");
|
||||
myStatus.srcSet = false;
|
||||
}
|
||||
private function errorHandler(err:IOErrorEvent):void {
|
||||
// MP3 player needs to stop progress and timeupdate events as they are started before the error occurs.
|
||||
// NB: The MP4 player works differently and the error occurs before they are started.
|
||||
progressUpdates(false);
|
||||
timeUpdates(false);
|
||||
myStatus.error(); // Resets status except the src, and it sets srcError property.
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_ERROR, myStatus));
|
||||
}
|
||||
private function loadOpen(e:Event):void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "loadOpen:"));
|
||||
waitingTimer.stop();
|
||||
myStatus.loading();
|
||||
if(myStatus.playOnLoad) {
|
||||
myStatus.playOnLoad = false; // Capture the flag
|
||||
// this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADSTART, myStatus)); // So loadstart event happens before play event occurs.
|
||||
play();
|
||||
} else {
|
||||
// this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADSTART, myStatus));
|
||||
pause();
|
||||
}
|
||||
progressUpdates(true);
|
||||
}
|
||||
private function loadComplete(e:Event):void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "loadComplete:"));
|
||||
myStatus.loaded();
|
||||
progressUpdates(false);
|
||||
progressEvent();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_CANPLAYTHROUGH, myStatus));
|
||||
}
|
||||
private function soundCompleteHandler(e:Event):void {
|
||||
myStatus.pausePosition = 0;
|
||||
myStatus.isPlaying = false;
|
||||
timeUpdates(false);
|
||||
timeUpdateEvent();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_ENDED, myStatus));
|
||||
}
|
||||
private function progressUpdates(active:Boolean):void {
|
||||
// Using a timer rather than Flash's load progress event, because that event gave data at about 200Hz. The 10Hz timer is closer to HTML5 norm.
|
||||
if(active) {
|
||||
progressTimer.start();
|
||||
} else {
|
||||
progressTimer.stop();
|
||||
}
|
||||
}
|
||||
private function progressHandler(e:TimerEvent):void {
|
||||
progressEvent();
|
||||
}
|
||||
private function progressEvent():void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "progressEvent:"));
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PROGRESS, myStatus));
|
||||
}
|
||||
private function timeUpdates(active:Boolean):void {
|
||||
if(active) {
|
||||
timeUpdateTimer.start();
|
||||
playingTimer.start();
|
||||
} else {
|
||||
timeUpdateTimer.stop();
|
||||
playingTimer.stop();
|
||||
}
|
||||
}
|
||||
private function timeUpdateHandler(e:TimerEvent):void {
|
||||
timeUpdateEvent();
|
||||
}
|
||||
private function timeUpdateEvent():void {
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_TIMEUPDATE, myStatus));
|
||||
}
|
||||
private function seeking(active:Boolean):void {
|
||||
if(active) {
|
||||
seekingEvent();
|
||||
waitingEvent();
|
||||
seekingTimer.start();
|
||||
} else {
|
||||
seekingTimer.stop();
|
||||
}
|
||||
}
|
||||
private function seekingHandler(e:TimerEvent):void {
|
||||
if(myStatus.pausePosition <= getDuration()) {
|
||||
seekedEvent();
|
||||
seeking(false);
|
||||
if(myStatus.playOnSeek) {
|
||||
myStatus.playOnSeek = false; // Capture the flag.
|
||||
play();
|
||||
}
|
||||
} else if(myStatus.isLoaded && (myStatus.pausePosition > getDuration())) {
|
||||
// Illegal seek time
|
||||
seeking(false);
|
||||
seekedEvent();
|
||||
pause(0);
|
||||
}
|
||||
}
|
||||
private function seekingEvent():void {
|
||||
myStatus.isSeeking = true;
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_SEEKING, myStatus));
|
||||
}
|
||||
private function seekedEvent():void {
|
||||
myStatus.isSeeking = false;
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_SEEKED, myStatus));
|
||||
}
|
||||
private function playingHandler(e:TimerEvent):void {
|
||||
checkPlaying(false); // Without forcing playing event.
|
||||
}
|
||||
private function checkPlaying(force:Boolean):void {
|
||||
if(mySound.isBuffering) {
|
||||
if(!myStatus.isWaiting) {
|
||||
waitingEvent();
|
||||
}
|
||||
} else {
|
||||
if(myStatus.isWaiting || force) {
|
||||
playingEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
private function waitingEvent():void {
|
||||
myStatus.isWaiting = true;
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_WAITING, myStatus));
|
||||
}
|
||||
private function playingEvent():void {
|
||||
myStatus.isWaiting = false;
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_CANPLAY, myStatus));
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PLAYING, myStatus));
|
||||
}
|
||||
private function waitingHandler(e:TimerEvent):void {
|
||||
waitingTimer.stop();
|
||||
if(myStatus.playOnLoad) {
|
||||
waitingEvent();
|
||||
}
|
||||
}
|
||||
public function load():Boolean {
|
||||
if(myStatus.loadRequired()) {
|
||||
myStatus.startingDownload();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADSTART, myStatus));
|
||||
waitingTimer.start();
|
||||
mySound.load(myRequest, myContext);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function play(time:Number = NaN):Boolean {
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
|
||||
if(!isNaN(time) && myStatus.srcSet) {
|
||||
if(myStatus.isPlaying) {
|
||||
myChannel.stop();
|
||||
myStatus.isPlaying = false;
|
||||
}
|
||||
myStatus.pausePosition = time;
|
||||
}
|
||||
|
||||
if(myStatus.isStartingDownload) {
|
||||
myStatus.playOnLoad = true; // Raise flag, captured in loadOpen()
|
||||
return true;
|
||||
} else if(myStatus.loadRequired()) {
|
||||
myStatus.playOnLoad = true; // Raise flag, captured in loadOpen()
|
||||
return load();
|
||||
} else if((myStatus.isLoading || myStatus.isLoaded) && !myStatus.isPlaying) {
|
||||
if(myStatus.isLoaded && myStatus.pausePosition > getDuration()) { // The time is invalid, ie., past the end.
|
||||
myStatus.pausePosition = 0;
|
||||
timeUpdates(false);
|
||||
timeUpdateEvent();
|
||||
if(wasPlaying) { // For when playing and then get a play(huge)
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PAUSE, myStatus));
|
||||
}
|
||||
} else if(myStatus.pausePosition > getDuration()) {
|
||||
myStatus.playOnSeek = true;
|
||||
seeking(true);
|
||||
} else {
|
||||
myStatus.isPlaying = true; // Set immediately before playing. Could affects events.
|
||||
myChannel = mySound.play(myStatus.pausePosition);
|
||||
myChannel.soundTransform = myTransform;
|
||||
myChannel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
|
||||
timeUpdates(true);
|
||||
if(!wasPlaying) {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PLAY, myStatus));
|
||||
}
|
||||
checkPlaying(true); // Force the playing event unless waiting, which will be dealt with in the playingTimer.
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function pause(time:Number = NaN):Boolean {
|
||||
myStatus.playOnLoad = false; // Reset flag in case load/play issued immediately before this command, ie., before loadOpen() event.
|
||||
myStatus.playOnSeek = false; // Reset flag in case play(time) issued before the command and is still seeking to time set.
|
||||
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
|
||||
// To avoid possible loops with timeupdate and pause(time). A pause() does not have the problem.
|
||||
var alreadyPausedAtTime:Boolean = false;
|
||||
if(!isNaN(time) && myStatus.pausePosition == time) {
|
||||
alreadyPausedAtTime = true;
|
||||
}
|
||||
|
||||
if(myStatus.isPlaying) {
|
||||
myStatus.isPlaying = false;
|
||||
myChannel.stop();
|
||||
if(myChannel.position > 0) { // Required otherwise a fast play then pause causes myChannel.position to equal zero and not the correct value. ie., When it happens leave pausePosition alone.
|
||||
myStatus.pausePosition = myChannel.position;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isNaN(time) && myStatus.srcSet) {
|
||||
myStatus.pausePosition = time;
|
||||
}
|
||||
|
||||
if(wasPlaying) {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PAUSE, myStatus));
|
||||
}
|
||||
|
||||
if(myStatus.isStartingDownload) {
|
||||
return true;
|
||||
} else if(myStatus.loadRequired()) {
|
||||
if(time > 0) { // We do not want the stop() command, which does pause(0), causing a load operation.
|
||||
return load();
|
||||
} else {
|
||||
return true; // Technically the pause(0) succeeded. ie., It did nothing, since nothing was required.
|
||||
}
|
||||
} else if(myStatus.isLoading || myStatus.isLoaded) {
|
||||
if(myStatus.isLoaded && myStatus.pausePosition > getDuration()) { // The time is invalid, ie., past the end.
|
||||
myStatus.pausePosition = 0;
|
||||
} else if(myStatus.pausePosition > getDuration()) {
|
||||
seeking(true);
|
||||
}
|
||||
timeUpdates(false);
|
||||
// Need to be careful with timeupdate event, otherwise a pause in a timeupdate event can cause a loop.
|
||||
// Neither pause() nor pause(time) will cause a timeupdate loop.
|
||||
if(wasPlaying || !isNaN(time) && !alreadyPausedAtTime) {
|
||||
timeUpdateEvent();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function playHead(percent:Number):Boolean {
|
||||
var time:Number = percent * getDuration() / 100;
|
||||
if(myStatus.isPlaying || myStatus.playOnLoad || myStatus.playOnSeek) {
|
||||
return play(time);
|
||||
} else {
|
||||
return pause(time);
|
||||
}
|
||||
}
|
||||
public function setVolume(v:Number):void {
|
||||
myStatus.volume = v;
|
||||
myTransform.volume = v;
|
||||
myChannel.soundTransform = myTransform;
|
||||
}
|
||||
private function updateStatusValues():void {
|
||||
myStatus.seekPercent = 100 * getLoadRatio();
|
||||
myStatus.currentTime = getCurrentTime();
|
||||
myStatus.currentPercentRelative = 100 * getCurrentRatioRel();
|
||||
myStatus.currentPercentAbsolute = 100 * getCurrentRatioAbs();
|
||||
myStatus.duration = getDuration();
|
||||
}
|
||||
public function getLoadRatio():Number {
|
||||
if((myStatus.isLoading || myStatus.isLoaded) && mySound.bytesTotal > 0) {
|
||||
return mySound.bytesLoaded / mySound.bytesTotal;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getDuration():Number {
|
||||
if(mySound.length > 0) {
|
||||
return mySound.length;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getCurrentTime():Number {
|
||||
if(myStatus.isPlaying) {
|
||||
return myChannel.position;
|
||||
} else {
|
||||
return myStatus.pausePosition;
|
||||
}
|
||||
}
|
||||
public function getCurrentRatioRel():Number {
|
||||
if((getDuration() > 0) && (getCurrentTime() <= getDuration())) {
|
||||
return getCurrentTime() / getDuration();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getCurrentRatioAbs():Number {
|
||||
return getCurrentRatioRel() * getLoadRatio();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,412 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT license.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Mark J Panaghiston
|
||||
* Date: 29th January 2013
|
||||
*/
|
||||
|
||||
package happyworm.jPlayer {
|
||||
import flash.display.Sprite;
|
||||
|
||||
import flash.media.Video;
|
||||
import flash.media.SoundTransform;
|
||||
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
|
||||
import flash.utils.Timer;
|
||||
|
||||
import flash.events.NetStatusEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.events.TimerEvent;
|
||||
|
||||
public class JplayerMp4 extends Sprite {
|
||||
|
||||
public var myVideo:Video = new Video();
|
||||
private var myConnection:NetConnection;
|
||||
private var myStream:NetStream;
|
||||
|
||||
private var myTransform:SoundTransform = new SoundTransform();
|
||||
|
||||
public var myStatus:JplayerStatus = new JplayerStatus();
|
||||
|
||||
private var timeUpdateTimer:Timer = new Timer(250, 0); // Matched to HTML event freq
|
||||
private var progressTimer:Timer = new Timer(250, 0); // Matched to HTML event freq
|
||||
private var seekingTimer:Timer = new Timer(100, 0); // Internal: How often seeking is checked to see if it is over.
|
||||
|
||||
public function JplayerMp4(volume:Number) {
|
||||
myConnection = new NetConnection();
|
||||
myConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
|
||||
myConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
|
||||
myVideo.smoothing = true;
|
||||
this.addChild(myVideo);
|
||||
|
||||
timeUpdateTimer.addEventListener(TimerEvent.TIMER, timeUpdateHandler);
|
||||
progressTimer.addEventListener(TimerEvent.TIMER, progressHandler);
|
||||
seekingTimer.addEventListener(TimerEvent.TIMER, seekingHandler);
|
||||
|
||||
myStatus.volume = volume;
|
||||
}
|
||||
private function progressUpdates(active:Boolean):void {
|
||||
if(active) {
|
||||
progressTimer.start();
|
||||
} else {
|
||||
progressTimer.stop();
|
||||
}
|
||||
}
|
||||
private function progressHandler(e:TimerEvent):void {
|
||||
if(myStatus.isLoading) {
|
||||
if(getLoadRatio() == 1) { // Close as can get to a loadComplete event since client.onPlayStatus only works with FMS
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "progressHandler: loadComplete"));
|
||||
myStatus.loaded();
|
||||
progressUpdates(false);
|
||||
}
|
||||
}
|
||||
progressEvent();
|
||||
}
|
||||
private function progressEvent():void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "progressEvent:"));
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PROGRESS, myStatus));
|
||||
}
|
||||
private function timeUpdates(active:Boolean):void {
|
||||
if(active) {
|
||||
timeUpdateTimer.start();
|
||||
} else {
|
||||
timeUpdateTimer.stop();
|
||||
}
|
||||
}
|
||||
private function timeUpdateHandler(e:TimerEvent):void {
|
||||
timeUpdateEvent();
|
||||
}
|
||||
private function timeUpdateEvent():void {
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_TIMEUPDATE, myStatus));
|
||||
}
|
||||
private function seeking(active:Boolean):void {
|
||||
if(active) {
|
||||
if(!myStatus.isSeeking) {
|
||||
seekingEvent();
|
||||
}
|
||||
seekingTimer.start();
|
||||
} else {
|
||||
if(myStatus.isSeeking) {
|
||||
seekedEvent();
|
||||
}
|
||||
seekingTimer.stop();
|
||||
}
|
||||
}
|
||||
private function seekingHandler(e:TimerEvent):void {
|
||||
if(getSeekTimeRatio() <= getLoadRatio()) {
|
||||
seeking(false);
|
||||
if(myStatus.playOnSeek) {
|
||||
myStatus.playOnSeek = false; // Capture the flag.
|
||||
play(myStatus.pausePosition); // Must pass time or the seek time is never set.
|
||||
} else {
|
||||
pause(myStatus.pausePosition); // Must pass time or the stream.time is read.
|
||||
}
|
||||
} else if(myStatus.metaDataReady && myStatus.pausePosition > myStatus.duration) {
|
||||
// Illegal seek time
|
||||
seeking(false);
|
||||
pause(0);
|
||||
}
|
||||
}
|
||||
private function seekingEvent():void {
|
||||
myStatus.isSeeking = true;
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_SEEKING, myStatus));
|
||||
}
|
||||
private function seekedEvent():void {
|
||||
myStatus.isSeeking = false;
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_SEEKED, myStatus));
|
||||
}
|
||||
private function netStatusHandler(e:NetStatusEvent):void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "netStatusHandler: '" + e.info.code + "'"));
|
||||
switch(e.info.code) {
|
||||
case "NetConnection.Connect.Success":
|
||||
connectStream();
|
||||
break;
|
||||
case "NetStream.Play.Start":
|
||||
// This event code occurs once, when the media is opened. Equiv to loadOpen() in mp3 player.
|
||||
myStatus.loading();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADSTART, myStatus));
|
||||
progressUpdates(true);
|
||||
// See onMetaDataHandler() for other condition, since duration is vital.
|
||||
break;
|
||||
case "NetStream.Play.Stop":
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "NetStream.Play.Stop: getDuration() - getCurrentTime() = " + (getDuration() - getCurrentTime())));
|
||||
|
||||
// Check if media is at the end (or close) otherwise this was due to download bandwidth stopping playback. ie., Download is not fast enough.
|
||||
if(Math.abs(getDuration() - getCurrentTime()) < 150) { // Testing found 150ms worked best for M4A files, where playHead(99.9) caused a stuck state due to firing with ~116ms left to play.
|
||||
endedEvent();
|
||||
}
|
||||
break;
|
||||
case "NetStream.Seek.InvalidTime":
|
||||
// Used for capturing invalid set times and clicks on the end of the progress bar.
|
||||
endedEvent();
|
||||
break;
|
||||
case "NetStream.Play.StreamNotFound":
|
||||
myStatus.error(); // Resets status except the src, and it sets srcError property.
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_ERROR, myStatus));
|
||||
break;
|
||||
}
|
||||
// "NetStream.Seek.Notify" event code is not very useful. It occurs after every seek(t) command issued and does not appear to wait for the media to be ready.
|
||||
}
|
||||
private function endedEvent():void {
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
pause(0);
|
||||
timeUpdates(false);
|
||||
timeUpdateEvent();
|
||||
if(wasPlaying) {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_ENDED, myStatus));
|
||||
}
|
||||
}
|
||||
private function securityErrorHandler(event:SecurityErrorEvent):void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "securityErrorHandler."));
|
||||
}
|
||||
private function connectStream():void {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "connectStream."));
|
||||
var customClient:Object = new Object();
|
||||
customClient.onMetaData = onMetaDataHandler;
|
||||
// customClient.onPlayStatus = onPlayStatusHandler; // According to the forums and my tests, onPlayStatus only works with FMS (Flash Media Server).
|
||||
myStream = null;
|
||||
myStream = new NetStream(myConnection);
|
||||
myStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
|
||||
myStream.client = customClient;
|
||||
myVideo.attachNetStream(myStream);
|
||||
setVolume(myStatus.volume);
|
||||
myStream.play(myStatus.src);
|
||||
}
|
||||
public function setFile(src:String):void {
|
||||
if(myStream != null) {
|
||||
myStream.close();
|
||||
}
|
||||
myVideo.clear();
|
||||
progressUpdates(false);
|
||||
timeUpdates(false);
|
||||
|
||||
myStatus.reset();
|
||||
myStatus.src = src;
|
||||
myStatus.srcSet = true;
|
||||
timeUpdateEvent();
|
||||
}
|
||||
public function clearFile():void {
|
||||
setFile("");
|
||||
myStatus.srcSet = false;
|
||||
}
|
||||
public function load():Boolean {
|
||||
if(myStatus.loadRequired()) {
|
||||
myStatus.startingDownload();
|
||||
myConnection.connect(null);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function play(time:Number = NaN):Boolean {
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
|
||||
if(!isNaN(time) && myStatus.srcSet) {
|
||||
if(myStatus.isPlaying) {
|
||||
myStream.pause();
|
||||
myStatus.isPlaying = false;
|
||||
}
|
||||
myStatus.pausePosition = time;
|
||||
}
|
||||
|
||||
if(myStatus.isStartingDownload) {
|
||||
myStatus.playOnLoad = true; // Raise flag, captured in onMetaDataHandler()
|
||||
return true;
|
||||
} else if(myStatus.loadRequired()) {
|
||||
myStatus.playOnLoad = true; // Raise flag, captured in onMetaDataHandler()
|
||||
return load();
|
||||
} else if((myStatus.isLoading || myStatus.isLoaded) && !myStatus.isPlaying) {
|
||||
if(myStatus.metaDataReady && myStatus.pausePosition > myStatus.duration) { // The time is invalid, ie., past the end.
|
||||
myStream.pause(); // Since it is playing by default at this point.
|
||||
myStatus.pausePosition = 0;
|
||||
myStream.seek(0);
|
||||
timeUpdates(false);
|
||||
timeUpdateEvent();
|
||||
if(wasPlaying) { // For when playing and then get a play(huge)
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PAUSE, myStatus));
|
||||
}
|
||||
} else if(getSeekTimeRatio() > getLoadRatio()) { // Use an estimate based on the downloaded amount
|
||||
myStatus.playOnSeek = true;
|
||||
seeking(true);
|
||||
myStream.pause(); // Since it is playing by default at this point.
|
||||
} else {
|
||||
if(!isNaN(time)) { // Avoid using seek() when it is already correct.
|
||||
myStream.seek(myStatus.pausePosition/1000); // Since time is in ms and seek() takes seconds
|
||||
}
|
||||
myStatus.isPlaying = true; // Set immediately before playing. Could affects events.
|
||||
myStream.resume();
|
||||
timeUpdates(true);
|
||||
if(!wasPlaying) {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PLAY, myStatus));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function pause(time:Number = NaN):Boolean {
|
||||
myStatus.playOnLoad = false; // Reset flag in case load/play issued immediately before this command, ie., before onMetadata() event.
|
||||
myStatus.playOnSeek = false; // Reset flag in case play(time) issued before the command and is still seeking to time set.
|
||||
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
|
||||
// To avoid possible loops with timeupdate and pause(time). A pause() does not have the problem.
|
||||
var alreadyPausedAtTime:Boolean = false;
|
||||
if(!isNaN(time) && myStatus.pausePosition == time) {
|
||||
alreadyPausedAtTime = true;
|
||||
}
|
||||
|
||||
// Need to wait for metadata to load before ever issuing a pause. The metadata handler will call this function if needed, when ready.
|
||||
if(myStream != null && myStatus.metaDataReady) { // myStream is a null until the 1st media is loaded. ie., The 1st ever setMedia being followed by a pause() or pause(t).
|
||||
myStream.pause();
|
||||
}
|
||||
if(myStatus.isPlaying) {
|
||||
myStatus.isPlaying = false;
|
||||
myStatus.pausePosition = myStream.time * 1000;
|
||||
}
|
||||
|
||||
if(!isNaN(time) && myStatus.srcSet) {
|
||||
myStatus.pausePosition = time;
|
||||
}
|
||||
|
||||
if(wasPlaying) {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PAUSE, myStatus));
|
||||
}
|
||||
|
||||
if(myStatus.isStartingDownload) {
|
||||
return true;
|
||||
} else if(myStatus.loadRequired()) {
|
||||
if(time > 0) { // We do not want the stop() command, which does pause(0), causing a load operation.
|
||||
return load();
|
||||
} else {
|
||||
return true; // Technically the pause(0) succeeded. ie., It did nothing, since nothing was required.
|
||||
}
|
||||
} else if(myStatus.isLoading || myStatus.isLoaded) {
|
||||
if(myStatus.metaDataReady && myStatus.pausePosition > myStatus.duration) { // The time is invalid, ie., past the end.
|
||||
myStatus.pausePosition = 0;
|
||||
myStream.seek(0);
|
||||
seekedEvent(); // Deals with seeking effect when using setMedia() then pause(huge). NB: There is no preceeding seeking event.
|
||||
} else if(!isNaN(time)) {
|
||||
if(getSeekTimeRatio() > getLoadRatio()) { // Use an estimate based on the downloaded amount
|
||||
seeking(true);
|
||||
} else {
|
||||
if(myStatus.metaDataReady) { // Otherwise seek(0) will stop the metadata loading.
|
||||
myStream.seek(myStatus.pausePosition/1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
timeUpdates(false);
|
||||
// Need to be careful with timeupdate event, otherwise a pause in a timeupdate event can cause a loop.
|
||||
// Neither pause() nor pause(time) will cause a timeupdate loop.
|
||||
if(wasPlaying || !isNaN(time) && !alreadyPausedAtTime) {
|
||||
timeUpdateEvent();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function playHead(percent:Number):Boolean {
|
||||
var time:Number = percent * getDuration() * getLoadRatio() / 100;
|
||||
if(myStatus.isPlaying || myStatus.playOnLoad || myStatus.playOnSeek) {
|
||||
return play(time);
|
||||
} else {
|
||||
return pause(time);
|
||||
}
|
||||
}
|
||||
public function setVolume(v:Number):void {
|
||||
myStatus.volume = v;
|
||||
myTransform.volume = v;
|
||||
if(myStream != null) {
|
||||
myStream.soundTransform = myTransform;
|
||||
}
|
||||
}
|
||||
private function updateStatusValues():void {
|
||||
myStatus.seekPercent = 100 * getLoadRatio();
|
||||
myStatus.currentTime = getCurrentTime();
|
||||
myStatus.currentPercentRelative = 100 * getCurrentRatioRel();
|
||||
myStatus.currentPercentAbsolute = 100 * getCurrentRatioAbs();
|
||||
myStatus.duration = getDuration();
|
||||
}
|
||||
public function getLoadRatio():Number {
|
||||
if((myStatus.isLoading || myStatus.isLoaded) && myStream.bytesTotal > 0) {
|
||||
return myStream.bytesLoaded / myStream.bytesTotal;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getDuration():Number {
|
||||
return myStatus.duration; // Set from meta data.
|
||||
}
|
||||
public function getCurrentTime():Number {
|
||||
if(myStatus.isPlaying) {
|
||||
return myStream.time * 1000;
|
||||
} else {
|
||||
return myStatus.pausePosition;
|
||||
}
|
||||
}
|
||||
public function getCurrentRatioRel():Number {
|
||||
if((getLoadRatio() > 0) && (getCurrentRatioAbs() <= getLoadRatio())) {
|
||||
return getCurrentRatioAbs() / getLoadRatio();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getCurrentRatioAbs():Number {
|
||||
if(getDuration() > 0) {
|
||||
return getCurrentTime() / getDuration();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getSeekTimeRatio():Number {
|
||||
if(getDuration() > 0) {
|
||||
return myStatus.pausePosition / getDuration();
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
public function onMetaDataHandler(info:Object):void { // Used in connectStream() in myStream.client object.
|
||||
// This event occurs when jumping to the start of static files! ie., seek(0) will cause this event to occur.
|
||||
if(!myStatus.metaDataReady) {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "onMetaDataHandler: " + info.duration + " | " + info.width + "x" + info.height));
|
||||
|
||||
myStatus.metaDataReady = true; // Set flag so that this event only effects jPlayer the 1st time.
|
||||
myStatus.metaData = info;
|
||||
myStatus.duration = info.duration * 1000; // Only available via Meta Data.
|
||||
if(info.width != undefined) {
|
||||
myVideo.width = myStatus.videoWidth = info.width;
|
||||
}
|
||||
if(info.height != undefined) {
|
||||
myVideo.height = myStatus.videoHeight = info.height;
|
||||
}
|
||||
|
||||
if(myStatus.playOnLoad) {
|
||||
myStatus.playOnLoad = false; // Capture the flag
|
||||
if(myStatus.pausePosition > 0 ) { // Important for setMedia followed by play(time).
|
||||
play(myStatus.pausePosition);
|
||||
} else {
|
||||
play(); // Not always sending pausePosition avoids the extra seek(0) for a normal play() command.
|
||||
}
|
||||
} else {
|
||||
pause(myStatus.pausePosition); // Always send the pausePosition. Important for setMedia() followed by pause(time). Deals with not reading stream.time with setMedia() and play() immediately followed by stop() or pause(0)
|
||||
}
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADEDMETADATA, myStatus));
|
||||
} else {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG, myStatus, "onMetaDataHandler: Already read (NO EFFECT)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,983 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT license.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Robert M. Hall
|
||||
* Date: 29th January 2013
|
||||
* Based on JplayerMp4.as with modifications for rtmp
|
||||
*/
|
||||
|
||||
package happyworm.jPlayer
|
||||
{
|
||||
import flash.display.Sprite;
|
||||
|
||||
import flash.media.Video;
|
||||
import flash.media.SoundTransform;
|
||||
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
import flash.net.Responder;
|
||||
|
||||
import flash.utils.Timer;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
import flash.events.NetStatusEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.events.ErrorEvent;
|
||||
import flash.events.UncaughtErrorEvent;
|
||||
import flash.utils.clearInterval;
|
||||
import flash.utils.setInterval;
|
||||
import happyworm.jPlayer.ConnectManager;
|
||||
|
||||
public class JplayerRtmp extends Sprite
|
||||
{
|
||||
|
||||
public var myVideo:Video = new Video;
|
||||
private var myConnection:NetConnection;
|
||||
private var myStream:NetStream;
|
||||
|
||||
public var responder:Responder;
|
||||
|
||||
private var streamName:String;
|
||||
|
||||
private var connectString:Object;
|
||||
|
||||
private var firstTime:Boolean = true;
|
||||
|
||||
private var myTransform:SoundTransform = new SoundTransform ;
|
||||
|
||||
public var myStatus:JplayerStatus = new JplayerStatus ;
|
||||
|
||||
private var ConnMgr:ConnectManager=new ConnectManager();
|
||||
|
||||
private var timeUpdateTimer:Timer = new Timer(250,0);// Matched to HTML event freq
|
||||
private var progressTimer:Timer = new Timer(250,0);// Matched to HTML event freq
|
||||
private var seekingTimer:Timer = new Timer(100,0);// Internal: How often seeking is checked to see if it is over.
|
||||
|
||||
private var startBuffer:Number = 3;
|
||||
private var maxBuffer:Number = 12;
|
||||
|
||||
public function JplayerRtmp(volume:Number)
|
||||
{
|
||||
myConnection = new NetConnection ;
|
||||
myConnection.client = this;
|
||||
|
||||
|
||||
// Moved the netconnection negotiation into the ConnectManager.as class - not needed for initial connection
|
||||
// may need to add eventHandler back in for errors only or just dispatch from the ConnectManager..revisit...
|
||||
|
||||
// myConnection.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
|
||||
// myConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
|
||||
myVideo.smoothing = true;
|
||||
this.addChild(myVideo);
|
||||
|
||||
timeUpdateTimer.addEventListener(TimerEvent.TIMER,timeUpdateHandler);
|
||||
progressTimer.addEventListener(TimerEvent.TIMER,progressHandler);
|
||||
seekingTimer.addEventListener(TimerEvent.TIMER,seekingHandler);
|
||||
|
||||
myStatus.volume = volume;
|
||||
|
||||
addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
|
||||
{
|
||||
trace("UNCAUGHT ERROR - try loading again");
|
||||
|
||||
if (event.error is Error)
|
||||
{
|
||||
var error:Error = event.error as Error;
|
||||
trace(error);
|
||||
// do something with the error
|
||||
}
|
||||
else if (event.error is ErrorEvent)
|
||||
{
|
||||
var errorEvent:ErrorEvent = event.error as ErrorEvent;
|
||||
// do something with the error
|
||||
trace(errorEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
// a non-Error, non-ErrorEvent type was thrown and uncaught
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function progressUpdates(active:Boolean):void
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
progressTimer.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
progressTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private function progressHandler(e:TimerEvent):void
|
||||
{
|
||||
if (myStatus.isLoading)
|
||||
{
|
||||
if ((getLoadRatio() == 1))
|
||||
{// Close as can get to a loadComplete event since client.onPlayStatus only works with FMS
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"progressHandler: loadComplete"));
|
||||
myStatus.loaded();
|
||||
progressUpdates(false);
|
||||
}
|
||||
}
|
||||
progressEvent();
|
||||
}
|
||||
|
||||
private function progressEvent():void
|
||||
{
|
||||
// temporarily disabled progress event dispatching - not really needed for rtmp
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"progressEvent:"));
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PROGRESS,myStatus));
|
||||
}
|
||||
|
||||
private function timeUpdates(active:Boolean):void
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
timeUpdateTimer.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
timeUpdateTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private function timeUpdateHandler(e:TimerEvent):void
|
||||
{
|
||||
timeUpdateEvent();
|
||||
}
|
||||
|
||||
private function timeUpdateEvent():void
|
||||
{
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_TIMEUPDATE,myStatus));
|
||||
}
|
||||
private function seeking(active:Boolean):void
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
if (! myStatus.isSeeking)
|
||||
{
|
||||
seekingEvent();
|
||||
}
|
||||
seekingTimer.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (myStatus.isSeeking)
|
||||
{
|
||||
seekedEvent();
|
||||
}
|
||||
seekingTimer.stop();
|
||||
}
|
||||
}
|
||||
private function seekingHandler(e:TimerEvent):void
|
||||
{
|
||||
if ((getSeekTimeRatio() <= getLoadRatio()))
|
||||
{
|
||||
seeking(false);
|
||||
if (myStatus.playOnSeek)
|
||||
{
|
||||
myStatus.playOnSeek = false;// Capture the flag.
|
||||
play(myStatus.pausePosition);// Must pass time or the seek time is never set.
|
||||
}
|
||||
else
|
||||
{
|
||||
pause(myStatus.pausePosition);// Must pass time or the stream.time is read.
|
||||
}
|
||||
}
|
||||
else if (myStatus.metaDataReady && myStatus.pausePosition > myStatus.duration)
|
||||
{
|
||||
// Illegal seek time
|
||||
seeking(false);
|
||||
pause(0);
|
||||
}
|
||||
}
|
||||
private function seekingEvent():void
|
||||
{
|
||||
myStatus.isSeeking = true;
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_SEEKING,myStatus));
|
||||
}
|
||||
private function seekedEvent():void
|
||||
{
|
||||
myStatus.isSeeking = false;
|
||||
updateStatusValues();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_SEEKED,myStatus));
|
||||
}
|
||||
|
||||
|
||||
private function netStatusHandler(e:NetStatusEvent):void
|
||||
{
|
||||
trace(("netStatusHandler: " + e.info.code));
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"netStatusHandler: '" + e.info.code + "'"));
|
||||
//trace("BEFORE: bufferTime: "+myStream.bufferTime+" - bufferTimeMax: "+myStream.bufferTimeMax);
|
||||
switch (e.info.code)
|
||||
{
|
||||
case "NetConnection.Connect.Success" :
|
||||
// connectStream(); // This method did not do anything sensible anyway.
|
||||
// Do not think this case occurs. This was for the static file connection.
|
||||
// Which now seems to be handled by the Connection Manager.
|
||||
break;
|
||||
case "NetStream.Buffer.Full":
|
||||
if(connectString.streamTYPE == "LIVE") {
|
||||
myStream.bufferTime = startBuffer;
|
||||
} else {
|
||||
myStream.bufferTime = maxBuffer;
|
||||
}
|
||||
break;
|
||||
case "NetStream.Buffer.Flush":
|
||||
myStream.bufferTime = startBuffer;
|
||||
break;
|
||||
case "NetStream.Buffer.Empty":
|
||||
myStream.bufferTime = startBuffer;
|
||||
break;
|
||||
case "NetStream.Seek.Notify":
|
||||
myStream.bufferTime = startBuffer;
|
||||
break;
|
||||
case "NetStream.Play.Start" :
|
||||
|
||||
if (firstTime) {
|
||||
firstTime = false; // Capture flag
|
||||
|
||||
myStatus.loading();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADSTART,myStatus));
|
||||
|
||||
// NB: With MP4 player both audio and video types get connected to myVideo.
|
||||
// NB: Had believed it was important for the audio too, otherwise what plays it?
|
||||
if(videoBinding) {
|
||||
myVideo.attachNetStream(myStream);
|
||||
}
|
||||
|
||||
setVolume(myStatus.volume);
|
||||
|
||||
// Really the progress event just needs to be generated once, and should probably happen before now.
|
||||
progressUpdates(true);
|
||||
|
||||
// This is an ASSUMPTION! Made it so that the default GUI worked.
|
||||
// Hence why this part should be refactored.
|
||||
// Lots of commands sequences after setMedia would be corrupted by this assumption.
|
||||
// Bascally, we assume that after a setMedia, you will play it.
|
||||
// Doing setMedia and pause(15) cause the flag to be set incorrectly and the GUI locks up.
|
||||
myStatus.isPlaying = true; // Should be handled elsewhere.
|
||||
}
|
||||
|
||||
// Under RTMP, this event code occurs every time the media starts playing and when a new position is seeked to, even when paused.
|
||||
|
||||
// Since under RTMP the event behaviour is quite different, believe a refactor is best here.
|
||||
// ie., Under RTMP we should be able to know a lot more info about the stream.
|
||||
|
||||
// See onMetaDataHandler() for other condition, since duration is vital.
|
||||
// See onResult() response handler too.
|
||||
// Appears to be some duplication between onMetaDataHandler() and onResult(), along with a race between them occuring.
|
||||
|
||||
break;
|
||||
case "NetStream.Play.UnpublishNotify":
|
||||
myStream.bufferTime = startBuffer; // was 3
|
||||
case "NetStream.Play.Stop" :
|
||||
myStream.bufferTime = startBuffer; // was 3
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"NetStream.Play.Stop: getDuration() - getCurrentTime() = " + (getDuration() - getCurrentTime())));
|
||||
|
||||
// Check if media is at the end (or close) otherwise this was due to download bandwidth stopping playback. ie., Download is not fast enough.
|
||||
if (Math.abs((getDuration() - getCurrentTime())) < 150)
|
||||
{// Testing found 150ms worked best for M4A files, where playHead(99.9) caused a stuck state due to firing with ~116ms left to play.
|
||||
//endedEvent();
|
||||
}
|
||||
break;
|
||||
case "NetStream.Seek.InvalidTime" :
|
||||
// Used for capturing invalid set times and clicks on the end of the progress bar.
|
||||
endedEvent();
|
||||
break;
|
||||
case "NetStream.Play.StreamNotFound" :
|
||||
myStatus.error();
|
||||
// Resets status except the src, and it sets srcError property.;
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_ERROR,myStatus));
|
||||
break;
|
||||
}
|
||||
//trace("AFTER: bufferTime: "+myStream.bufferTime+" - bufferTimeMax: "+myStream.bufferTimeMax);
|
||||
// "NetStream.Seek.Notify" event code is not very useful. It occurs after every seek(t) command issued and does not appear to wait for the media to be ready.
|
||||
}
|
||||
private function endedEvent():void
|
||||
{
|
||||
trace("ENDED STREAM EVENT");
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
|
||||
// timeUpdates(false);
|
||||
// timeUpdateEvent();
|
||||
pause(0);
|
||||
|
||||
if (wasPlaying)
|
||||
{
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_ENDED,myStatus));
|
||||
}
|
||||
}
|
||||
private function securityErrorHandler(event:SecurityErrorEvent):void
|
||||
{
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"securityErrorHandler."));
|
||||
}
|
||||
public function connectStream():void
|
||||
{
|
||||
trace("CONNECTING");
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"connectStream."));
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_CANPLAY,myStatus));
|
||||
|
||||
timeUpdates(true);
|
||||
progressUpdates(true);
|
||||
//myVideo.attachNetStream(myStream);
|
||||
//setVolume(myStatus.volume);
|
||||
}
|
||||
|
||||
private function onResult(result:Object):void
|
||||
{
|
||||
trace("OnResult EVENT FIRED!");
|
||||
myStatus.duration = parseFloat(result.toString()) * 1000;
|
||||
trace((("The stream length is " + result) + " seconds"));
|
||||
|
||||
if(!myConnection.connected) {
|
||||
load();
|
||||
} else {
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_CANPLAY,myStatus,"Rockit!"));
|
||||
|
||||
//myStatus.loaded();
|
||||
//myStatus.isPlaying=true;
|
||||
if (! myStatus.metaDataReady)
|
||||
{
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"onMetaDataHandler: " + myStatus.duration));
|
||||
|
||||
// Allow multiple onResult Handlers to affect size. As per PR #131 and #98.
|
||||
// myStatus.metaDataReady = true;
|
||||
|
||||
/*var info:Object = new Object();
|
||||
info.duration=myStatus.duration
|
||||
info.width=undefined;
|
||||
info.height=undefined;
|
||||
myStatus.metaData = info;
|
||||
*/
|
||||
if (myStatus.playOnLoad)
|
||||
{
|
||||
myStatus.playOnLoad = false;// Capture the flag
|
||||
if (myStatus.pausePosition > 0)
|
||||
{// Important for setMedia followed by play(time).
|
||||
play(myStatus.pausePosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
play();// Not always sending pausePosition avoids the extra seek(0) for a normal play() command.
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pause(myStatus.pausePosition);// Always send the pausePosition. Important for setMedia() followed by pause(time). Deals with not reading stream.time with setMedia() and play() immediately followed by stop() or pause(0)
|
||||
}
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADEDMETADATA,myStatus));
|
||||
}
|
||||
else
|
||||
{
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"onMetaDataHandler: Already read (NO EFFECT)"));
|
||||
}
|
||||
|
||||
myStream.play(streamName);
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PLAY,myStatus));
|
||||
// timeUpdates(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var overRideConnect:Boolean=false;
|
||||
public function doneYet():void {
|
||||
if(!myConnection.connected) {
|
||||
// try again
|
||||
ConnMgr.stopAll(true);
|
||||
overRideConnect=true;
|
||||
trace("Connected: "+myConnection.connected+" - "+myStatus.loadRequired());
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
private var videoBinding:Boolean=false;
|
||||
public function setFile(src:String,videoSupport:Boolean=false):void
|
||||
{
|
||||
// videoSupport turns on/off video - by default no video, audio only
|
||||
videoBinding=videoSupport;
|
||||
/* Dont close the stream or netconnection here anymore so we can recycle if host/appname are the same
|
||||
if ((myStream != null))
|
||||
{
|
||||
myStream.close();
|
||||
myConnection.close();
|
||||
}
|
||||
*/
|
||||
if(ConnMgr.getNegotiating() == true) {
|
||||
//ConnMgr.stopAll();
|
||||
ConnMgr.setNegotiating(false);
|
||||
}
|
||||
|
||||
myVideo.clear();
|
||||
|
||||
progressUpdates(false);
|
||||
timeUpdates(false);
|
||||
|
||||
myStatus.reset();
|
||||
myStatus.src = src;
|
||||
myStatus.srcSet = true;
|
||||
|
||||
firstTime = true;
|
||||
|
||||
//myStatus.loaded();
|
||||
|
||||
if(src != "") {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_CANPLAY,myStatus));
|
||||
}
|
||||
|
||||
//timeUpdateEvent();
|
||||
}
|
||||
|
||||
public function shutDownNcNs():void {
|
||||
trace("Connections Closed");
|
||||
timeUpdates(false);
|
||||
progressUpdates(false);
|
||||
myStream.close();
|
||||
myConnection.close();
|
||||
|
||||
myStatus.reset();
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_ENDED,myStatus));
|
||||
}
|
||||
|
||||
public function clearFile():void
|
||||
{
|
||||
if (myStream != null)
|
||||
{
|
||||
myStream.close();
|
||||
// Dont close the netConnection here any longer, as we may recycle it later
|
||||
// may need an extra way to close manually if switching media types after an rtmp session - revisit
|
||||
// myConnection.close();
|
||||
myStatus.reset();
|
||||
}
|
||||
setFile("");
|
||||
myStatus.srcSet = false;
|
||||
}
|
||||
|
||||
public function parseRTMPsrcConnect(rtmpSrc:String):Object
|
||||
{
|
||||
// rtmp://cp76372.live.edgefcs.net/live/Flash1Office@60204
|
||||
var appName:String = "";
|
||||
var streamFileName:String = "";
|
||||
var startIndex:uint = 2 + rtmpSrc.indexOf("//");
|
||||
var streamTYPE:String = "recorded";
|
||||
var host:String = rtmpSrc.substr(startIndex);
|
||||
var port:String = "";
|
||||
host = host.substr(0,host.indexOf("/"));
|
||||
var endHost:Number = startIndex + host.length + 1;
|
||||
|
||||
// See if there is a host port specified
|
||||
if(host.indexOf(":") != -1) {
|
||||
port = host.substr(host.indexOf(":")+1);
|
||||
host = host.substr(0,host.indexOf(":"));
|
||||
}
|
||||
|
||||
// Akamai specific live streams
|
||||
if (rtmpSrc.lastIndexOf("/live/") != -1)
|
||||
{
|
||||
trace("LIVE!");
|
||||
|
||||
|
||||
appName = rtmpSrc.substring(endHost,rtmpSrc.lastIndexOf("/live/") + 6);
|
||||
streamFileName = rtmpSrc.substr(rtmpSrc.lastIndexOf("/live/") + 6);
|
||||
streamTYPE="LIVE";
|
||||
} else {
|
||||
streamTYPE="RECORDED";
|
||||
|
||||
}
|
||||
|
||||
// Mp3 streams with standard appname/no instance name, mp3: prefix
|
||||
if (rtmpSrc.indexOf(".mp3") != -1)
|
||||
{
|
||||
appName = rtmpSrc.substring(endHost,rtmpSrc.indexOf("mp3:"));
|
||||
streamFileName = rtmpSrc.substr(rtmpSrc.indexOf("mp3:"));
|
||||
streamFileName = streamFileName.substr(0,streamFileName.length - 4);
|
||||
}
|
||||
// rtmp://cp83813.edgefcs.net/ondemand/rob_hall/bruce_campbell_oldspice.flv
|
||||
|
||||
// Mp4 streams with standard appname/no instance name, mp4: prefix
|
||||
if (rtmpSrc.indexOf("mp4:") != -1)
|
||||
{
|
||||
appName = rtmpSrc.substring(endHost,rtmpSrc.indexOf("mp4:"));
|
||||
streamFileName = rtmpSrc.substr(rtmpSrc.indexOf("mp4:"));
|
||||
streamFileName = streamFileName.substr(0,streamFileName.length - 4);
|
||||
}
|
||||
|
||||
// .f4v streams with standard appname/no instance name, .flv extension
|
||||
if (rtmpSrc.indexOf(".flv") != -1)
|
||||
{
|
||||
// allow use of ^ in rtmp string to indicate break point for an appname or instance name that
|
||||
// contains a / in it where it would require multiple connection attempts or manual configuratiom
|
||||
// of the appname/instancename
|
||||
var endApp:Number=0;
|
||||
if(rtmpSrc.indexOf("^") != -1) {
|
||||
endApp=rtmpSrc.indexOf("^");
|
||||
rtmpSrc.replace("^", "/");
|
||||
} else {
|
||||
endApp = rtmpSrc.indexOf("/",endHost);
|
||||
}
|
||||
appName = rtmpSrc.substring(endHost,endApp) + "/";
|
||||
streamFileName = rtmpSrc.substr(endApp+1);
|
||||
}
|
||||
|
||||
if(port=="") {
|
||||
port="MULTI";
|
||||
}
|
||||
//rtmp, rtmpt, rtmps, rtmpe, rtmpte
|
||||
|
||||
|
||||
trace(("\n\n*** HOST: " + host));
|
||||
trace(("*** PORT: " + port));
|
||||
trace(("*** APPNAME: " + appName));
|
||||
trace(("*** StreamName: " + streamFileName));
|
||||
|
||||
var streamParts:Object = new Object;
|
||||
streamParts.streamTYPE=streamTYPE;
|
||||
streamParts.appName = appName;
|
||||
streamParts.streamFileName = streamFileName;
|
||||
streamParts.hostName = host;
|
||||
streamName = streamFileName;
|
||||
|
||||
return streamParts;
|
||||
}
|
||||
|
||||
public function load():Boolean
|
||||
{
|
||||
//trace("LOAD: "+myStatus.src);
|
||||
if (myStatus.loadRequired() || overRideConnect==true)
|
||||
{
|
||||
overRideConnect=false;
|
||||
myStatus.startingDownload();
|
||||
var lastAppName:String;
|
||||
var lastHostName:String;
|
||||
|
||||
try{
|
||||
// we do a try, as these properties might not exist yet
|
||||
if(connectString.appName != "" && connectString.appName != undefined) {
|
||||
trace("PREVIOUS APP/HOST INFO AVAILABLE");
|
||||
lastAppName = connectString.appName;
|
||||
lastHostName = connectString.hostName;
|
||||
trace("LAST: "+lastAppName,lastHostName);
|
||||
}
|
||||
} catch (error:Error) {
|
||||
//trace("*** Caught an error condition: "+error);
|
||||
}
|
||||
|
||||
connectString = parseRTMPsrcConnect(myStatus.src);
|
||||
|
||||
|
||||
|
||||
trace("**** LOAD :: CONNECT SOURCE: " +connectString.hostName +" "+ connectString.appName);
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_WAITING, myStatus));
|
||||
|
||||
if((connectString.appName == lastAppName && connectString.hostName == lastHostName) && (myConnection.connected)) {
|
||||
// recycle the netConnection
|
||||
trace("RECYCLING NETCONNECTION");
|
||||
if ((myStream != null))
|
||||
{
|
||||
myStream.close();
|
||||
}
|
||||
connectStream();
|
||||
onBWDone(null,myConnection);
|
||||
} else {
|
||||
// myConnection.connect(connectString.appName);
|
||||
trace("NEW NetConnection Negotiation");
|
||||
if ((myStream != null))
|
||||
{
|
||||
myStream.close();
|
||||
myConnection.close();
|
||||
}
|
||||
|
||||
ConnMgr.stopAll(true);
|
||||
ConnMgr.negotiateConnect(this,connectString.hostName,connectString.appName);
|
||||
}
|
||||
|
||||
trace("**** LOAD2 :: CONNECT SOURCE: " +connectString.hostName +" "+ connectString.appName);
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_WAITING, myStatus));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function onFCUnsubscribe(info:Object):void
|
||||
{
|
||||
trace(("onFCUnSubscribe worked" + info));
|
||||
}
|
||||
|
||||
public function onFCSubscribe(info:Object):void
|
||||
{
|
||||
trace(("onFCSubscribe worked" + info));
|
||||
}
|
||||
|
||||
public function onBWDone(info:Object,nc:NetConnection):void
|
||||
{
|
||||
if(nc.connected) {
|
||||
myConnection=nc;
|
||||
trace(((("onBWDone " + info) + " :: ") + myStatus.src));
|
||||
|
||||
var customClient:Object = new Object ;
|
||||
customClient.onMetaData = onMetaDataHandler;
|
||||
customClient.onPlayStatus = onPlayStatusHandler;// According to the forums and my tests, onPlayStatus only works with FMS (Flash Media Server).
|
||||
|
||||
myStream = null;
|
||||
myStream = new NetStream(myConnection);
|
||||
myStream.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
|
||||
myStream.client = customClient;
|
||||
if(connectString.streamTYPE == "LIVE") {
|
||||
myStream.bufferTime = 3; // was 3
|
||||
myStream.bufferTimeMax = 24;
|
||||
startBuffer = 3;
|
||||
maxBuffer = 12;
|
||||
|
||||
} else {
|
||||
myStream.bufferTime = .2; // was 3
|
||||
myStream.bufferTimeMax = 0;
|
||||
startBuffer = .2;
|
||||
maxBuffer = 12;
|
||||
}
|
||||
|
||||
|
||||
//streamName="";
|
||||
//var connectString:Object = parseRTMPsrcConnect(myStatus.src);
|
||||
//streamName=connectString.streamFileName;
|
||||
|
||||
responder = new Responder(onResult);
|
||||
myConnection.call("getStreamLength",responder,streamName);
|
||||
} else {
|
||||
connectStream();
|
||||
}
|
||||
|
||||
trace("PLAY SOURCE: "+connectString);
|
||||
|
||||
}
|
||||
|
||||
public function play(time:Number = NaN):Boolean {
|
||||
//trace("PLAY: "+time+" - isPlaying: "+myStatus.isPlaying +" - myStatus.isStartingDownload:"+myStatus.isStartingDownload);
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
|
||||
if(!isNaN(time) && myStatus.srcSet) {
|
||||
if(myStatus.isPlaying) {
|
||||
myStream.pause();
|
||||
myStatus.isPlaying = false;
|
||||
}
|
||||
myStatus.pausePosition = time;
|
||||
}
|
||||
|
||||
if(myStatus.isStartingDownload) {
|
||||
myStatus.playOnLoad = true; // Raise flag, captured in onMetaDataHandler()
|
||||
return true;
|
||||
} else if(myStatus.loadRequired()) {
|
||||
myStatus.playOnLoad = true; // Raise flag, captured in onMetaDataHandler()
|
||||
return load();
|
||||
} else if((myStatus.isLoading || myStatus.isLoaded) && !myStatus.isPlaying) {
|
||||
if(myStatus.metaDataReady && myStatus.pausePosition > myStatus.duration && connectString.streamTYPE != "LIVE") { // The time is invalid, ie., past the end.
|
||||
myStream.pause(); // Since it is playing by default at this point.
|
||||
myStatus.pausePosition = 0;
|
||||
trace("SEEKER!");
|
||||
myStream.seek(0);
|
||||
timeUpdates(false);
|
||||
timeUpdateEvent();
|
||||
if(wasPlaying) { // For when playing and then get a play(huge)
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PAUSE, myStatus));
|
||||
}
|
||||
} else if(getSeekTimeRatio() > getLoadRatio()) { // Use an estimate based on the downloaded amount
|
||||
myStatus.playOnSeek = true;
|
||||
seeking(true);
|
||||
trace("SEEKER PAUSE!");
|
||||
myStream.pause(); // Since it is playing by default at this point.
|
||||
} else {
|
||||
if(!isNaN(time)) { // Avoid using seek() when it is already correct.
|
||||
trace("SEEKER3");
|
||||
myStream.seek(myStatus.pausePosition/1000); // Since time is in ms and seek() takes seconds
|
||||
}
|
||||
myStatus.isPlaying = true; // Set immediately before playing. Could affects events.
|
||||
trace("SHOULD GET RESUME!");
|
||||
myStream.resume();
|
||||
timeUpdates(true);
|
||||
if(!wasPlaying) {
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PLAY, myStatus));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function pause(time:Number=NaN):Boolean
|
||||
{
|
||||
//trace("PAUSE: "+time);
|
||||
myStatus.playOnLoad = false;// Reset flag in case load/play issued immediately before this command, ie., before onMetadata() event.
|
||||
myStatus.playOnSeek = false;// Reset flag in case play(time) issued before the command and is still seeking to time set.
|
||||
|
||||
var wasPlaying:Boolean = myStatus.isPlaying;
|
||||
|
||||
|
||||
// To avoid possible loops with timeupdate and pause(time). A pause() does not have the problem.
|
||||
var alreadyPausedAtTime:Boolean = false;
|
||||
if(!isNaN(time) && myStatus.pausePosition == time) {
|
||||
alreadyPausedAtTime = true;
|
||||
}
|
||||
|
||||
trace("!isNaN: "+!isNaN(time) +" isNaN: "+isNaN(time));
|
||||
|
||||
// Need to wait for metadata to load before ever issuing a pause. The metadata handler will call this function if needed, when ready.
|
||||
if (((myStream != null) && myStatus.metaDataReady))
|
||||
{// myStream is a null until the 1st media is loaded. ie., The 1st ever setMedia being followed by a pause() or pause(t).
|
||||
|
||||
if(connectString.streamTYPE == "LIVE") {
|
||||
trace("PAUSING LIVE");
|
||||
myStream.play(false)
|
||||
} else {
|
||||
trace("PAUSING RECORDED");
|
||||
myStream.pause();
|
||||
}
|
||||
}
|
||||
if (myStatus.isPlaying)
|
||||
{
|
||||
myStatus.isPlaying = false;
|
||||
myStatus.pausePosition = myStream.time * 1000;
|
||||
}
|
||||
|
||||
if (! isNaN(time) && myStatus.srcSet)
|
||||
{
|
||||
myStatus.pausePosition = time;
|
||||
}
|
||||
|
||||
if (wasPlaying)
|
||||
{
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_PAUSE,myStatus));
|
||||
}
|
||||
|
||||
if (myStatus.isStartingDownload)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (myStatus.loadRequired())
|
||||
{
|
||||
if ((time > 0))
|
||||
{// We do not want the stop() command, which does pause(0), causing a load operation.
|
||||
return load();
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;// Technically the pause(0) succeeded. ie., It did nothing, since nothing was required.
|
||||
}
|
||||
}
|
||||
else if (myStatus.isLoading || myStatus.isLoaded)
|
||||
{
|
||||
if (myStatus.metaDataReady && myStatus.pausePosition > myStatus.duration && connectString.streamTYPE != "LIVE" )
|
||||
{// The time is invalid, ie., past the end.
|
||||
myStatus.pausePosition = 0;
|
||||
|
||||
trace("GOT HERE!");
|
||||
myStream.seek(0);
|
||||
seekedEvent();// Deals with seeking effect when using setMedia() then pause(huge). NB: There is no preceeding seeking event.
|
||||
}
|
||||
else if (! isNaN(time))
|
||||
{
|
||||
if ((getSeekTimeRatio() > getLoadRatio()))
|
||||
{// Use an estimate based on the downloaded amount
|
||||
seeking(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (myStatus.metaDataReady && connectString.streamTYPE != "LIVE")
|
||||
{// Otherwise seek(0) will stop the metadata loading.
|
||||
trace("GOT HERE TOO!");
|
||||
myStream.seek(myStatus.pausePosition / 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
timeUpdates(false);
|
||||
// Need to be careful with timeupdate event, otherwise a pause in a timeupdate event can cause a loop.
|
||||
// Neither pause() nor pause(time) will cause a timeupdate loop.
|
||||
if(wasPlaying || !isNaN(time) && !alreadyPausedAtTime) {
|
||||
timeUpdateEvent();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function playHead(percent:Number):Boolean
|
||||
{
|
||||
var time:Number = percent * getDuration() * getLoadRatio() / 100;
|
||||
if (myStatus.isPlaying || myStatus.playOnLoad || myStatus.playOnSeek)
|
||||
{
|
||||
return play(time);
|
||||
}
|
||||
else
|
||||
{
|
||||
return pause(time);
|
||||
}
|
||||
}
|
||||
public function setVolume(v:Number):void
|
||||
{
|
||||
myStatus.volume = v;
|
||||
myTransform.volume = v;
|
||||
if ((myStream != null))
|
||||
{
|
||||
myStream.soundTransform = myTransform;
|
||||
}
|
||||
}
|
||||
private function updateStatusValues():void
|
||||
{
|
||||
//myStatus.seekPercent = 100 * getLoadRatio();
|
||||
myStatus.seekPercent = 100;
|
||||
myStatus.currentTime = getCurrentTime();
|
||||
myStatus.currentPercentRelative = 100 * getCurrentRatioRel();
|
||||
myStatus.currentPercentAbsolute = 100 * getCurrentRatioAbs();
|
||||
myStatus.duration = getDuration();
|
||||
}
|
||||
public function getLoadRatio():Number
|
||||
{
|
||||
return 1;
|
||||
/*trace("LoadRatio:"+myStream.bytesLoaded, myStream.bytesTotal);
|
||||
if((myStatus.isLoading || myStatus.isLoaded) && myStream.bytesTotal > 0) {
|
||||
|
||||
return myStream.bytesLoaded / myStream.bytesTotal;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
public function getDuration():Number
|
||||
{
|
||||
return myStatus.duration;// Set from meta data.
|
||||
}
|
||||
public function getCurrentTime():Number
|
||||
{
|
||||
if (myStatus.isPlaying)
|
||||
{
|
||||
//trace(myStream.time * 1000);
|
||||
return myStream.time * 1000; // was +1000
|
||||
}
|
||||
else
|
||||
{
|
||||
return myStatus.pausePosition;
|
||||
}
|
||||
}
|
||||
public function getCurrentRatioRel():Number
|
||||
{
|
||||
|
||||
if ((getCurrentRatioAbs() <= getLoadRatio()))
|
||||
{
|
||||
//if((getLoadRatio() > 0) && (getCurrentRatioAbs() <= getLoadRatio())) {
|
||||
return getCurrentRatioAbs() / getLoadRatio();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getCurrentRatioAbs():Number
|
||||
{
|
||||
if ((getDuration() > 0))
|
||||
{
|
||||
return getCurrentTime() / getDuration();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getSeekTimeRatio():Number
|
||||
{
|
||||
if ((getDuration() > 0))
|
||||
{
|
||||
return myStatus.pausePosition / getDuration();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
public function onPlayStatusHandler(infoObject:Object):void
|
||||
{
|
||||
trace((("OnPlayStatusHandler called: (" + getTimer()) + " ms)"));
|
||||
for (var prop:* in infoObject)
|
||||
{
|
||||
trace(((("\t" + prop) + ":\t") + infoObject[prop]));
|
||||
}
|
||||
if (infoObject.code == "NetStream.Play.Complete")
|
||||
{
|
||||
endedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public function onMetaDataHandler(info:Object):void
|
||||
{// Used in connectStream() in myStream.client object.
|
||||
// This event occurs when jumping to the start of static files! ie., seek(0) will cause this event to occur.
|
||||
|
||||
if (! myStatus.metaDataReady)
|
||||
{
|
||||
trace("\n\n*** METADATA FIRED! ***\n\n");
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"onMetaDataHandler: " + info.duration + " | " + info.width + "x" + info.height));
|
||||
|
||||
myStatus.metaDataReady = true;// Set flag so that this event only effects jPlayer the 1st time.
|
||||
myStatus.metaData = info;
|
||||
myStatus.duration = info.duration * 1000;// Only available via Meta Data.
|
||||
if (info.width != undefined)
|
||||
{
|
||||
myVideo.width = myStatus.videoWidth = info.width;
|
||||
}
|
||||
if (info.height != undefined)
|
||||
{
|
||||
myVideo.height = myStatus.videoHeight = info.height;
|
||||
}
|
||||
|
||||
if (myStatus.playOnLoad)
|
||||
{
|
||||
myStatus.playOnLoad = false;// Capture the flag
|
||||
if (myStatus.pausePosition > 0)
|
||||
{// Important for setMedia followed by play(time).
|
||||
play(myStatus.pausePosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
play();// Not always sending pausePosition avoids the extra seek(0) for a normal play() command.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pause(myStatus.pausePosition);// Always send the pausePosition. Important for setMedia() followed by pause(time). Deals with not reading stream.time with setMedia() and play() immediately followed by stop() or pause(0)
|
||||
}
|
||||
this.dispatchEvent(new JplayerEvent(JplayerEvent.JPLAYER_LOADEDMETADATA,myStatus));
|
||||
}
|
||||
else
|
||||
{
|
||||
//this.dispatchEvent(new JplayerEvent(JplayerEvent.DEBUG_MSG,myStatus,"onMetaDataHandler: Already read (NO EFFECT)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT license.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Mark J Panaghiston
|
||||
* Date: 5th June 2013
|
||||
*/
|
||||
|
||||
package happyworm.jPlayer {
|
||||
public class JplayerStatus {
|
||||
|
||||
public static const VERSION:String = "2.4.0"; // The version of the Flash jPlayer entity.
|
||||
|
||||
public var volume:Number = 0.5; // Not affected by reset()
|
||||
public var muted:Boolean = false; // Not affected by reset()
|
||||
|
||||
public var src:String;
|
||||
public var srcError:Boolean;
|
||||
|
||||
public var srcSet:Boolean;
|
||||
public var isPlaying:Boolean;
|
||||
public var isSeeking:Boolean;
|
||||
|
||||
public var isWaiting:Boolean;
|
||||
|
||||
public var playOnLoad:Boolean;
|
||||
public var playOnSeek:Boolean;
|
||||
|
||||
public var isStartingDownload:Boolean;
|
||||
public var isLoading:Boolean;
|
||||
public var isLoaded:Boolean;
|
||||
|
||||
public var pausePosition:Number;
|
||||
|
||||
public var seekPercent:Number;
|
||||
public var currentTime:Number;
|
||||
public var currentPercentRelative:Number;
|
||||
public var currentPercentAbsolute:Number;
|
||||
public var duration:Number;
|
||||
|
||||
public var videoWidth:Number;
|
||||
public var videoHeight:Number;
|
||||
|
||||
public var metaDataReady:Boolean;
|
||||
public var metaData:Object;
|
||||
|
||||
public function JplayerStatus() {
|
||||
reset();
|
||||
}
|
||||
public function reset():void {
|
||||
src = "";
|
||||
srcError = false;
|
||||
|
||||
srcSet = false;
|
||||
isPlaying = false;
|
||||
isSeeking = false;
|
||||
|
||||
isWaiting = false;
|
||||
|
||||
playOnLoad = false;
|
||||
playOnSeek = false;
|
||||
|
||||
isStartingDownload = false;
|
||||
isLoading = false;
|
||||
isLoaded = false;
|
||||
|
||||
pausePosition = 0;
|
||||
|
||||
seekPercent = 0;
|
||||
currentTime = 0;
|
||||
currentPercentRelative = 0;
|
||||
currentPercentAbsolute = 0;
|
||||
duration = 0;
|
||||
|
||||
videoWidth = 0;
|
||||
videoHeight = 0;
|
||||
|
||||
metaDataReady = false;
|
||||
metaData = {};
|
||||
}
|
||||
public function error():void {
|
||||
var srcSaved:String = src;
|
||||
reset();
|
||||
src = srcSaved;
|
||||
srcError = true;
|
||||
}
|
||||
public function loadRequired():Boolean {
|
||||
return (srcSet && !isStartingDownload && !isLoading && !isLoaded);
|
||||
}
|
||||
public function startingDownload():void {
|
||||
isStartingDownload = true;
|
||||
isLoading = false;
|
||||
isLoaded = false;
|
||||
}
|
||||
public function loading():void {
|
||||
isStartingDownload = false;
|
||||
isLoading = true;
|
||||
isLoaded = false;
|
||||
}
|
||||
public function loaded():void {
|
||||
isStartingDownload = false;
|
||||
isLoading = false;
|
||||
isLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* jPlayer Plugin for jQuery JavaScript Library
|
||||
* http://www.jplayer.org
|
||||
*
|
||||
* Copyright (c) 2009 - 2013 Happyworm Ltd
|
||||
* Licensed under the MIT license.
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Author: Robert M. Hall
|
||||
* Date: 7th August 2012
|
||||
*/
|
||||
|
||||
package happyworm.jPlayer
|
||||
{
|
||||
import flash.net.LocalConnection;
|
||||
import flash.events.StatusEvent;
|
||||
import flash.system.Capabilities;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
public class TraceOut
|
||||
{
|
||||
|
||||
private var outgoing_lc:LocalConnection = new LocalConnection ();
|
||||
private var firstEvent:Boolean = true;
|
||||
private var _localAIRDebug:Boolean = false;
|
||||
|
||||
public function TraceOut()
|
||||
{
|
||||
outgoing_lc.addEventListener(StatusEvent.STATUS, lcListener);
|
||||
outgoing_lc.send("_log_output","startLogging","");
|
||||
}
|
||||
|
||||
private function lcListener(event:StatusEvent):void
|
||||
{
|
||||
// Must have this listener to avoid errors
|
||||
if (event.level == "error")
|
||||
{
|
||||
_localAIRDebug = false;
|
||||
}
|
||||
else if(event.level =="status" && firstEvent==true)
|
||||
{
|
||||
firstEvent = false;
|
||||
tracer("<< Successful Connection To Event Logger >>");
|
||||
tracer("DEBUG INFO: \n<"+Capabilities.serverString + ">\nFlash Player Version: " + Capabilities.version + "\n");
|
||||
_localAIRDebug = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function localAIRDebug():Boolean
|
||||
{
|
||||
return _localAIRDebug;
|
||||
}
|
||||
|
||||
public function tracer(msg:String):void
|
||||
{
|
||||
trace(msg);
|
||||
var outMsg:String = "[" + getTimer() + "ms] " + msg;
|
||||
outgoing_lc.send("_log_output","displayMsg",outMsg);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user