Skip to content

Instantly share code, notes, and snippets.

@ZoczuS
Created January 6, 2015 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZoczuS/d2e02323502863e3db56 to your computer and use it in GitHub Desktop.
Save ZoczuS/d2e02323502863e3db56 to your computer and use it in GitHub Desktop.
package {
import flash.display.Sprite;
import com.videojs.VideoJSApp;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
public class VideoJS extends Sprite {
public
const VERSION: String = "4.5.0";
private
var _app: VideoJSApp;
private
var _stageSizeTimer: Timer;
public
function VideoJS() {
super();
_stageSizeTimer = new Timer(250);
_stageSizeTimer.addEventListener(TimerEvent.TIMER, onStageSizeTimerTick);
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
return;
}
private
function init(): void {
Security.allowDomain("*");
Security.allowInsecureDomain("*");
if (!loaderInfo.hasOwnProperty("uncaughtErrorEvents")) {
if (ExternalInterface.available) {
registerExternalMethods();
}
}
_app = new VideoJSApp();
addChild(_app);
_app.model.stageRect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
var REG_2: ContextMenuItem = new ContextMenuItem("VideoJS Flash Component v" + VERSION, false, false);
var REG_3: ContextMenuItem = new ContextMenuItem("Copyright © 2014 Brightcove, Inc.", false, false);
var REG_4: ContextMenu = new ContextMenu();
REG_4.hideBuiltInItems();
REG_4.customItems.push(REG_2, REG_3);
contextMenu = REG_4;
return;
}
private
function registerExternalMethods(): void {
ExternalInterface.addCallback("vjs_appendBuffer", onAppendBufferCalled);
ExternalInterface.addCallback("vjs_echo", onEchoCalled);
ExternalInterface.addCallback("vjs_endOfStream", onEndOfStreamCalled);
ExternalInterface.addCallback("vjs_abort", onAbortCalled);
ExternalInterface.addCallback("vjs_getProperty", onGetPropertyCalled);
ExternalInterface.addCallback("vjs_setProperty", onSetPropertyCalled);
ExternalInterface.addCallback("vjs_autoplay", onAutoplayCalled);
ExternalInterface.addCallback("vjs_src", onSrcCalled);
ExternalInterface.addCallback("vjs_load", onLoadCalled);
ExternalInterface.addCallback("vjs_play", onPlayCalled);
ExternalInterface.addCallback("vjs_pause", onPauseCalled);
ExternalInterface.addCallback("vjs_resume", onResumeCalled);
ExternalInterface.addCallback("vjs_stop", onStopCalled);
throw (REG_4);
setTimeout(finish, 50);
return;
}
private
function finish(): void {
if (loaderInfo.parameters.mode != undefined) {
_app.model.mode = loaderInfo.parameters.mode;
}
if (loaderInfo.parameters.eventProxyFunction != undefined) {
_app.model.jsEventProxyName = loaderInfo.parameters.eventProxyFunction;
}
if (loaderInfo.parameters.errorEventProxyFunction != undefined) {
_app.model.jsErrorEventProxyName = loaderInfo.parameters.errorEventProxyFunction;
}
if (loaderInfo.parameters.autoplay != undefined && loaderInfo.parameters.autoplay == "true") {
_app.model.autoplay = true;
}
if (loaderInfo.parameters.preload === "none") {
_app.model.preload = false;
}
if (loaderInfo.parameters.poster != undefined && !(loaderInfo.parameters.poster == "")) {
_app.model.poster = String(loaderInfo.parameters.poster);
}
if (loaderInfo.parameters.src != undefined && !(loaderInfo.parameters.src == "")) {
if (isExternalMSObjectURL(loaderInfo.parameters.src)) {
_app.model.srcFromFlashvars = null;
openExternalMSObject(loaderInfo.parameters.src);
} else {
_app.model.srcFromFlashvars = String(loaderInfo.parameters.src);
}
} else if (loaderInfo.parameters.rtmpConnection != undefined && !(loaderInfo.parameters.rtmpConnection == "")) {
_app.model.rtmpConnectionURL = loaderInfo.parameters.rtmpConnection;
}
if (loaderInfo.parameters.rtmpStream != undefined && !(loaderInfo.parameters.rtmpStream == "")) {
_app.model.rtmpStream = loaderInfo.parameters.rtmpStream;
}
if (loaderInfo.parameters.readyFunction != undefined) {
ExternalInterface.call(_app.model.cleanEIString(loaderInfo.parameters.readyFunction), ExternalInterface.objectID);
}
return;
}
private
function onAddedToStage(arg1: Event): void {
stage.addEventListener(MouseEvent.CLICK, onStageClick);
stage.addEventListener(Event.RESIZE, onStageResize);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
_stageSizeTimer.start();
return;
}
private
function onStageSizeTimerTick(arg1: TimerEvent): void {
if (stage.stageWidth > 0 && stage.stageHeight > 0) {
_stageSizeTimer.stop();
_stageSizeTimer.removeEventListener(TimerEvent.TIMER, onStageSizeTimerTick);
init();
}
return;
}
private
function onStageResize(arg1: Event): void {
if (_app != null) {
_app.model.stageRect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
_app.model.broadcastEvent(new VideoJSEvent(VideoJSEvent.STAGE_RESIZE, {}));
}
return;
}
private
function onAppendBufferCalled(arg1: String): void {
var REG_3: ByteArray = Base64.decode(arg1);
_app.model.appendBuffer(REG_3);
return;
}
private
function onEchoCalled(arg1: * ): * {
return arg1;
}
private
function onEndOfStreamCalled(): * {
_app.model.endOfStream();
return;
}
private
function onAbortCalled(): * {
_app.model.abort();
return;
}
private
function onGetPropertyCalled(arg1: String = ""): * {
switch (arg1) {
case "mode":
return _app.model.mode;
case "autoplay":
return _app.model.autoplay;
case "loop":
return _app.model.loop;
case "preload":
return _app.model.preload;
case "metadata":
return _app.model.metadata;
case "duration":
return _app.model.duration;
case "eventProxyFunction":
return _app.model.jsEventProxyName;
case "errorEventProxyFunction":
return _app.model.jsErrorEventProxyName;
case "currentSrc":
return _app.model.src;
case "currentTime":
return _app.model.time;
case "time":
return _app.model.time;
case "initialTime":
return 0;
case "defaultPlaybackRate":
return 1;
case "ended":
return _app.model.hasEnded;
case "volume":
return _app.model.volume;
case "muted":
return _app.model.muted;
case "paused":
return _app.model.paused;
case "seeking":
return _app.model.seeking;
case "networkState":
return _app.model.networkState;
case "readyState":
return _app.model.readyState;
case "buffered":
return _app.model.buffered;
case "bufferedBytesStart":
return 0;
case "bufferedBytesEnd":
return _app.model.bufferedBytesEnd;
case "bytesTotal":
return _app.model.bytesTotal;
case "videoWidth":
return _app.model.videoWidth;
case "videoHeight":
return _app.model.videoHeight;
case "rtmpConnection":
return _app.model.rtmpConnectionURL;
case "rtmpStream":
return _app.model.rtmpStream;
default:
break;
}
return null;
}
private
function onSetPropertyCalled(arg1: String = "", arg2: * ): void {
switch (arg1) {
case "duration":
_app.model.duration = Number(arg2);
break;
case "mode":
_app.model.mode = String(arg2);
break;
case "loop":
_app.model.loop = _app.model.humanToBoolean(arg2);
break;
case "background":
_app.model.backgroundColor = _app.model.hexToNumber(String(arg2));
_app.model.backgroundAlpha = 1;
break;
case "eventProxyFunction":
_app.model.jsEventProxyName = String(arg2);
break;
case "errorEventProxyFunction":
_app.model.jsErrorEventProxyName = String(arg2);
break;
case "autoplay":
_app.model.autoplay = _app.model.humanToBoolean(arg2);
case "preload":
_app.model.preload = _app.model.humanToBoolean(arg2);
break;
case "poster":
_app.model.poster = String(arg2);
break;
case "src":
onSrcCalled(arg2);
break;
case "currentTime":
_app.model.seekBySeconds(Number(arg2));
break;
case "currentPercent":
_app.model.seekByPercent(Number(arg2));
break;
case "muted":
_app.model.muted = _app.model.humanToBoolean(arg2);
break;
case "volume":
_app.model.volume = Number(arg2);
break;
case "rtmpConnection":
_app.model.rtmpConnectionURL = String(arg2);
break;
case "rtmpStream":
_app.model.rtmpStream = String(arg2);
break;
default:
_app.model.broadcastErrorEventExternally(ExternalErrorEventName.PROPERTY_NOT_FOUND, arg1);
break;
}
return;
}
private
function onAutoplayCalled(arg1: * = false): void {
_app.model.autoplay = _app.model.humanToBoolean(arg1);
return;
}
private
function isExternalMSObjectURL(arg1: * ): Boolean {
return arg1.indexOf("blob:vjs-media-source/") === 0;
}
private
function openExternalMSObject(arg1: * ): void {
var REG_3: String = null;
if (new RegExp("^blob:vjs-media-source\\/\\d+$").test(arg1)) {
REG_3 = arg1;
} else {
REG_3 = _app.model.cleanEIString(arg1);
}
ExternalInterface.call("videojs.MediaSource.open", REG_3, ExternalInterface.objectID);
return;
}
private
function onSrcCalled(arg1: * = ""): void {
if (isExternalMSObjectURL(arg1)) {
_app.model.src = null;
openExternalMSObject(arg1);
} else {
_app.model.src = String(arg1);
}
return;
}
private
function onLoadCalled(): void {
_app.model.load();
return;
}
private
function onPlayCalled(): void {
_app.model.play();
return;
}
private
function onPauseCalled(): void {
_app.model.pause();
return;
}
private
function onResumeCalled(): void {
_app.model.resume();
return;
}
private
function onStopCalled(): void {
_app.model.stop();
return;
}
private
function onUncaughtError(arg1: Event): void {
arg1.preventDefault();
return;
}
private
function onStageClick(arg1: MouseEvent): void {
_app.model.broadcastEventExternally(ExternalEventName.ON_STAGE_CLICK);
return;
}
}
}
package com.videojs.structs {
public class ExternalErrorEventName extends Object {
public static
const SRC_NOT_SET: String = "srcnotset";
public static
const SRC_404: String = "srcnotfound";
public static
const RTMP_CONNECT_FAILURE: String = "rtmpconnectfailure";
public static
const PROPERTY_NOT_FOUND: String = "propertynotfound";
public static
const POSTER_IO_ERROR: String = "posterioerror";
public static
const POSTER_SECURITY_ERROR: String = "postersecurityerror";
public static
const UNSUPPORTED_MODE: String = "unsupportedmode";
public
function ExternalErrorEventName() {
super();
return;
}
}
}
package com.videojs {
import flash.display.Sprite;
import com.videojs.VideoJSView;
import com.videojs.VideoJSModel;
public class VideoJSApp extends Sprite {
private
var _uiView: VideoJSView;
private
var _model: VideoJSModel;
public
function VideoJSApp() {
super();
_model = VideoJSModel.getInstance();
_uiView = new VideoJSView();
addChild(_uiView);
return;
}
public
function get model(): VideoJSModel {
return _model;
}
}
}
package com.videojs.events {
import flash.events.Event;
public class VideoJSEvent extends Event {
public static
const STAGE_RESIZE: String = "VideoJSEvent.STAGE_RESIZE";
public static
const BACKGROUND_COLOR_SET: String = "VideoJSEvent.BACKGROUND_COLOR_SET";
public static
const POSTER_SET: String = "VideoJSEvent.POSTER_SET";
private
var _data: Object;
public
function VideoJSEvent(arg1: String, arg2: Object) {
super(arg1, true, false);
_data = arg2;
return;
}
public
function get data(): Object {
return _data;
}
}
}
package com.videojs.structs {
public class ExternalEventName extends Object {
public static
const ON_SRC_CHANGE: String = "onsrcchange";
public static
const ON_LOAD_START: String = "loadstart";
public static
const ON_START: String = "playing";
public static
const ON_PAUSE: String = "pause";
public static
const ON_RESUME: String = "play";
public static
const ON_SEEK_START: String = "seeking";
public static
const ON_SEEK_COMPLETE: String = "seeked";
public static
const ON_BUFFER_FULL: String = "loadeddata";
public static
const ON_BUFFER_EMPTY: String = "waiting";
public static
const ON_BUFFER_FLUSH: String = "emptied";
public static
const ON_PLAYBACK_COMPLETE: String = "ended";
public static
const ON_METADATA: String = "loadedmetadata";
public static
const ON_DURATION_CHANGE: String = "durationchange";
public static
const ON_CAN_PLAY: String = "canplay";
public static
const ON_CAN_PLAY_THROUGH: String = "canplaythrough";
public static
const ON_VOLUME_CHANGE: String = "volumechange";
public static
const ON_RTMP_CONNECT_SUCCESS: String = "rtmpconnected";
public static
const ON_RTMP_RETRY: String = "rtmpretry";
public static
const ON_STAGE_CLICK: String = "stageclick";
public
function ExternalEventName() {
super();
return;
}
}
}
package com.videojs {
import flash.utils.ByteArray;
public class Base64 extends Object {
private static
const _decodeChars: Vector. < int > ;
final public static
function decode(arg1: String): ByteArray {
var REG_3: int = 0;
var REG_4: int = 0;
var REG_5: int = 0;
var REG_6: int = 0;
var REG_7: int = 0;
var REG_8: int = arg1.length;
var REG_9: ByteArray = new ByteArray();
REG_9.writeUTFBytes(arg1);
var REG_10: int = 0;
while (REG_7 < REG_8) {
REG_7 = REG_7 + 1;
REG_3 = _decodeChars[int(REG_9[REG_7])];
if (REG_3 == -1) {
break;
} else {
REG_7 = REG_7 + 1;
REG_4 = _decodeChars[int(REG_9[REG_7])];
if (REG_4 == -1) {
break;
} else {
REG_10 = REG_10 + 1;
REG_9[int(REG_10)] = REG_3 << 2 | (REG_4 & 48) >> 4;
REG_7 = REG_7 + 1;
REG_5 = REG_9[int(REG_7)];
if (REG_5 == 61) {
REG_9.length = REG_10;
return REG_9;
}
}
}
REG_5 = _decodeChars[int(REG_5)];
if (REG_5 == -1) {
break;
} else {
REG_10 = REG_10 + 1;
REG_9[int(REG_10)] = (REG_4 & 15) << 4 | (REG_5 & 60) >> 2;
REG_7 = REG_7 + 1;
REG_6 = REG_9[int(REG_7)];
if (REG_6 == 61) {
REG_9.length = REG_10;
return REG_9;
}
}
REG_6 = _decodeChars[int(REG_6)];
if (REG_6 == -1) {
break;
} else {
REG_10 = REG_10 + 1;
REG_9[int(REG_10)] = (REG_5 & 3) << 6 | REG_6;
}
}
REG_9.length = REG_10;
return REG_9;
}
final public static
function InitDecodeChar(): Vector. < int > {
new Vector. < int > (256)[0] = -1;
new Vector. < int > (256)[1] = -1;
new Vector. < int > (256)[2] = -1;
new Vector. < int > (256)[3] = -1;
new Vector. < int > (256)[4] = -1;
new Vector. < int > (256)[5] = -1;
new Vector. < int > (256)[6] = -1;
new Vector. < int > (256)[7] = -1;
new Vector. < int > (256)[8] = -1;
new Vector. < int > (256)[9] = -1;
new Vector. < int > (256)[10] = -1;
new Vector. < int > (256)[11] = -1;
new Vector. < int > (256)[12] = -1;
new Vector. < int > (256)[13] = -1;
new Vector. < int > (256)[14] = -1;
new Vector. < int > (256)[15] = -1;
new Vector. < int > (256)[16] = -1;
new Vector. < int > (256)[17] = -1;
new Vector. < int > (256)[18] = -1;
new Vector. < int > (256)[19] = -1;
new Vector. < int > (256)[20] = -1;
new Vector. < int > (256)[21] = -1;
new Vector. < int > (256)[22] = -1;
new Vector. < int > (256)[23] = -1;
new Vector. < int > (256)[24] = -1;
new Vector. < int > (256)[25] = -1;
new Vector. < int > (256)[26] = -1;
new Vector. < int > (256)[27] = -1;
new Vector. < int > (256)[28] = -1;
new Vector. < int > (256)[29] = -1;
new Vector. < int > (256)[30] = -1;
new Vector. < int > (256)[31] = -1;
new Vector. < int > (256)[32] = -1;
new Vector. < int > (256)[33] = -1;
new Vector. < int > (256)[34] = -1;
new Vector. < int > (256)[35] = -1;
new Vector. < int > (256)[36] = -1;
new Vector. < int > (256)[37] = -1;
new Vector. < int > (256)[38] = -1;
new Vector. < int > (256)[39] = -1;
new Vector. < int > (256)[40] = -1;
new Vector. < int > (256)[41] = -1;
new Vector. < int > (256)[42] = -1;
new Vector. < int > (256)[43] = 62;
new Vector. < int > (256)[44] = -1;
new Vector. < int > (256)[45] = -1;
new Vector. < int > (256)[46] = -1;
new Vector. < int > (256)[47] = 63;
new Vector. < int > (256)[48] = 52;
new Vector. < int > (256)[49] = 53;
new Vector. < int > (256)[50] = 54;
new Vector. < int > (256)[51] = 55;
new Vector. < int > (256)[52] = 56;
new Vector. < int > (256)[53] = 57;
new Vector. < int > (256)[54] = 58;
new Vector. < int > (256)[55] = 59;
new Vector. < int > (256)[56] = 60;
new Vector. < int > (256)[57] = 61;
new Vector. < int > (256)[58] = -1;
new Vector. < int > (256)[59] = -1;
new Vector. < int > (256)[60] = -1;
new Vector. < int > (256)[61] = -1;
new Vector. < int > (256)[62] = -1;
new Vector. < int > (256)[63] = -1;
new Vector. < int > (256)[64] = -1;
new Vector. < int > (256)[65] = 0;
new Vector. < int > (256)[66] = 1;
new Vector. < int > (256)[67] = 2;
new Vector. < int > (256)[68] = 3;
new Vector. < int > (256)[69] = 4;
new Vector. < int > (256)[70] = 5;
new Vector. < int > (256)[71] = 6;
new Vector. < int > (256)[72] = 7;
new Vector. < int > (256)[73] = 8;
new Vector. < int > (256)[74] = 9;
new Vector. < int > (256)[75] = 10;
new Vector. < int > (256)[76] = 11;
new Vector. < int > (256)[77] = 12;
new Vector. < int > (256)[78] = 13;
new Vector. < int > (256)[79] = 14;
new Vector. < int > (256)[80] = 15;
new Vector. < int > (256)[81] = 16;
new Vector. < int > (256)[82] = 17;
new Vector. < int > (256)[83] = 18;
new Vector. < int > (256)[84] = 19;
new Vector. < int > (256)[85] = 20;
new Vector. < int > (256)[86] = 21;
new Vector. < int > (256)[87] = 22;
new Vector. < int > (256)[88] = 23;
new Vector. < int > (256)[89] = 24;
new Vector. < int > (256)[90] = 25;
new Vector. < int > (256)[91] = -1;
new Vector. < int > (256)[92] = -1;
new Vector. < int > (256)[93] = -1;
new Vector. < int > (256)[94] = -1;
new Vector. < int > (256)[95] = -1;
new Vector. < int > (256)[96] = -1;
new Vector. < int > (256)[97] = 26;
new Vector. < int > (256)[98] = 27;
new Vector. < int > (256)[99] = 28;
new Vector. < int > (256)[100] = 29;
new Vector. < int > (256)[101] = 30;
new Vector. < int > (256)[102] = 31;
new Vector. < int > (256)[103] = 32;
new Vector. < int > (256)[104] = 33;
new Vector. < int > (256)[105] = 34;
new Vector. < int > (256)[106] = 35;
new Vector. < int > (256)[107] = 36;
new Vector. < int > (256)[108] = 37;
new Vector. < int > (256)[109] = 38;
new Vector. < int > (256)[110] = 39;
new Vector. < int > (256)[111] = 40;
new Vector. < int > (256)[112] = 41;
new Vector. < int > (256)[113] = 42;
new Vector. < int > (256)[114] = 43;
new Vector. < int > (256)[115] = 44;
new Vector. < int > (256)[116] = 45;
new Vector. < int > (256)[117] = 46;
new Vector. < int > (256)[118] = 47;
new Vector. < int > (256)[119] = 48;
new Vector. < int > (256)[120] = 49;
new Vector. < int > (256)[121] = 50;
new Vector. < int > (256)[122] = 51;
new Vector. < int > (256)[123] = -1;
new Vector. < int > (256)[124] = -1;
new Vector. < int > (256)[125] = -1;
new Vector. < int > (256)[126] = -1;
new Vector. < int > (256)[127] = -1;
new Vector. < int > (256)[128] = -1;
new Vector. < int > (256)[129] = -1;
new Vector. < int > (256)[130] = -1;
new Vector. < int > (256)[131] = -1;
new Vector. < int > (256)[132] = -1;
new Vector. < int > (256)[133] = -1;
new Vector. < int > (256)[134] = -1;
new Vector. < int > (256)[135] = -1;
new Vector. < int > (256)[136] = -1;
new Vector. < int > (256)[137] = -1;
new Vector. < int > (256)[138] = -1;
new Vector. < int > (256)[139] = -1;
new Vector. < int > (256)[140] = -1;
new Vector. < int > (256)[141] = -1;
new Vector. < int > (256)[142] = -1;
new Vector. < int > (256)[143] = -1;
new Vector. < int > (256)[144] = -1;
new Vector. < int > (256)[145] = -1;
new Vector. < int > (256)[146] = -1;
new Vector. < int > (256)[147] = -1;
new Vector. < int > (256)[148] = -1;
new Vector. < int > (256)[149] = -1;
new Vector. < int > (256)[150] = -1;
new Vector. < int > (256)[151] = -1;
new Vector. < int > (256)[152] = -1;
new Vector. < int > (256)[153] = -1;
new Vector. < int > (256)[154] = -1;
new Vector. < int > (256)[155] = -1;
new Vector. < int > (256)[156] = -1;
new Vector. < int > (256)[157] = -1;
new Vector. < int > (256)[158] = -1;
new Vector. < int > (256)[159] = -1;
new Vector. < int > (256)[160] = -1;
new Vector. < int > (256)[161] = -1;
new Vector. < int > (256)[162] = -1;
new Vector. < int > (256)[163] = -1;
new Vector. < int > (256)[164] = -1;
new Vector. < int > (256)[165] = -1;
new Vector. < int > (256)[166] = -1;
new Vector. < int > (256)[167] = -1;
new Vector. < int > (256)[168] = -1;
new Vector. < int > (256)[169] = -1;
new Vector. < int > (256)[170] = -1;
new Vector. < int > (256)[171] = -1;
new Vector. < int > (256)[172] = -1;
new Vector. < int > (256)[173] = -1;
new Vector. < int > (256)[174] = -1;
new Vector. < int > (256)[175] = -1;
new Vector. < int > (256)[176] = -1;
new Vector. < int > (256)[177] = -1;
new Vector. < int > (256)[178] = -1;
new Vector. < int > (256)[179] = -1;
new Vector. < int > (256)[180] = -1;
new Vector. < int > (256)[181] = -1;
new Vector. < int > (256)[182] = -1;
new Vector. < int > (256)[183] = -1;
new Vector. < int > (256)[184] = -1;
new Vector. < int > (256)[185] = -1;
new Vector. < int > (256)[186] = -1;
new Vector. < int > (256)[187] = -1;
new Vector. < int > (256)[188] = -1;
new Vector. < int > (256)[189] = -1;
new Vector. < int > (256)[190] = -1;
new Vector. < int > (256)[191] = -1;
new Vector. < int > (256)[192] = -1;
new Vector. < int > (256)[193] = -1;
new Vector. < int > (256)[194] = -1;
new Vector. < int > (256)[195] = -1;
new Vector. < int > (256)[196] = -1;
new Vector. < int > (256)[197] = -1;
new Vector. < int > (256)[198] = -1;
new Vector. < int > (256)[199] = -1;
new Vector. < int > (256)[200] = -1;
new Vector. < int > (256)[201] = -1;
new Vector. < int > (256)[202] = -1;
new Vector. < int > (256)[203] = -1;
new Vector. < int > (256)[204] = -1;
new Vector. < int > (256)[205] = -1;
new Vector. < int > (256)[206] = -1;
new Vector. < int > (256)[207] = -1;
new Vector. < int > (256)[208] = -1;
new Vector. < int > (256)[209] = -1;
new Vector. < int > (256)[210] = -1;
new Vector. < int > (256)[211] = -1;
new Vector. < int > (256)[212] = -1;
new Vector. < int > (256)[213] = -1;
new Vector. < int > (256)[214] = -1;
new Vector. < int > (256)[215] = -1;
new Vector. < int > (256)[216] = -1;
new Vector. < int > (256)[217] = -1;
new Vector. < int > (256)[218] = -1;
new Vector. < int > (256)[219] = -1;
new Vector. < int > (256)[220] = -1;
new Vector. < int > (256)[221] = -1;
new Vector. < int > (256)[222] = -1;
new Vector. < int > (256)[223] = -1;
new Vector. < int > (256)[224] = -1;
new Vector. < int > (256)[225] = -1;
new Vector. < int > (256)[226] = -1;
new Vector. < int > (256)[227] = -1;
new Vector. < int > (256)[228] = -1;
new Vector. < int > (256)[229] = -1;
new Vector. < int > (256)[230] = -1;
new Vector. < int > (256)[231] = -1;
new Vector. < int > (256)[232] = -1;
new Vector. < int > (256)[233] = -1;
new Vector. < int > (256)[234] = -1;
new Vector. < int > (256)[235] = -1;
new Vector. < int > (256)[236] = -1;
new Vector. < int > (256)[237] = -1;
new Vector. < int > (256)[238] = -1;
new Vector. < int > (256)[239] = -1;
new Vector. < int > (256)[240] = -1;
new Vector. < int > (256)[241] = -1;
new Vector. < int > (256)[242] = -1;
new Vector. < int > (256)[243] = -1;
new Vector. < int > (256)[244] = -1;
new Vector. < int > (256)[245] = -1;
new Vector. < int > (256)[246] = -1;
new Vector. < int > (256)[247] = -1;
new Vector. < int > (256)[248] = -1;
new Vector. < int > (256)[249] = -1;
new Vector. < int > (256)[250] = -1;
new Vector. < int > (256)[251] = -1;
new Vector. < int > (256)[252] = -1;
new Vector. < int > (256)[253] = -1;
new Vector. < int > (256)[254] = -1;
new Vector. < int > (256)[255] = -1;
var REG_2: Vector. < int > = new Vector. < int > (256);
return REG_2;
}
public
function Base64() {
super();
return;
}
}
}
package com.videojs {
import flash.display.Sprite;
import flash.media.Video;
import flash.display.Loader;
import com.videojs.VideoJSModel;
import com.videojs.events.VideoPlaybackEvent;
import com.videojs.events.VideoJSEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
public class VideoJSView extends Sprite {
private
var _uiVideo: Video;
private
var _uiPosterContainer: Sprite;
private
var _uiPosterImage: Loader;
private
var _uiBackground: Sprite;
private
var _model: VideoJSModel;
public
function VideoJSView() {
super();
_model = VideoJSModel.getInstance();
_model.addEventListener(VideoJSEvent.POSTER_SET, onPosterSet);
_model.addEventListener(VideoJSEvent.BACKGROUND_COLOR_SET, onBackgroundColorSet);
_model.addEventListener(VideoJSEvent.STAGE_RESIZE, onStageResize);
_model.addEventListener(VideoPlaybackEvent.ON_STREAM_START, onStreamStart);
_model.addEventListener(VideoPlaybackEvent.ON_META_DATA, onMetaData);
_model.addEventListener(VideoPlaybackEvent.ON_VIDEO_DIMENSION_UPDATE, onDimensionUpdate);
_uiBackground = new Sprite();
_uiBackground.graphics.beginFill(_model.backgroundColor, 1);
_uiBackground.graphics.drawRect(0, 0, _model.stageRect.width, _model.stageRect.height);
_uiBackground.graphics.endFill();
_uiBackground.alpha = _model.backgroundAlpha;
addChild(_uiBackground);
_uiPosterContainer = new Sprite();
_uiPosterImage = new Loader();
_uiPosterImage.visible = false;
_uiPosterContainer.addChild(_uiPosterImage);
addChild(_uiPosterContainer);
_uiVideo = new Video();
_uiVideo.width = _model.stageRect.width;
_uiVideo.height = _model.stageRect.height;
_uiVideo.smoothing = true;
addChild(_uiVideo);
_model.videoReference = _uiVideo;
return;
}
private
function loadPoster(): void {
var REG_2: URLRequest = null;
var REG_3: LoaderContext = null;
if (_model.poster != "") {
if (_uiPosterImage != null) {
_uiPosterImage.contentLoaderInfo.removeEventListener(Event.COMPLETE, onPosterLoadComplete);
_uiPosterImage.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onPosterLoadError);
_uiPosterImage.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onPosterLoadSecurityError);
_uiPosterImage.parent.removeChild(_uiPosterImage);
_uiPosterImage = null;
}
}
REG_2 = new URLRequest(_model.poster);
_uiPosterImage = new Loader();
_uiPosterImage.visible = false;
REG_3 = new LoaderContext();
_uiPosterImage.contentLoaderInfo.addEventListener(Event.COMPLETE, onPosterLoadComplete);
_uiPosterImage.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onPosterLoadError);
_uiPosterImage.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onPosterLoadSecurityError);
_uiPosterImage.load(REG_2, REG_3);
return;
}
private
function sizeVideoObject(): void {
var REG_2: int = 0;
var REG_3: int = 0;
var REG_4: int = _model.stageRect.width;
var REG_5: int = _model.stageRect.height;
var REG_6: int = 100;
if (_model.metadata.width != undefined) {
REG_6 = Number(_model.metadata.width);
}
if (_uiVideo.videoWidth != 0) {
REG_6 = _uiVideo.videoWidth;
}
var REG_7: int = 100;
if (_model.metadata.width != undefined) {
REG_7 = Number(_model.metadata.height);
}
if (_uiVideo.videoWidth != 0) {
REG_7 = _uiVideo.videoHeight;
}
REG_2 = REG_4;
REG_3 = REG_2 * REG_7 / REG_6;
if (REG_3 > REG_5) {
REG_2 = REG_2 * REG_5 / REG_3;
REG_3 = REG_5;
}
_uiVideo.width = REG_2;
_uiVideo.height = REG_3;
_uiVideo.x = Math.round((_model.stageRect.width - _uiVideo.width) / 2);
_uiVideo.y = Math.round((_model.stageRect.height - _uiVideo.height) / 2);
return;
}
private
function sizePoster(): void {
var REG_2: int = 0;
var REG_3: int = 0;
var REG_4: int = 0;
var REG_5: int = 0;
var REG_6: int = 0;
var REG_7: int = 0;
if (_uiPosterImage.content != null) {
REG_4 = _model.stageRect.width;
REG_5 = _model.stageRect.height;
REG_6 = _uiPosterImage.content.width;
REG_7 = _uiPosterImage.content.height;
REG_2 = REG_4;
REG_3 = REG_2 * REG_7 / REG_6;
if (REG_3 > REG_5) {
REG_2 = REG_2 * REG_5 / REG_3;
REG_3 = REG_5;
}
}
_uiPosterImage.width = REG_2;
_uiPosterImage.height = REG_3;
_uiPosterImage.x = Math.round((_model.stageRect.width - _uiPosterImage.width) / 2);
_uiPosterImage.y = Math.round((_model.stageRect.height - _uiPosterImage.height) / 2);
return;
}
private
function onBackgroundColorSet(arg1: VideoPlaybackEvent): void {
_uiBackground.graphics.clear();
_uiBackground.graphics.beginFill(_model.backgroundColor, 1);
_uiBackground.graphics.drawRect(0, 0, _model.stageRect.width, _model.stageRect.height);
_uiBackground.graphics.endFill();
return;
}
private
function onStageResize(arg1: VideoJSEvent): void {
_uiBackground.graphics.clear();
_uiBackground.graphics.beginFill(_model.backgroundColor, 1);
_uiBackground.graphics.drawRect(0, 0, _model.stageRect.width, _model.stageRect.height);
_uiBackground.graphics.endFill();
sizePoster();
sizeVideoObject();
return;
}
private
function onPosterSet(arg1: VideoJSEvent): void {
loadPoster();
return;
}
private
function onPosterLoadComplete(arg1: Event): void {
var SLOT1: Event = arg1;
(_uiPosterImage.content as Bitmap).smoothing = true;
_uiPosterContainer.addChild(_uiPosterImage);
sizePoster();
if (!_model.playing) {
_uiPosterImage.visible = true;
}
return;
}
private
function onPosterLoadError(arg1: IOErrorEvent): void {
_model.broadcastErrorEventExternally(ExternalErrorEventName.POSTER_IO_ERROR, arg1.text);
return;
}
private
function onPosterLoadSecurityError(arg1: SecurityErrorEvent): void {
_model.broadcastErrorEventExternally(ExternalErrorEventName.POSTER_SECURITY_ERROR, arg1.text);
return;
}
private
function onStreamStart(arg1: VideoPlaybackEvent): void {
_uiPosterImage.visible = false;
return;
}
private
function onMetaData(arg1: VideoPlaybackEvent): void {
sizeVideoObject();
return;
}
private
function onDimensionUpdate(arg1: VideoPlaybackEvent): void {
sizeVideoObject();
return;
}
}
}
package com.videojs {
import flash.events.EventDispatcher;
import com.videojs.VideoJSModel;
import flash.media.SoundTransform;
import flash.media.Video;
import com.videojs.providers.IProvider;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import flash.events.Event;
public class VideoJSModel extends EventDispatcher {
private static
var _instance: VideoJSModel;
final public static
function getInstance(): VideoJSModel {
if (_instance === null) {
_instance = new this(new SingletonLock());
}
return _instance;
}
private
var _masterVolume: SoundTransform;
private
var _currentPlaybackType: String;
private
var _videoReference: Video;
private
var _lastSetVolume: Number = 1;
private
var _provider: IProvider;
private
var _mode: String;
private
var _stageRect: Rectangle;
private
var _jsEventProxyName: String = "";
private
var _jsErrorEventProxyName: String = "";
private
var _backgroundColor: Number = 0;
private
var _backgroundAlpha: Number = 0;
private
var _volume: Number = 1;
private
var _autoplay: Boolean = false;
private
var _preload: Boolean = true;
private
var _loop: Boolean = false;
private
var _src: String = "";
private
var _rtmpConnectionURL: String = "";
private
var _rtmpStream: String = "";
private
var _poster: String = "";
public
function VideoJSModel(arg1: SingletonLock) {
super();
if (!arg1 is SingletonLock) {
throw (new Error("Invalid Singleton access. Use VideoJSModel.getInstance()!"));
}
_mode = PlayerMode.VIDEO;
_currentPlaybackType = PlaybackType.HTTP;
_masterVolume = new SoundTransform();
_stageRect = new Rectangle(0, 0, 100, 100);
return;
}
public
function get mode(): String {
return _mode;
}
public
function set mode(arg1: String): void {
switch (arg1) {
case PlayerMode.VIDEO:
_mode = arg1;
break;
case PlayerMode.AUDIO:
_mode = arg1;
break;
default:
broadcastEventExternally(ExternalErrorEventName.UNSUPPORTED_MODE);
break;
}
return;
}
public
function get jsEventProxyName(): String {
return _jsEventProxyName;
}
public
function set jsEventProxyName(arg1: String): void {
_jsEventProxyName = cleanEIString(arg1);
return;
}
public
function get jsErrorEventProxyName(): String {
return _jsErrorEventProxyName;
}
public
function set jsErrorEventProxyName(arg1: String): void {
_jsErrorEventProxyName = cleanEIString(arg1);
return;
}
public
function get stageRect(): Rectangle {
return _stageRect;
}
public
function set stageRect(arg1: Rectangle): void {
_stageRect = arg1;
return;
}
public
function appendBuffer(arg1: ByteArray): void {
_provider.appendBuffer(arg1);
return;
}
public
function endOfStream(): void {
_provider.endOfStream();
return;
}
public
function abort(): void {
_provider.abort();
return;
}
public
function get backgroundColor(): Number {
return _backgroundColor;
}
public
function set backgroundColor(arg1: Number): void {
if (arg1 < 0) {
_backgroundColor = 0;
} else {
_backgroundColor = arg1;
broadcastEvent(new VideoPlaybackEvent(VideoJSEvent.BACKGROUND_COLOR_SET, {}));
}
return;
}
public
function get backgroundAlpha(): Number {
return _backgroundAlpha;
}
public
function set backgroundAlpha(arg1: Number): void {
if (arg1 < 0) {
_backgroundAlpha = 0;
} else {
_backgroundAlpha = arg1;
}
return;
}
public
function get videoReference(): Video {
return _videoReference;
}
public
function set videoReference(arg1: Video): void {
_videoReference = arg1;
return;
}
public
function get metadata(): Object {
if (_provider) {
return _provider.metadata;
}
return {};
}
public
function get volume(): Number {
return _volume;
}
public
function set volume(arg1: Number): void {
if (arg1 >= 0 && arg1 <= 1) {
_volume = arg1;
} else {
_volume = 1;
}
_masterVolume.volume = _volume;
SoundMixer.soundTransform = _masterVolume;
_lastSetVolume = _volume;
broadcastEventExternally(ExternalEventName.ON_VOLUME_CHANGE, _volume);
return;
}
public
function get duration(): Number {
if (_provider) {
return _provider.duration;
}
return 0;
}
public
function set duration(arg1: Number): void {
if (_provider && _provider is HTTPVideoProvider) {
(_provider as HTTPVideoProvider).duration = arg1;
}
return;
}
public
function get autoplay(): Boolean {
return _autoplay;
}
public
function set autoplay(arg1: Boolean): void {
_autoplay = arg1;
return;
}
public
function get src(): String {
if (_provider) {
return _provider.srcAsString;
}
return _src;
}
public
function set src(arg1: String): void {
_src = arg1;
_rtmpConnectionURL = "";
_rtmpStream = "";
_currentPlaybackType = PlaybackType.HTTP;
broadcastEventExternally(ExternalEventName.ON_SRC_CHANGE, _src);
initProvider();
if (_autoplay) {
_provider.play();
} else if (_preload) {
_provider.load();
}
return;
}
public
function get rtmpConnectionURL(): String {
return _rtmpConnectionURL;
}
public
function set rtmpConnectionURL(arg1: String): void {
_src = "";
_rtmpConnectionURL = arg1;
return;
}
public
function get rtmpStream(): String {
return _rtmpStream;
}
public
function set rtmpStream(arg1: String): void {
var REG_3: Object = null;
_src = "";
_rtmpStream = arg1;
broadcastEventExternally(ExternalEventName.ON_SRC_CHANGE, _src);
if (_provider != null && _currentPlaybackType == PlaybackType.RTMP) {
REG_3 = {
"connectionURL": _rtmpConnectionURL,
"streamURL": _rtmpStream
};
_provider.src = REG_3;
} else {
_currentPlaybackType = PlaybackType.RTMP;
initProvider();
}
if (_autoplay) {
play();
}
return;
}
public
function set srcFromFlashvars(arg1: String): void {
_src = arg1;
_currentPlaybackType = PlaybackType.HTTP;
initProvider();
if (_autoplay) {
_provider.play();
} else if (_preload) {
_provider.load();
}
return;
}
public
function get poster(): String {
return _poster;
}
public
function set poster(arg1: String): void {
_poster = arg1;
broadcastEvent(new VideoJSEvent(VideoJSEvent.POSTER_SET));
return;
}
public
function get hasEnded(): Boolean {
if (_provider) {
return _provider.ended;
}
return false;
}
public
function get time(): Number {
if (_provider) {
return _provider.time;
}
return 0;
}
public
function get muted(): Boolean {
return _volume == 0;
}
public
function set muted(arg1: Boolean): void {
var REG_3: Number = NaN;
if (arg1) {
REG_3 = _lastSetVolume;
volume = 0;
_lastSetVolume = REG_3;
} else {
volume = _lastSetVolume;
}
return;
}
public
function get seeking(): Boolean {
if (_provider) {
return _provider.seeking;
}
return false;
}
public
function get networkState(): int {
if (_provider) {
return _provider.networkState;
}
return 0;
}
public
function get readyState(): int {
if (_provider) {
return _provider.readyState;
}
return 0;
}
public
function get preload(): Boolean {
return _preload;
}
public
function set preload(arg1: Boolean): void {
_preload = arg1;
return;
}
public
function get loop(): Boolean {
return _loop;
}
public
function set loop(arg1: Boolean): void {
_loop = arg1;
return;
}
public
function get buffered(): Number {
if (_provider) {
return _provider.buffered;
}
return 0;
}
public
function get bufferedBytesEnd(): int {
if (_provider) {
return _provider.bufferedBytesEnd;
}
return 0;
}
public
function get bytesTotal(): int {
if (_provider) {
return _provider.bytesTotal;
}
return 0;
}
public
function get videoWidth(): int {
if (_videoReference != null) {
return _videoReference.videoWidth;
}
return 0;
}
public
function get videoHeight(): int {
if (_videoReference != null) {
return _videoReference.videoHeight;
}
return 0;
}
public
function get playing(): Boolean {
if (_provider) {
return _provider.playing;
}
return false;
}
public
function get paused(): Boolean {
if (_provider) {
return _provider.paused;
}
return false;
}
public
function broadcastEvent(arg1: Event): void {
dispatchEvent(arg1);
return;
}
public
function broadcastEventExternally(): void {
var REG_3: * = undefined;
var REG_4: Array = null;
if (_jsEventProxyName != "") {
if (ExternalInterface.available) {
REG_3 = REG_2 as Array;
REG_4 = [_jsEventProxyName, ExternalInterface.objectID].concat(REG_3);
ExternalInterface.call.apply(null, REG_4);
}
}
return;
}
public
function broadcastErrorEventExternally(): void {
var REG_3: * = undefined;
var REG_4: Array = null;
if (_jsErrorEventProxyName != "") {
if (ExternalInterface.available) {
REG_3 = REG_2 as Array;
REG_4 = [_jsErrorEventProxyName, ExternalInterface.objectID].concat(REG_3);
ExternalInterface.call.apply(null, REG_4);
}
}
return;
}
public
function load(): void {
if (_provider) {
_provider.load();
}
return;
}
public
function play(): void {
if (_provider) {
_provider.play();
}
return;
}
public
function pause(): void {
if (_provider) {
_provider.pause();
}
return;
}
public
function resume(): void {
if (_provider) {
_provider.resume();
}
return;
}
public
function seekBySeconds(arg1: Number): void {
if (_provider) {
_provider.seekBySeconds(arg1);
}
return;
}
public
function seekByPercent(arg1: Number): void {
if (_provider) {
_provider.seekByPercent(arg1);
}
return;
}
public
function stop(): void {
if (_provider) {
_provider.stop();
}
return;
}
public
function hexToNumber(arg1: String): Number {
var REG_3: Number = 0;
if (arg1.indexOf("#") != -1) {
arg1 = arg1.slice(arg1.indexOf("#") + 1);
}
if (arg1.length == 6) {
REG_3 = Number("0x" + arg1);
}
return REG_3;
}
public
function humanToBoolean(arg1: * ): Boolean {
if (String(arg1) == "true" || String(arg1) == "1") {
return true;
}
return false;
}
public
function cleanEIString(arg1: String): String {
return arg1.replace(new RegExp("[^A-Za-z0-9_.]", "gi"), "");
}
private
function initProvider(): void {
var REG_2: Object = null;
if (_provider) {
_provider.die();
_provider = null;
}
switch (_mode) {
case PlayerMode.VIDEO:
if (_currentPlaybackType == PlaybackType.HTTP) {
REG_2 = {
"path": _src
};
_provider = new HTTPVideoProvider();
_provider.attachVideo(_videoReference);
_provider.init(REG_2, _autoplay);
} else if (_currentPlaybackType == PlaybackType.RTMP) {
REG_2 = {
"connectionURL": _rtmpConnectionURL,
"streamURL": _rtmpStream
};
_provider = new RTMPVideoProvider();
_provider.attachVideo(_videoReference);
_provider.init(REG_2, _autoplay);
}
break;
case PlayerMode.AUDIO:
REG_2 = {
"path": _src
};
_provider = new HTTPAudioProvider();
_provider.init(REG_2, _autoplay);
break;
default:
broadcastEventExternally(ExternalErrorEventName.UNSUPPORTED_MODE);
break;
}
return;
}
}
}
private class SingletonLock extends Object {
public
function SingletonLock() {
super();
return;
}
}
package com.videojs.events {
import flash.events.Event;
public class VideoPlaybackEvent extends Event {
public static
const ON_CUE_POINT: String = "VideoPlaybackEvent.ON_CUE_POINT";
public static
const ON_META_DATA: String = "VideoPlaybackEvent.ON_META_DATA";
public static
const ON_XMP_DATA: String = "VideoPlaybackEvent.ON_XMP_DATA";
public static
const ON_NETSTREAM_STATUS: String = "VideoPlaybackEvent.ON_NETSTREAM_STATUS";
public static
const ON_NETCONNECTION_STATUS: String = "VideoPlaybackEvent.ON_NETCONNECTION_STATUS";
public static
const ON_STREAM_READY: String = "VideoPlaybackEvent.ON_STREAM_READY";
public static
const ON_STREAM_NOT_READY: String = "VideoPlaybackEvent.ON_STREAM_NOT_READY";
public static
const ON_STREAM_START: String = "VideoPlaybackEvent.ON_STREAM_START";
public static
const ON_STREAM_CLOSE: String = "VideoPlaybackEvent.ON_STREAM_CLOSE";
public static
const ON_STREAM_METRICS_UPDATE: String = "VideoPlaybackEvent.ON_STREAM_METRICS_UPDATE";
public static
const ON_STREAM_PAUSE: String = "VideoPlaybackEvent.ON_STREAM_PAUSE";
public static
const ON_STREAM_RESUME: String = "VideoPlaybackEvent.ON_STREAM_RESUME";
public static
const ON_STREAM_SEEK_COMPLETE: String = "VideoPlaybackEvent.ON_STREAM_SEEK_COMPLETE";
public static
const ON_STREAM_REBUFFER_START: String = "VideoPlaybackEvent.ON_STREAM_REBUFFER_START";
public static
const ON_STREAM_REBUFFER_END: String = "VideoPlaybackEvent.ON_STREAM_REBUFFER_END";
public static
const ON_ERROR: String = "VideoPlaybackEvent.ON_ERROR";
public static
const ON_UPDATE: String = "VideoPlaybackEvent.ON_UPDATE";
public static
const ON_VIDEO_DIMENSION_UPDATE: String = "VideoPlaybackEvent.ON_VIDEO_DIMENSION_UPDATE";
private
var _data: Object;
public
function VideoPlaybackEvent(arg1: String, arg2: Object) {
super(arg1, true, false);
_data = arg2;
return;
}
public
function get data(): Object {
return _data;
}
}
}
package com.videojs.providers {
import flash.utils.ByteArray;
import flash.media.Video;
public interface IProvider {
public
function IProvider();
function get loop(): Boolean;
function set loop(arg1: Boolean): void;
function get time(): Number;
function get duration(): Number;
function appendBuffer(arg1: ByteArray): void;
function endOfStream(): void;
function abort(): void;
function get readyState(): int;
function get networkState(): int;
function get buffered(): Number;
function get bufferedBytesEnd(): int;
function get bytesLoaded(): int;
function get bytesTotal(): int;
function get playing(): Boolean;
function get paused(): Boolean;
function get ended(): Boolean;
function get seeking(): Boolean;
function get usesNetStream(): Boolean;
function get metadata(): Object;
function get srcAsString(): String;
function set src(arg1: Object): void;
function init(arg1: Object, arg2: Boolean): void;
function load(): void;
function play(): void;
function pause(): void;
function resume(): void;
function seekBySeconds(arg1: Number): void;
function seekByPercent(arg1: Number): void;
function stop(): void;
function attachVideo(arg1: Video): void;
function die(): void;
}
}
package com.videojs.providers {
import flash.events.EventDispatcher;
import com.videojs.providers.IProvider;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.utils.Timer;
import flash.media.Video;
import com.videojs.VideoJSModel;
import flash.utils.ByteArray;
import flash.events.NetStatusEvent;
import flash.events.TimerEvent;
public class HTTPVideoProvider extends EventDispatcher implements IProvider {
private
var _nc: NetConnection;
private
var _ns: NetStream;
private
var _throughputTimer: Timer;
private
var _currentThroughput: int = 0;
private
var _loadStartTimestamp: int;
private
var _loadStarted: Boolean = false;
private
var _loadCompleted: Boolean = false;
private
var _loadErrored: Boolean = false;
private
var _pauseOnStart: Boolean = false;
private
var _pausePending: Boolean = false;
private
var _onmetadadataFired: Boolean = false;
private
var _startOffset: Number = 0;
private
var _ending: Boolean = false;
private
var _videoReference: Video;
private
var _pausedSeekValue: Number = 4294967295;
private
var _src: Object;
private
var _metadata: Object;
private
var _isPlaying: Boolean = false;
private
var _isPaused: Boolean = true;
private
var _isBuffering: Boolean = false;
private
var _isSeeking: Boolean = false;
private
var _isLive: Boolean = false;
private
var _canSeekAhead: Boolean = false;
private
var _hasEnded: Boolean = false;
private
var _canPlayThrough: Boolean = false;
private
var _loop: Boolean = false;
private
var _durationOverride: Number;
private
var _model: VideoJSModel;
public
function HTTPVideoProvider() {
super();
_model = VideoJSModel.getInstance();
_metadata = {};
_throughputTimer = new Timer(250, 0);
_throughputTimer.addEventListener(TimerEvent.TIMER, onThroughputTimerTick);
return;
}
public
function get loop(): Boolean {
return _loop;
}
public
function set loop(arg1: Boolean): void {
_loop = arg1;
return;
}
public
function get time(): Number {
if (_ns != null) {
if (_pausedSeekValue != -1) {
return _pausedSeekValue;
}
} else {
return 0;
}
return _startOffset + _ns.time;
}
public
function get duration(): Number {
if (_metadata != null && !(_metadata.duration == undefined)) {
return Number(_metadata.duration);
}
if (_durationOverride && _durationOverride > 0) {
return _durationOverride;
}
return 0;
}
public
function set duration(arg1: Number): void {
_durationOverride = arg1;
return;
}
public
function get readyState(): int {
if (_metadata != null && !(_metadata.duration == undefined)) {
if (_isPlaying) {
if (_canPlayThrough) {
return 4;
}
} else {
return 1;
}
} else {
return 0;
}
if (_ns.bufferLength >= _ns.bufferTime) {
return 3;
}
return 2;
}
public
function get networkState(): int {
if (!_loadStarted) {
return 0;
}
if (_loadCompleted) {
return 1;
}
if (_loadErrored) {
return 3;
}
return 2;
}
public
function appendBytesAction(arg1: String): void {
if (_ns) {
_ns.appendBytesAction(arg1);
}
return;
}
public
function appendBuffer(arg1: ByteArray): void {
_ns.appendBytes(arg1);
return;
}
public
function endOfStream(): void {
_ending = true;
return;
}
public
function abort(): void {
_ns.seek(time);
return;
}
public
function get buffered(): Number {
if (_ns && _src.path == null) {
return _startOffset + _ns.bufferLength + _ns.time;
}
if (duration > 0) {
return _ns.bytesLoaded / _ns.bytesTotal * duration;
}
return 0;
}
public
function get bufferedBytesEnd(): int {
if (_loadStarted) {
return _ns.bytesLoaded;
}
return 0;
}
public
function get bytesLoaded(): int {
return 0;
}
public
function get bytesTotal(): int {
return 0;
}
public
function get playing(): Boolean {
return _isPlaying;
}
public
function get paused(): Boolean {
return _isPaused;
}
public
function get ended(): Boolean {
return _hasEnded;
}
public
function get seeking(): Boolean {
return _isSeeking;
}
public
function get usesNetStream(): Boolean {
return true;
}
public
function get metadata(): Object {
return _metadata;
}
public
function set src(arg1: Object): void {
init(arg1, false);
return;
}
public
function get srcAsString(): String {
if (_src != null) {
return _src.url;
}
return "";
}
public
function init(arg1: Object, arg2: Boolean): void {
_onmetadadataFired = false;
_src = arg1;
_loadErrored = false;
_loadStarted = false;
_loadCompleted = false;
if (_model.preload) {
initNetConnection();
}
return;
}
public
function load(): void {
_pauseOnStart = true;
_isPlaying = false;
_isPaused = true;
initNetConnection();
return;
}
public
function play(): void {
if (!_loadStarted) {
_pauseOnStart = false;
_isPlaying = false;
_isPaused = false;
_metadata = {};
initNetConnection();
} else if (_hasEnded) {
_hasEnded = false;
_ns.seek(0);
}
_pausePending = false;
_ns.resume();
_isPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
if (!_isBuffering) {
_model.broadcastEventExternally(ExternalEventName.ON_START);
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_START, {}));
return;
}
public
function pause(): void {
_ns.pause();
if (_isPlaying && !_isPaused) {
_isPaused = true;
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
if (_isBuffering) {
_pausePending = true;
}
} else if (_hasEnded) {
_hasEnded = false;
_ns.seek(0);
}
return;
}
public
function resume(): void {
if (_isPlaying && _isPaused) {
_ns.resume();
_isPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
if (!_isBuffering) {
_model.broadcastEventExternally(ExternalEventName.ON_START);
}
}
return;
}
public
function seekBySeconds(arg1: Number): void {
if (_isPlaying) {
_isSeeking = true;
_throughputTimer.stop();
if (_isPaused) {
_pausedSeekValue = arg1;
}
} else if (_hasEnded) {
_isPlaying = true;
_hasEnded = false;
}
_isBuffering = true;
if (_src.path === null) {
_startOffset = arg1;
return;
}
_ns.seek(arg1);
return;
}
public
function seekByPercent(arg1: Number): void {
if (_isPlaying && !(_metadata.duration == undefined)) {
_isSeeking = true;
if (arg1 < 0) {
_ns.seek(0);
} else if (arg1 > 1) {
_throughputTimer.stop();
_ns.seek(arg1 / 100 * _metadata.duration);
} else {
_throughputTimer.stop();
_ns.seek(arg1 * _metadata.duration);
}
}
return;
}
public
function stop(): void {
if (_isPlaying) {
_ns.close();
_isPlaying = false;
_hasEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {}));
_throughputTimer.stop();
_throughputTimer.reset();
}
return;
}
public
function attachVideo(arg1: Video): void {
_videoReference = arg1;
return;
}
public
function die(): void {
if (_videoReference) {
_videoReference.attachNetStream(null);
}
if (_ns) {
_ns.close();
_ns = null;
}
if (_nc) {
_nc.close();
_nc = null;
}
if (_throughputTimer) {
_throughputTimer.stop();
_throughputTimer = null;
}
return;
}
private
function initNetConnection(): void {
_loadStarted = true;
_model.broadcastEventExternally(ExternalEventName.ON_LOAD_START);
if (_nc != null) {
_nc.close();
}
_nc.removeEventListener(NetStatusEvent.NET_STATUS, onNetConnectionStatus);
_nc = null;
_nc = new NetConnection();
_nc.client = this;
_nc.addEventListener(NetStatusEvent.NET_STATUS, onNetConnectionStatus);
_nc.connect(null);
return;
}
private
function initNetStream(): void {
if (_ns != null) {
_ns.close();
_ns.removeEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatus);
_ns = null;
}
_ns = new NetStream(_nc);
_ns.inBufferSeek = true;
_ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatus);
_ns.client = this;
_ns.bufferTime = 0.5;
_ns.play(_src.path);
_ns.pause();
_videoReference.attachNetStream(_ns);
if (_src.path === null) {
_pausePending = true;
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_READY, {
"ns": _ns
}));
return;
}
private
function calculateThroughput(): void {
var REG_2: Number = NaN;
if (_ns.bytesLoaded == _ns.bytesTotal) {
_canPlayThrough = true;
_loadCompleted = true;
_throughputTimer.stop();
_throughputTimer.reset();
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
} else if (_ns.bytesTotal > 0 && !(_metadata == null) && !(_metadata.duration == undefined)) {
_currentThroughput = _ns.bytesLoaded / (getTimer() - _loadStartTimestamp) / 1000;
REG_2 = (_ns.bytesTotal - _ns.bytesLoaded) * _currentThroughput;
if (REG_2 <= _metadata.duration) {
_throughputTimer.stop();
_throughputTimer.reset();
_canPlayThrough = true;
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
}
}
return;
}
private
function onNetConnectionStatus(arg1: NetStatusEvent): void {
switch (arg1.info.code) {
case "NetConnection.Connect.Success":
initNetStream();
break;
case "NetConnection.Connect.Failed":
break;
default:
break;
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_NETCONNECTION_STATUS, {
"info": arg1.info
}));
return;
}
private
function onNetStreamStatus(arg1: NetStatusEvent): void {
switch (arg1.info.code) {
case "NetStream.Play.Start":
_pausedSeekValue = -1;
_metadata = null;
_canPlayThrough = false;
_hasEnded = false;
_isBuffering = true;
_currentThroughput = 0;
_loadStartTimestamp = getTimer();
_throughputTimer.reset();
_throughputTimer.start();
if (!_pauseOnStart || _model.autoplay) {
_ns.resume();
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_START, {
"info": arg1.info
}));
}
break;
case "NetStream.SeekStart.Notify":
if (_src.path === null) {
appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);
}
_model.broadcastEventExternally(ExternalEventName.ON_SEEK_START);
break;
case "NetStream.Buffer.Full":
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY);
_pausedSeekValue = -1;
_isPlaying = true;
if (_pausePending) {
_pausePending = false;
_ns.pause();
_isPaused = true;
} else if (_isBuffering) {
_model.broadcastEventExternally(ExternalEventName.ON_START);
}
_isBuffering = false;
break;
case "NetStream.Buffer.Empty":
if (!_isPlaying) {
return;
}
if (_ending) {
_ending = false;
_isPlaying = false;
_isPaused = true;
_hasEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {
"info": arg1.info
}));
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);
_startOffset = 0;
_pausedSeekValue = 0;
break;
} else {
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
break;
}
case "NetStream.Play.Stop":
if (!_loop) {
_isPlaying = false;
_isPaused = true;
_hasEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {
"info": arg1.info
}));
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);
} else {
_ns.seek(0);
}
_throughputTimer.stop();
_throughputTimer.reset();
break;
case "NetStream.Seek.Notify":
_isPlaying = true;
_isSeeking = false;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_SEEK_COMPLETE, {
"info": arg1.info
}));
_model.broadcastEventExternally(ExternalEventName.ON_SEEK_COMPLETE);
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
_currentThroughput = 0;
_loadStartTimestamp = getTimer();
_throughputTimer.reset();
_throughputTimer.start();
break;
case "NetStream.Play.StreamNotFound":
_loadErrored = true;
_model.broadcastErrorEventExternally(ExternalErrorEventName.SRC_404);
break;
case "NetStream.Video.DimensionChange":
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_VIDEO_DIMENSION_UPDATE, {
"videoWidth": _videoReference.videoWidth,
"videoHeight": _videoReference.videoHeight
}));
if (_model.metadata && _videoReference) {
_model.metadata.width = _videoReference.videoWidth;
_model.metadata.height = _videoReference.videoHeight;
}
break;
default:
break;
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_NETSTREAM_STATUS, {
"info": arg1.info
}));
return;
}
private
function onThroughputTimerTick(arg1: TimerEvent): void {
calculateThroughput();
return;
}
public
function onMetaData(arg1: Object): void {
if (_onmetadadataFired) {
return;
}
_metadata = arg1;
if (arg1.duration != undefined) {
_isLive = false;
_canSeekAhead = true;
_model.broadcastEventExternally(ExternalEventName.ON_DURATION_CHANGE, _metadata.duration);
} else {
_isLive = true;
_canSeekAhead = false;
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_META_DATA, {
"metadata": _metadata
}));
_model.broadcastEventExternally(ExternalEventName.ON_METADATA, _metadata);
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_FULL);
_onmetadadataFired = true;
return;
}
public
function onCuePoint(arg1: Object): void {
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_CUE_POINT, {
"cuepoint": arg1
}));
return;
}
public
function onXMPData(arg1: Object): void {
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_XMP_DATA, {
"cuepoint": arg1
}));
return;
}
public
function onPlayStatus(arg1: Object): void {
return;
}
}
}
package com.videojs.structs {
public class PlaybackType extends Object {
public static
const HTTP: String = "PlaybackType.HTTP";
public static
const RTMP: String = "PlaybackType.RTMP";
public
function PlaybackType() {
super();
return;
}
}
}
package com.videojs.providers {
import com.videojs.providers.IProvider;
import flash.utils.Timer;
import flash.media.Sound;
import flash.media.SoundChannel;
import com.videojs.VideoJSModel;
import flash.utils.ByteArray;
import flash.media.Video;
import flash.events.TimerEvent;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
public class HTTPAudioProvider extends Object implements IProvider {
private
var _throughputTimer: Timer;
private
var _currentThroughput: int = 0;
private
var _loadStartTimestamp: int;
private
var _loadStarted: Boolean = false;
private
var _loadCompleted: Boolean = false;
private
var _loadErrored: Boolean = false;
private
var _isBuffering: Boolean = false;
private
var _src: Object;
private
var _metadata: Object;
private
var _loop: Boolean = false;
private
var _preloadInitiated: Boolean = false;
private
var _sound: Sound;
private
var _soundChannel: SoundChannel;
private
var _audioPlaybackStarted: Boolean = false;
private
var _audioPlaybackStopped: Boolean = false;
private
var _audioPlaybackPaused: Boolean = false;
private
var _audioIsSeeking: Boolean = false;
private
var _audioPlaybackHasEnded: Boolean = false;
private
var _audioBytesLoaded: int = 0;
private
var _audioBytesTotal: int = 0;
private
var _audioDuration: Number = 0;
private
var _audioPausePoint: Number = 0;
private
var _estimatedDurations: int = 0;
private
var _canPlayThroughDispatched: Boolean = false;
private
var _model: VideoJSModel;
public
function HTTPAudioProvider() {
super();
_model = VideoJSModel.getInstance();
_metadata = {};
_throughputTimer = new Timer(250, 0);
_throughputTimer.addEventListener(TimerEvent.TIMER, onThroughputTimerTick);
return;
}
public
function get loop(): Boolean {
return _loop;
}
public
function set loop(arg1: Boolean): void {
_loop = arg1;
return;
}
public
function get time(): Number {
if (_audioPlaybackStarted) {
if (_soundChannel != null) {
return _soundChannel.position / 1000;
}
} else {
return 0;
}
return 0;
}
public
function get duration(): Number {
return _audioDuration / 1000;
}
public
function get readyState(): int {
if (_canPlayThroughDispatched) {
return 4;
}
if (_audioPlaybackStarted) {
return 3;
}
if (_loadStarted) {
return 2;
}
if (_estimatedDurations >= 5) {
return 1;
}
return 0;
}
public
function get networkState(): int {
if (_loadErrored) {
return 3;
}
if (_loadStarted) {
return 2;
}
return 1;
}
public
function appendBuffer(arg1: ByteArray): void {
throw ("HTTPAudioProvider does not support appendBuffer");
}
public
function endOfStream(): void {
throw ("HTTPAudioProvider does not support endOfStream");
}
public
function abort(): void {
throw ("HTTPAudioProvider does not support abort");
}
public
function get buffered(): Number {
if (duration > 0) {
return bytesLoaded / bytesTotal * duration;
}
return 0;
}
public
function get bufferedBytesEnd(): int {
return _audioBytesLoaded;
}
public
function get bytesLoaded(): int {
return _audioBytesLoaded;
}
public
function get bytesTotal(): int {
return _audioBytesTotal;
}
public
function get playing(): Boolean {
return _audioPlaybackStarted;
}
public
function get paused(): Boolean {
return _audioPlaybackPaused;
}
public
function get ended(): Boolean {
return _audioPlaybackHasEnded;
}
public
function get seeking(): Boolean {
return _audioIsSeeking;
}
public
function get usesNetStream(): Boolean {
return false;
}
public
function get metadata(): Object {
return _metadata;
}
public
function get srcAsString(): String {
if (_src != null && !(_src.path == undefined)) {
return _src.path;
}
return "";
}
public
function set src(arg1: Object): void {
_src = arg1;
return;
}
public
function init(arg1: Object, arg2: Boolean): void {
_src = arg1;
_loadErrored = false;
_loadStarted = false;
_loadCompleted = false;
if (arg2) {
play();
}
return;
}
public
function load(): void {
var SLOT1: URLRequest = null;
_preloadInitiated = true;
if (_src != "") {
if (_audioPlaybackStarted) {
_soundChannel.stop();
_soundChannel = null;
_throughputTimer.stop();
_throughputTimer.reset();
} else if (_sound == null) {
_sound = new Sound();
_sound.addEventListener(IOErrorEvent.IO_ERROR, onSoundLoadError);
_sound.addEventListener(ProgressEvent.PROGRESS, onSoundProgress);
_sound.addEventListener(Event.COMPLETE, onSoundLoadComplete);
_sound.addEventListener(Event.OPEN, onSoundOpen);
_sound.addEventListener(Event.ID3, onID3Loaded);
}
}
_audioPlaybackStarted = false;
_audioPlaybackStopped = false;
_audioPlaybackPaused = false;
_audioPlaybackHasEnded = false;
_audioBytesLoaded = 0;
_audioBytesTotal = 0;
_audioDuration = 0;
_audioPausePoint = 0;
_estimatedDurations = 0;
_canPlayThroughDispatched = false;
_loadErrored = false;
SLOT1 = new URLRequest(_src.path);
_sound.load(SLOT1);
_model.broadcastEventExternally(ExternalEventName.ON_LOAD_START);
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
return;
}
public
function play(): void {
var SLOT1: URLRequest = null;
if (_src != "") {
if (_preloadInitiated) {
_preloadInitiated = false;
_soundChannel = _sound.play();
_soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundPlayComplete);
} else if (_audioPlaybackStarted) {
if (_audioPlaybackPaused) {
resume();
} else {
_soundChannel.stop();
_soundChannel = null;
_throughputTimer.stop();
_throughputTimer.reset();
}
} else {
_sound = new Sound();
_sound.addEventListener(IOErrorEvent.IO_ERROR, onSoundLoadError);
_sound.addEventListener(ProgressEvent.PROGRESS, onSoundProgress);
_sound.addEventListener(Event.COMPLETE, onSoundLoadComplete);
_sound.addEventListener(Event.OPEN, onSoundOpen);
_sound.addEventListener(Event.ID3, onID3Loaded);
}
}
_audioPlaybackStarted = false;
_audioPlaybackStopped = false;
_audioPlaybackPaused = false;
_audioPlaybackHasEnded = false;
_audioBytesLoaded = 0;
_audioBytesTotal = 0;
_audioDuration = 0;
_audioPausePoint = 0;
_estimatedDurations = 0;
_canPlayThroughDispatched = false;
_loadErrored = false;
SLOT1 = new URLRequest(_src.path);
_sound.load(SLOT1);
_soundChannel = _sound.play();
_soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundPlayComplete);
_model.broadcastEventExternally(ExternalEventName.ON_LOAD_START);
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
return;
}
public
function pause(): void {
if (_audioPlaybackStarted) {
_audioPausePoint = _soundChannel.position;
_soundChannel.stop();
_audioPlaybackPaused = true;
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
}
return;
}
public
function resume(): void {
if (_audioPlaybackStarted && _audioPlaybackPaused) {
_soundChannel = _sound.play(_audioPausePoint);
_audioPlaybackPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
_model.broadcastEventExternally(ExternalEventName.ON_START);
}
return;
}
public
function seekBySeconds(arg1: Number): void {
if (_audioDuration > 0) {
_soundChannel.stop();
_soundChannel = _sound.play(int(arg1 * 1000));
_audioPlaybackStarted = true;
_audioPlaybackHasEnded = false;
_audioPlaybackPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_SEEK_COMPLETE);
}
return;
}
public
function seekByPercent(arg1: Number): void {
if (_audioPlaybackStarted && _audioDuration > 0) {
_soundChannel.stop();
_soundChannel = _sound.play(arg1 * _audioDuration);
_audioPlaybackStarted = true;
_audioPlaybackHasEnded = false;
_audioPlaybackPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_SEEK_COMPLETE);
}
return;
}
public
function stop(): void {
if (_audioPlaybackStarted) {
_soundChannel.stop();
_audioPlaybackStarted = false;
_audioPlaybackStopped = true;
_audioPlaybackPaused = false;
}
return;
}
public
function attachVideo(arg1: Video): void {
return;
}
public
function die(): void {
if (_soundChannel) {
stop();
_soundChannel = null;
}
if (_throughputTimer) {
_throughputTimer.stop();
_throughputTimer = null;
}
return;
}
private
function doLoadCalculations(): void {
var REG_2: Number = NaN;
var REG_3: Number = NaN;
var REG_4: Number = NaN;
if (_sound.bytesLoaded == _sound.bytesTotal) {
_loadCompleted = true;
_audioDuration = _sound.length;
_throughputTimer.stop();
_throughputTimer.reset();
_model.broadcastEventExternally(ExternalEventName.ON_DURATION_CHANGE, _audioDuration);
_canPlayThroughDispatched = true;
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
} else {
REG_2 = _sound.bytesLoaded / _sound.bytesTotal;
_audioDuration = _sound.length * 1 / REG_2;
var REG_5: * = this;
var REG_6: * = REG_5._estimatedDurations + 1;
REG_5._estimatedDurations = REG_6;
if (_estimatedDurations == 5) {
_model.broadcastEventExternally(ExternalEventName.ON_DURATION_CHANGE, _audioDuration);
} else if (_estimatedDurations > 5) {
REG_3 = _sound.bytesLoaded / (getTimer() - _loadStartTimestamp) / 1000;
REG_4 = (_sound.bytesTotal - _sound.bytesLoaded) / REG_3;
if (!_canPlayThroughDispatched && REG_4 < _audioDuration) {
_canPlayThroughDispatched = true;
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
}
}
}
return;
}
private
function onThroughputTimerTick(arg1: TimerEvent): void {
doLoadCalculations();
return;
}
private
function onSoundProgress(arg1: ProgressEvent): void {
_audioBytesLoaded = arg1.bytesLoaded;
_audioBytesTotal = arg1.bytesTotal;
_audioDuration = _sound.length;
return;
}
private
function onSoundOpen(arg1: Event): void {
_loadStartTimestamp = getTimer();
_throughputTimer.start();
_audioPlaybackStarted = true;
_model.broadcastEventExternally(ExternalEventName.ON_START);
return;
}
private
function onSoundLoadComplete(arg1: Event): void {
_throughputTimer.stop();
_throughputTimer.reset();
doLoadCalculations();
return;
}
private
function onSoundPlayComplete(arg1: Event): void {
if (!_loop) {
_audioPlaybackStarted = false;
_audioPlaybackHasEnded = true;
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);
} else if (_audioDuration > 0) {
_soundChannel.stop();
_soundChannel = _sound.play(0);
_audioPlaybackStarted = true;
}
return;
}
private
function onSoundLoadError(arg1: IOErrorEvent): void {
_loadErrored = true;
_model.broadcastErrorEventExternally(ExternalErrorEventName.SRC_404);
return;
}
private
function onID3Loaded(arg1: Event): void {
_metadata = {
"id3": _sound.id3
};
_model.broadcastEventExternally(ExternalEventName.ON_METADATA, _metadata);
return;
}
}
}
package com.videojs.providers {
import flash.events.EventDispatcher;
import com.videojs.providers.IProvider;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.utils.Timer;
import flash.media.Video;
import com.videojs.VideoJSModel;
import flash.utils.ByteArray;
import flash.events.TimerEvent;
import flash.events.NetStatusEvent;
public class RTMPVideoProvider extends EventDispatcher implements IProvider {
private
var _nc: NetConnection;
private
var _ns: NetStream;
private
var _rtmpRetryTimer: Timer;
private
var _ncRTMPRetryThreshold: int = 3;
private
var _ncRTMPCurrentRetry: int = 0;
private
var _throughputTimer: Timer;
private
var _currentThroughput: int = 0;
private
var _loadStartTimestamp: int;
private
var _loadStarted: Boolean = false;
private
var _loadCompleted: Boolean = false;
private
var _loadErrored: Boolean = false;
private
var _pauseOnStart: Boolean = false;
private
var _pausePending: Boolean = false;
private
var _videoReference: Video;
private
var _src: Object;
private
var _metadata: Object;
private
var _hasDuration: Boolean = false;
private
var _isPlaying: Boolean = false;
private
var _isPaused: Boolean = true;
private
var _isBuffering: Boolean = false;
private
var _isSeeking: Boolean = false;
private
var _isLive: Boolean = false;
private
var _canSeekAhead: Boolean = false;
private
var _hasEnded: Boolean = false;
private
var _reportEnded: Boolean = false;
private
var _canPlayThrough: Boolean = false;
private
var _loop: Boolean = false;
private
var _model: VideoJSModel;
public
function RTMPVideoProvider() {
super();
_model = VideoJSModel.getInstance();
_metadata = {};
_rtmpRetryTimer = new Timer(25, 1);
_rtmpRetryTimer.addEventListener(TimerEvent.TIMER, onRTMPRetryTimerTick);
_throughputTimer = new Timer(250, 0);
_throughputTimer.addEventListener(TimerEvent.TIMER, onThroughputTimerTick);
return;
}
public
function get loop(): Boolean {
return _loop;
}
public
function set loop(arg1: Boolean): void {
_loop = arg1;
return;
}
public
function get time(): Number {
if (_ns != null) {
return _ns.time;
}
return 0;
}
public
function get duration(): Number {
if (_metadata != null && !(_metadata.duration == undefined)) {
return Number(_metadata.duration);
}
return 0;
}
public
function get readyState(): int {
if (_metadata != null && !(_metadata.duration == undefined)) {
if (_isPlaying) {
if (_canPlayThrough) {
return 4;
}
} else {
return 1;
}
} else {
return 0;
}
if (_ns.bufferLength >= _ns.bufferTime) {
return 3;
}
return 2;
}
public
function get networkState(): int {
if (!_loadStarted) {
return 0;
}
if (_loadCompleted) {
return 1;
}
if (_loadErrored) {
return 3;
}
return 2;
}
public
function appendBuffer(arg1: ByteArray): void {
throw ("RTMPVideoProvider does not support appendBuffer");
}
public
function endOfStream(): void {
throw ("RTMPVideoProvider does not support endOfStream");
}
public
function abort(): void {
throw ("RTMPVideoProvider does not support abort");
}
public
function get buffered(): Number {
if (duration > 0) {
return duration;
}
return 0;
}
public
function get bufferedBytesEnd(): int {
if (_loadStarted) {
return _ns.bytesLoaded;
}
return 0;
}
public
function get bytesLoaded(): int {
return 0;
}
public
function get bytesTotal(): int {
return 0;
}
public
function get playing(): Boolean {
return _isPlaying;
}
public
function get paused(): Boolean {
return _isPaused;
}
public
function get ended(): Boolean {
return _reportEnded;
}
public
function get seeking(): Boolean {
return _isSeeking;
}
public
function get usesNetStream(): Boolean {
return true;
}
public
function get metadata(): Object {
return _metadata;
}
public
function set src(arg1: Object): void {
_hasDuration = false;
if (_isPlaying) {
_ns.close();
_loadErrored = false;
_loadStarted = false;
_loadCompleted = false;
_src = arg1;
initNetConnection();
} else {
init(arg1, false);
}
return;
}
public
function get srcAsString(): String {
if (_src != null) {
return _src.url;
}
return "";
}
public
function init(arg1: Object, arg2: Boolean): void {
_src = arg1;
_loadErrored = false;
_loadStarted = false;
_loadCompleted = false;
if (arg2) {
play();
}
return;
}
public
function load(): void {
_pauseOnStart = true;
_isPlaying = false;
_isPaused = true;
initNetConnection();
return;
}
public
function play(): void {
if (!_loadStarted) {
_pauseOnStart = false;
_isPlaying = false;
_isPaused = false;
_metadata = {};
initNetConnection();
} else if (_isPaused && !_reportEnded) {
_pausePending = false;
_ns.resume();
_isPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_START, {}));
} else if (_hasEnded) {
_ns.seek(0);
_isPlaying = true;
_isPaused = false;
_hasEnded = false;
_reportEnded = false;
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
}
return;
}
public
function pause(): void {
if (_isPlaying && !_isPaused) {
_ns.pause();
_isPaused = true;
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
if (_isBuffering) {
_pausePending = true;
}
} else if (_hasEnded && !_isPaused) {
_isPaused = true;
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
}
return;
}
public
function resume(): void {
if (_isPlaying && _isPaused) {
_ns.resume();
_isPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
}
return;
}
public
function seekBySeconds(arg1: Number): void {
if (_isPlaying) {
_isSeeking = true;
_throughputTimer.stop();
_ns.seek(arg1);
_isBuffering = true;
} else if (_hasEnded) {
_ns.seek(arg1);
_isPlaying = true;
_hasEnded = false;
_reportEnded = false;
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
}
return;
}
public
function seekByPercent(arg1: Number): void {
if (_isPlaying && !(_metadata.duration == undefined)) {
_isSeeking = true;
if (arg1 < 0) {
_ns.seek(0);
} else if (arg1 > 1) {
_throughputTimer.stop();
_ns.seek(arg1 / 100 * _metadata.duration);
} else {
_throughputTimer.stop();
_ns.seek(arg1 * _metadata.duration);
}
}
return;
}
public
function stop(): void {
if (_isPlaying) {
_ns.close();
_isPlaying = false;
_hasEnded = true;
_reportEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {}));
_throughputTimer.stop();
_throughputTimer.reset();
}
return;
}
public
function attachVideo(arg1: Video): void {
_videoReference = arg1;
return;
}
public
function die(): void {
if (_videoReference) {
_videoReference.attachNetStream(null);
}
if (_ns) {
_ns.close();
_ns = null;
}
if (_nc) {
_nc.close();
_nc = null;
}
if (_throughputTimer) {
_throughputTimer.stop();
_throughputTimer = null;
}
if (_rtmpRetryTimer) {
_rtmpRetryTimer.stop();
_rtmpRetryTimer = null;
}
return;
}
private
function initNetConnection(): void {
if (_nc == null) {
_nc = new NetConnection();
_nc.client = this;
_nc.addEventListener(NetStatusEvent.NET_STATUS, onNetConnectionStatus);
}
if (_nc.connected) {
if (_src.connectionURL != _nc.uri) {
_nc.connect(_src.connectionURL);
} else {
initNetStream();
}
} else {
_nc.connect(_src.connectionURL);
}
return;
}
private
function initNetStream(): void {
if (_ns != null) {
_ns.removeEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatus);
_ns = null;
}
_ns = new NetStream(_nc);
_ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatus);
_ns.client = this;
_ns.bufferTime = 1;
_ns.play(_src.streamURL);
_videoReference.attachNetStream(_ns);
_model.broadcastEventExternally(ExternalEventName.ON_LOAD_START);
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_READY, {
"ns": _ns
}));
return;
}
private
function calculateThroughput(): void {
var REG_2: Number = NaN;
if (_ns.bytesLoaded == _ns.bytesTotal) {
_canPlayThrough = true;
_loadCompleted = true;
_throughputTimer.stop();
_throughputTimer.reset();
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
} else if (_ns.bytesTotal > 0 && !(_metadata == null) && !(_metadata.duration == undefined)) {
_currentThroughput = _ns.bytesLoaded / (getTimer() - _loadStartTimestamp) / 1000;
REG_2 = (_ns.bytesTotal - _ns.bytesLoaded) * _currentThroughput;
if (REG_2 <= _metadata.duration) {
_throughputTimer.stop();
_throughputTimer.reset();
_canPlayThrough = true;
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
}
}
return;
}
private
function onRTMPRetryTimerTick(arg1: TimerEvent): void {
initNetConnection();
return;
}
private
function onNetConnectionStatus(arg1: NetStatusEvent): void {
switch (arg1.info.code) {
case "NetConnection.Connect.Success":
_model.broadcastEventExternally(ExternalEventName.ON_RTMP_CONNECT_SUCCESS);
initNetStream();
break;
case "NetConnection.Connect.Failed":
if (_ncRTMPCurrentRetry < _ncRTMPRetryThreshold) {
var REG_3: * = this;
var REG_4: * = REG_3._ncRTMPCurrentRetry + 1;
REG_3._ncRTMPCurrentRetry = REG_4;
_model.broadcastErrorEventExternally(ExternalErrorEventName.RTMP_CONNECT_FAILURE);
_rtmpRetryTimer.start();
_model.broadcastEventExternally(ExternalEventName.ON_RTMP_RETRY);
}
break;
default:
if (arg1.info.level == "error") {
_model.broadcastErrorEventExternally(arg1.info.code);
_model.broadcastErrorEventExternally(arg1.info.description);
}
break;
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_NETCONNECTION_STATUS, {
"info": arg1.info
}));
return;
}
private
function onNetStreamStatus(arg1: NetStatusEvent): void {
switch (arg1.info.code) {
case "NetStream.Play.Reset":
break;
case "NetStream.Play.Start":
_canPlayThrough = false;
_hasEnded = false;
_reportEnded = false;
_isBuffering = true;
_currentThroughput = 0;
_loadStartTimestamp = getTimer();
_throughputTimer.reset();
_throughputTimer.start();
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
if (_pauseOnStart && _loadStarted == false) {
_ns.pause();
_isPaused = true;
} else if (!_isPlaying) {
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_START, {
"info": arg1.info
}));
_loadStarted = true;
break;
case "NetStream.Buffer.Full":
_isBuffering = false;
_isPlaying = true;
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_FULL);
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY);
_model.broadcastEventExternally(ExternalEventName.ON_START);
if (_pausePending) {
_pausePending = false;
_ns.pause();
_isPaused = true;
}
break;
case "NetStream.Buffer.Empty":
if (_hasEnded) {
if (!_loop) {
_isPlaying = false;
_hasEnded = true;
_reportEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {
"info": arg1.info
}));
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);
} else {
_ns.seek(0);
}
} else {
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
}
break;
case "NetStream.Play.Stop":
_hasEnded = true;
_throughputTimer.stop();
_throughputTimer.reset();
break;
case "NetStream.Seek.Notify":
_isPlaying = true;
_isSeeking = false;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_SEEK_COMPLETE, {
"info": arg1.info
}));
_model.broadcastEventExternally(ExternalEventName.ON_SEEK_COMPLETE);
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
_currentThroughput = 0;
_loadStartTimestamp = getTimer();
_throughputTimer.reset();
_throughputTimer.start();
break;
case "NetStream.Play.StreamNotFound":
_loadErrored = true;
_model.broadcastErrorEventExternally(ExternalErrorEventName.SRC_404);
break;
default:
if (arg1.info.level == "error") {
_model.broadcastErrorEventExternally(arg1.info.code);
_model.broadcastErrorEventExternally(arg1.info.description);
}
break;
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_NETSTREAM_STATUS, {
"info": arg1.info
}));
return;
}
private
function onThroughputTimerTick(arg1: TimerEvent): void {
calculateThroughput();
return;
}
public
function onMetaData(arg1: Object): void {
_metadata = arg1;
if (arg1.duration != undefined) {
_isLive = false;
_canSeekAhead = true;
if (!_hasDuration) {
_hasDuration = true;
_model.broadcastEventExternally(ExternalEventName.ON_DURATION_CHANGE, _metadata.duration);
}
} else {
_isLive = true;
_canSeekAhead = false;
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_META_DATA, {
"metadata": _metadata
}));
_model.broadcastEventExternally(ExternalEventName.ON_METADATA, _metadata);
return;
}
public
function onCuePoint(arg1: Object): void {
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_CUE_POINT, {
"cuepoint": arg1
}));
return;
}
public
function onXMPData(arg1: Object): void {
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_XMP_DATA, {
"cuepoint": arg1
}));
return;
}
public
function onPlayStatus(arg1: Object): void {
return;
}
public
function onBWCheck(): Number {
return 0;
}
public
function onBWDone(): void {
return;
}
public
function onFCSubscribe(arg1: Object): void {
return;
}
public
function onFCUnsubscribe(arg1: Object): void {
return;
}
public
function streamInfo(arg1: Object): void {
return;
}
}
}
package com.videojs.structs {
public class PlayerMode extends Object {
public static
const VIDEO: String = "video";
public static
const AUDIO: String = "audio";
public
function PlayerMode() {
super();
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment