PageRenderTime 3306ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/classes/net/palantir/video/VideoPlayer.as

http://flashy.googlecode.com/
ActionScript | 652 lines | 518 code | 17 blank | 117 comment | 103 complexity | 822b4386d83c0455a13eac20e0dfb8cd MD5 | raw file
  1. /**
  2. * @file
  3. *
  4. * Custom module for site-specific configuration.
  5. *
  6. * @copyright (C) Copyright 2009 Palantir.net
  7. * @license http://www.gnu.org/licenses/gpl-2.0.html
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. ?package net.palantir.video {
  23. import flash.display.Loader;
  24. import flash.display.Sprite;
  25. import flash.display.StageAlign;
  26. import flash.display.StageDisplayState;
  27. import flash.display.StageScaleMode;
  28. import flash.text.TextField;
  29. import flash.text.TextFieldAutoSize;
  30. import flash.text.TextFormat;
  31. import flash.events.Event;
  32. import flash.events.MouseEvent;
  33. import flash.events.NetStatusEvent;
  34. import flash.events.TimerEvent;
  35. import flash.media.Video;
  36. import flash.media.SoundTransform;
  37. import flash.net.NetConnection;
  38. import flash.net.NetStream;
  39. import flash.net.URLLoader;
  40. import flash.net.URLRequest;
  41. import flash.system.Capabilities;
  42. import flash.utils.Timer;
  43. import net.palantir.video.controls.ControlPanel;
  44. import net.palantir.video.controls.BaseButton;
  45. import net.palantir.video.controls.BaseSlider;
  46. import net.palantir.video.controls.PlayPauseButton;
  47. import net.palantir.video.controls.PrevButton;
  48. import net.palantir.video.controls.NextButton;
  49. import net.palantir.video.controls.SeekSlider;
  50. import net.palantir.video.controls.FullScreenButton;
  51. import net.palantir.video.controls.VolumeToggleButton;
  52. import net.palantir.video.controls.VolumeSlider;
  53. import net.palantir.video.controls.OverlayPlayButton;
  54. public class VideoPlayer extends Sprite {
  55. // PROPERTIES
  56. // general
  57. private var _video:Video;
  58. private var _videoContainer:Sprite;
  59. private var _connection:NetConnection;
  60. private var _stream:NetStream;
  61. private var _poster:Loader;
  62. private var _volume:SoundTransform;
  63. private var _volumeBackup:Number;
  64. private var _duration:Number;
  65. private var _playlist:XML;
  66. private var _ns:Namespace;
  67. private var _currentFile:int;
  68. private var _isPlaying:Boolean;
  69. private var _replay:Boolean;
  70. private var _uiControls:Array;
  71. private var _uiColors:Array;
  72. private var _uiBgColor:Array;
  73. private var _uiHideTimer:Timer;
  74. private var _uiDisabled:Boolean;
  75. // ui
  76. private var _controlPanel:ControlPanel;
  77. private var _playPauseButton:PlayPauseButton;
  78. private var _prevButton:PrevButton;
  79. private var _nextButton:NextButton;
  80. private var _seekSlider:SeekSlider;
  81. private var _fullScreenButton:FullScreenButton;
  82. private var _volumeToggleButton:VolumeToggleButton;
  83. private var _volumeSlider:VolumeSlider;
  84. private var _overlayPlayButton:OverlayPlayButton;
  85. private var _output:TextField; // DEBUGGING
  86. // CONSTRUCTOR
  87. public function VideoPlayer() {
  88. this.addEventListener(Event.ADDED_TO_STAGE, onInit, false, 0, false);
  89. };
  90. // METHODS
  91. // Connect
  92. private function connect(file:String):void {
  93. _connection.close();
  94. if (isHTTPRequest(file)) {
  95. _connection.connect(null);
  96. } else {
  97. // If RTMP and not already used ...
  98. if (_connection.uri != null && _connection.uri != getFilePath(file)) {
  99. _connection.connect(getFilePath(file));
  100. }
  101. }
  102. };
  103. // Load
  104. private function load(video:XML):void {
  105. default xml namespace = _ns;
  106. connect(video..location.toString());
  107. if (getBoolean(root.loaderInfo.parameters.autoPlay)) {
  108. play(video);
  109. if (_overlayPlayButton) _overlayPlayButton.hide();
  110. } else {
  111. cue(video);
  112. if (_overlayPlayButton) _overlayPlayButton.show();
  113. }
  114. if (_controlPanel) {
  115. if (getBoolean(video..options.@disableControls.toString())) {
  116. _uiDisabled = true;
  117. stage.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOverStage);
  118. _controlPanel.hide();
  119. } else {
  120. if (_uiDisabled) {
  121. _uiDisabled = false;
  122. _controlPanel.show();
  123. if (getBoolean(root.loaderInfo.parameters.uiAutoHide)) {
  124. stage.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverStage, false, 0, false);
  125. _uiHideTimer.start();
  126. }
  127. }
  128. }
  129. }
  130. addEventListener(Event.ENTER_FRAME, onLoadStream, false, 0, false);
  131. };
  132. // Cue
  133. private function cue(video:XML):void {
  134. var poster:String = video.image.toString();
  135. if (poster && poster != "") {
  136. _videoContainer.visible = false;
  137. var req:URLRequest = new URLRequest(poster);
  138. _poster.load(req);
  139. } else {
  140. _poster.unload();
  141. }
  142. play(video);
  143. _isPlaying = false;
  144. _stream.pause();
  145. _stream.seek(0);
  146. if (_playPauseButton) _playPauseButton.toggle(true);
  147. if (_seekSlider) {
  148. seekStop();
  149. _seekSlider.seekValue = 0;
  150. }
  151. };
  152. // Play
  153. private function play(video:XML):void {
  154. _isPlaying = true;
  155. _replay = false;
  156. _stream.play(video..location.toString());
  157. if (_seekSlider) seekStart();
  158. };
  159. // Load Prev
  160. private function loadPrev(evt:MouseEvent = null):void {
  161. //trace(_currentFile);
  162. if (--_currentFile < 0) _currentFile = (_playlist.trackList.children().length() - 1);
  163. load(_playlist..track[_currentFile]);
  164. };
  165. // Load Next
  166. private function loadNext(evt:MouseEvent = null):void {
  167. //trace(_currentFile);
  168. if (++_currentFile > (_playlist.trackList.children().length() - 1)) _currentFile = 0;
  169. load(_playlist..track[_currentFile]);
  170. };
  171. // Set Volume
  172. private function setVolume(vol:Number):void {
  173. // Constrain to 0 through 100
  174. vol = (isNaN(vol) || vol > 100) ? 1 : (vol < 4.5) ? 0 : vol / 100;
  175. _volume = _stream.soundTransform;
  176. _volume.volume = vol;
  177. _stream.soundTransform = _volume;
  178. if (_volumeToggleButton) _volumeToggleButton.toggle(!Boolean(vol));
  179. _volumeBackup = vol;
  180. };
  181. // Build Controls
  182. private function buildControls():void {
  183. var param:String = root.loaderInfo.parameters.uiControls;
  184. param = (param) ? param : "PlayPause|Prev|Next|Seek|FullScreen|MuteUnmute|Volume";
  185. if (param.toLowerCase() != "none") {
  186. _uiControls = param.split("|");
  187. // UI colors
  188. param = root.loaderInfo.parameters.uiColors;
  189. param = (param) ? param : "#000000|#000000|#000000|#000000|#000000|#000000|#000000";
  190. _uiColors = getColorsFromParam(param);
  191. // Control panel
  192. param = root.loaderInfo.parameters.uiBgColor;
  193. param = (param) ? param : "#FEFEFE|#CCCCCC";
  194. _uiBgColor = getColorsFromParam(param);
  195. _controlPanel = new ControlPanel(_uiBgColor[0], (_uiBgColor.length > 1) ? _uiBgColor[1] : null);
  196. addChild(_controlPanel);
  197. // UI controls
  198. var len:int = _uiControls.length;
  199. for (var i:int = 0; i < len; i++) {
  200. switch(_uiControls[i].toLowerCase()) {
  201. case "playpause":
  202. // PlayPause button
  203. _playPauseButton = new PlayPauseButton(_uiColors[i]);
  204. addChild(_playPauseButton);
  205. _controlPanel.addButton(BaseButton(_playPauseButton));
  206. _playPauseButton.addEventListener(MouseEvent.CLICK, onTogglePlay, false, 0, false);
  207. break;
  208. case "prev":
  209. // Prev button
  210. if (_playlist.trackList.children().length() > 1) {
  211. _prevButton = new PrevButton(_uiColors[i]);
  212. addChild(_prevButton);
  213. _controlPanel.addButton(BaseButton(_prevButton));
  214. _prevButton.addEventListener(MouseEvent.CLICK, loadPrev, false, 0, false);
  215. }
  216. break;
  217. case "next":
  218. // Next button
  219. if (_playlist.trackList.children().length() > 1) {
  220. _nextButton = new NextButton(_uiColors[i]);
  221. addChild(_nextButton);
  222. _controlPanel.addButton(BaseButton(_nextButton));
  223. _nextButton.addEventListener(MouseEvent.CLICK, loadNext, false, 0, false);
  224. }
  225. break;
  226. case "seek":
  227. // Seek slider
  228. _seekSlider = new SeekSlider(_uiColors[i], _uiBgColor[0], (_uiBgColor.length > 1) ? _uiBgColor[1] : null);
  229. addChild(_seekSlider);
  230. _controlPanel.addSlider(BaseSlider(_seekSlider), true);
  231. _seekSlider.addEventListener(MouseEvent.MOUSE_UP, onSeekMouseUp, false, 0, false);
  232. _seekSlider.addEventListener(MouseEvent.MOUSE_DOWN, onSeekMouseDown, false, 0, false);
  233. break;
  234. case "fullscreen":
  235. if (minVersionIs("9,0,115,0")) {
  236. // FullScreen button
  237. _fullScreenButton = new FullScreenButton(_uiColors[i]);
  238. addChild(_fullScreenButton);
  239. _controlPanel.addButton(BaseButton(_fullScreenButton));
  240. _fullScreenButton.addEventListener(MouseEvent.CLICK, onToggleFullScreen, false, 0, false);
  241. }
  242. break;
  243. case "muteunmute":
  244. // VolumeToggle button
  245. _volumeToggleButton = new VolumeToggleButton(_uiColors[i]);
  246. addChild(_volumeToggleButton);
  247. _controlPanel.addButton(BaseButton(_volumeToggleButton));
  248. _volumeToggleButton.addEventListener(MouseEvent.CLICK, onToggleVolume, false, 0, false);
  249. break;
  250. case "volume":
  251. // Volume slider
  252. _volumeSlider = new VolumeSlider(_uiColors[i], 0, 0);
  253. addChild(_volumeSlider);
  254. _controlPanel.addSlider(BaseSlider(_volumeSlider), false);
  255. _volumeSlider.volume = _stream.soundTransform.volume * 100;
  256. _volumeSlider.addEventListener(Event.CHANGE, onVolumeChange, false, 0, false);
  257. break;
  258. }
  259. }
  260. if (getBoolean(root.loaderInfo.parameters.uiAutoHide)) {
  261. _uiHideTimer.start();
  262. }
  263. }
  264. // Overlay Play Button
  265. _overlayPlayButton = new OverlayPlayButton();
  266. _overlayPlayButton.alpha = 0;
  267. _overlayPlayButton.mouseEnabled = false;
  268. addChild(_overlayPlayButton);
  269. };
  270. // Resize Controls
  271. private function resizeControls():void {
  272. _overlayPlayButton.resize();
  273. if (_controlPanel) _controlPanel.resize();
  274. };
  275. // Resize Video
  276. private function resizeVideo():void {
  277. var sw:int = Math.round(stage.stageWidth);
  278. var sh:int = Math.round(stage.stageHeight);
  279. var param:String = root.loaderInfo.parameters.maintainAspectRatio;
  280. if (param == null || getBoolean(param)) {
  281. var vw:int = Math.round(_video.videoWidth);
  282. vw = (vw == 0) ? sw : vw;
  283. var vh:int = Math.round(_video.videoHeight);
  284. vh = (vh == 0) ? sh : vh;
  285. var ratio:Number = vw / vh;
  286. // resize while maintaining aspect ratio
  287. if (sw / ratio < sh) {
  288. _video.width = sw;
  289. _poster.width = sw;
  290. _video.height = sw / ratio;
  291. _poster.height = sw / ratio;
  292. } else {
  293. _video.height = sh;
  294. _poster.height = sh;
  295. _video.width = sh * ratio;
  296. _poster.width = sh * ratio;
  297. }
  298. // reposition
  299. _video.x = sw / 2 - _video.width / 2;
  300. _poster.x = sw / 2 - _poster.width / 2;
  301. _video.y = sh / 2 - _video.height / 2;
  302. _poster.y = sh / 2 - _poster.height / 2;
  303. } else {
  304. // simple resize
  305. _video.width = sw;
  306. _poster.width = sw;
  307. _video.height = sh;
  308. _poster.height = sh;
  309. }
  310. };
  311. // Seek Start
  312. private function seekStart():void {
  313. addEventListener(Event.ENTER_FRAME, updateSeekKnob);
  314. };
  315. // Seek Stop
  316. private function seekStop():void {
  317. removeEventListener(Event.ENTER_FRAME, updateSeekKnob);
  318. };
  319. // Update Seek Knob
  320. private function updateSeekKnob(evt:Event):void {
  321. _seekSlider.seekValue = _stream.time / _duration;
  322. };
  323. // EVENT HANDLERS
  324. // onInit
  325. private function onInit(evt:Event):void {
  326. // Output DEBUGGING
  327. /*
  328. _output = new TextField();
  329. _output.background = true;
  330. _output.selectable = false;
  331. _output.autoSize = TextFieldAutoSize.LEFT;
  332. var fmt:TextFormat = new TextFormat();
  333. fmt.color = 0xFF0000;
  334. fmt.size = 32;
  335. _output.defaultTextFormat = fmt;
  336. addChild(_output);
  337. */
  338. // Prep
  339. this.opaqueBackground = 0x000000;
  340. stage.align = StageAlign.TOP_LEFT;
  341. stage.scaleMode = StageScaleMode.NO_SCALE;
  342. _poster = new Loader();
  343. _poster.mouseEnabled = false;
  344. _currentFile = 0;
  345. // Instantiate video-related objects
  346. _video = new Video();
  347. _connection = new NetConnection();
  348. // External param: playlist
  349. var param:String = root.loaderInfo.parameters.playlist;
  350. if (param != null) {
  351. var xmlLoader:URLLoader = new URLLoader();
  352. var xmlReq:URLRequest = new URLRequest(param);
  353. xmlLoader.load(xmlReq);
  354. xmlLoader.addEventListener(Event.COMPLETE, onXMLLoaded, false, 0, false);
  355. } else {
  356. _playlist = <playlist version="1" xmlns="http://xspf.org/ns/0/">
  357. <trackList></trackList>
  358. </playlist>;
  359. onInitContinue();
  360. }
  361. };
  362. // onInitContinue
  363. private function onInitContinue():void {
  364. var param:String;
  365. var file:String;
  366. var poster:String;
  367. var disableControls:String;
  368. var track:String;
  369. var node:XML;
  370. // External param: video (single file to play)
  371. param = root.loaderInfo.parameters.video;
  372. if (param != null) {
  373. file = param;
  374. } else {
  375. // For testing ...
  376. if (Capabilities.playerType == "StandAlone" || Capabilities.playerType == "External") {
  377. file = "test.flv";
  378. }
  379. }
  380. // External param: poster (stand-in image)
  381. param = root.loaderInfo.parameters.poster;
  382. poster = (param) ? param : "";
  383. // External param: disableControls (per-video option)
  384. param = root.loaderInfo.parameters.disableControls;
  385. disableControls = (getBoolean(param)) ? param : "";
  386. // Prep playlist track-related nodes
  387. track = "<track>";
  388. track += "<location>" + file + "</location>";
  389. track += "<image>" + poster + "</image>";
  390. track += "<extension>";
  391. track += "<options disableControls=\"" + disableControls + "\" />";
  392. track += "</extension>";
  393. track += "</track>";
  394. node = new XML(track);
  395. // If playlist already exists, prepend the single video ...
  396. _ns = new Namespace(_playlist.namespace());
  397. default xml namespace = _ns;
  398. if (_playlist.trackList.children().length() > 0) {
  399. // ... without duplication ...
  400. if (file != null && !playlistContainsFile(file)) {
  401. _playlist.trackList.prependChild(node);
  402. }
  403. } else {
  404. // ... otherwise, append the single video,
  405. // creating a playlist of one
  406. _playlist.trackList.appendChild(node);
  407. }
  408. // Continue instantiating video-related objects
  409. file = _playlist.trackList.track[0].location.toString();
  410. if (file == null) return;
  411. else connect(file);
  412. _stream = new NetStream(_connection);
  413. _video.attachNetStream(_stream);
  414. // Handle video-related events
  415. var listener:Object = new Object();
  416. listener.onMetaData = onMetaData;
  417. _stream.client = listener;
  418. _stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus, false, 0, false);
  419. // Add video and poster to display list,
  420. // set volume, load,
  421. // then build controls
  422. _videoContainer = new Sprite();
  423. _videoContainer.addChild(_video);
  424. addChild(_videoContainer);
  425. addChild(_poster);
  426. //addChild(_output);
  427. setVolume(parseFloat(root.loaderInfo.parameters.volume));
  428. if (getBoolean(root.loaderInfo.parameters.uiAutoHide)) {
  429. _uiHideTimer = new Timer(1200, 1);
  430. }
  431. buildControls();
  432. load(_playlist..track[_currentFile]);
  433. // Housekeeping
  434. this.removeEventListener(Event.ADDED_TO_STAGE, onInit);
  435. _videoContainer.addEventListener(MouseEvent.CLICK, onTogglePlay, false, 0, false);
  436. _poster.contentLoaderInfo.addEventListener(Event.COMPLETE, onPosterLoaded, false, 0, false);
  437. stage.addEventListener(Event.RESIZE, onResize, false, 0, false);
  438. if (getBoolean(root.loaderInfo.parameters.uiAutoHide)) {
  439. _uiHideTimer.addEventListener(TimerEvent.TIMER, onHideControls, false, 0, false);
  440. stage.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverStage, false, 0, false);
  441. stage.addEventListener(Event.MOUSE_LEAVE, onMouseLeaveStage, false, 0, false);
  442. }
  443. onResize();
  444. };
  445. // onXMLLoaded
  446. private function onXMLLoaded(evt:Event):void {
  447. _playlist = XML(evt.target.data);
  448. //_ns = new Namespace(_playlist.namespace());
  449. onInitContinue();
  450. }
  451. // onMetaData
  452. private function onMetaData(evt:Object):void {
  453. _duration = evt.duration;
  454. onResize();
  455. }
  456. // onStatus
  457. private function onStatus(evt:Object):void {
  458. if (evt.info.code == "NetStream.Play.Stop") {
  459. _isPlaying = false;
  460. seekStop();
  461. if (getBoolean(root.loaderInfo.parameters.loop)) {
  462. loadNext();
  463. } else {
  464. _replay = true;
  465. if (_playPauseButton) _playPauseButton.toggle(true);
  466. _overlayPlayButton.show();
  467. }
  468. }
  469. };
  470. // onLoadStream
  471. private function onLoadStream(evt:Event):void {
  472. var val:Number = _stream.bytesLoaded / _stream.bytesTotal;
  473. if (_seekSlider) {
  474. if (val < 1) {
  475. _seekSlider.progressValue = val;
  476. if (_output) _output.text = val.toString();
  477. } else {
  478. _seekSlider.progressValue = 1;
  479. if (_output) _output.text = "";
  480. removeEventListener(Event.ENTER_FRAME, onLoadStream);
  481. }
  482. }
  483. };
  484. // onResize
  485. private function onResize(evt:Event = null):void {
  486. resizeVideo();
  487. resizeControls();
  488. };
  489. // onTogglePlay
  490. private function onTogglePlay(evt:MouseEvent):void {
  491. if (_replay) {
  492. _replay = false;
  493. _stream.seek(0);
  494. _isPlaying = true;
  495. if (_seekSlider) seekStart();
  496. if (_playPauseButton) _playPauseButton.toggle(false);
  497. _overlayPlayButton.hide();
  498. } else {
  499. if (_isPlaying) {
  500. _stream.pause();
  501. if (_seekSlider) seekStop();
  502. if (_playPauseButton) _playPauseButton.toggle(true);
  503. _overlayPlayButton.show();
  504. } else {
  505. _stream.resume();
  506. if (_seekSlider) seekStart();
  507. if (_playPauseButton) _playPauseButton.toggle(false);
  508. _overlayPlayButton.hide();
  509. }
  510. _isPlaying = !_isPlaying;
  511. _poster.unload();
  512. }
  513. };
  514. // onToggleFullScreen
  515. private function onToggleFullScreen(evt:MouseEvent):void {
  516. if (stage.displayState == StageDisplayState.NORMAL) {
  517. stage.displayState = StageDisplayState.FULL_SCREEN;
  518. } else {
  519. stage.displayState = StageDisplayState.NORMAL;
  520. }
  521. resizeControls();
  522. };
  523. // onToggleVolume
  524. private function onToggleVolume(evt:MouseEvent):void {
  525. _volumeBackup = (_volumeBackup > 0) ? _volumeBackup : 1;
  526. _volume = _stream.soundTransform;
  527. if (_volume.volume == 0) {
  528. _volume.volume = _volumeBackup;
  529. if (_volumeSlider) _volumeSlider.volume = _volumeBackup * 100;
  530. } else {
  531. _volume.volume = 0;
  532. if (_volumeSlider) _volumeSlider.volume = 0;
  533. }
  534. _stream.soundTransform = _volume;
  535. _volumeToggleButton.toggle(!_volumeSlider.volume);
  536. };
  537. // onVolumeChange
  538. private function onVolumeChange(evt:Event):void {
  539. setVolume(_volumeSlider.volume);
  540. };
  541. // onSeekMouseDown
  542. private function onSeekMouseDown(evt:MouseEvent):void {
  543. seekStop();
  544. stage.addEventListener(MouseEvent.MOUSE_UP, onSeekMouseUp);
  545. };
  546. // onSeekMouseUp
  547. private function onSeekMouseUp(evt:MouseEvent):void {
  548. stage.removeEventListener(MouseEvent.MOUSE_UP, onSeekMouseUp);
  549. _stream.seek(_duration * _seekSlider.seekValue);
  550. seekStart();
  551. };
  552. // onMouseOverStage
  553. private function onMouseOverStage(evt:MouseEvent):void {
  554. if (getBoolean(root.loaderInfo.parameters.uiAutoHide)) {
  555. if (_controlPanel) {
  556. _uiHideTimer.stop();
  557. _controlPanel.show();
  558. }
  559. }
  560. };
  561. // onMouseLeaveStage
  562. private function onMouseLeaveStage(evt:Event):void {
  563. if (_controlPanel) _uiHideTimer.start();
  564. };
  565. // onControlsTimer
  566. private function onHideControls(evt:TimerEvent):void {
  567. _controlPanel.hide();
  568. };
  569. // onPosterLoaded
  570. private function onPosterLoaded(evt:Event):void {
  571. resizeVideo();
  572. _videoContainer.visible = true;
  573. };
  574. // UTILITIES
  575. // Playlist Contains File?
  576. private function playlistContainsFile(file:String):Boolean {
  577. var verdict:Boolean = false;
  578. var len:int = _playlist..track.length();
  579. for (var i:int = 0; i < len; i++) {
  580. if (_playlist..track[i].location == file) {
  581. verdict = true;
  582. break;
  583. }
  584. }
  585. return verdict;
  586. };
  587. // Get File Name
  588. private function getFileName(str:String, includeExtension:Boolean):String {
  589. var re:RegExp = /\/([\w\d]+)(\.[\w\d]{3,4})$/i;
  590. var result:Object = re.exec(str);
  591. return includeExtension ? result[1] + result[2] : result[1];
  592. };
  593. // Get File Path
  594. private function getFilePath(str:String):String {
  595. return str.substr(0, str.lastIndexOf("/"))
  596. };
  597. // Is HTTP Request?
  598. private function isHTTPRequest(str:String):Boolean {
  599. // Is HTTP if URL fails to contain
  600. // rtmp, rtmpe, rtmps, rtmpt, or rtmpte
  601. var re:RegExp = /rtmp([es]|te?)?:\/\//i;
  602. var result:Object = re.exec(str);
  603. return (result == null);
  604. };
  605. // Get Boolean
  606. private function getBoolean(str:String):Boolean {
  607. return (str == "true") ? true : false;
  608. };
  609. // Get UI Colors
  610. private function getColorsFromParam(str:String):Array {
  611. var re:RegExp = /(?:#|0x?)((?:[a-f0-9]{2}){3})/i;
  612. var result:Object;
  613. var arr:Array = str.split("|");
  614. var len:int = arr.length;
  615. for (var i:int = 0; i < len; i++) {
  616. result = re.exec(arr[i]);
  617. arr[i] = parseInt("0x" + result[1]);
  618. }
  619. return arr;
  620. };
  621. // Min Version Is?
  622. private function minVersionIs(str:String):Boolean {
  623. var verdict:Boolean = false;
  624. var re:RegExp = /[^\d]*(\d+)[,.](\d+)[,.](\d+)[,.](\d+)/;
  625. var minRequired:Object = re.exec(str);
  626. var installed:Object = re.exec(Capabilities.version);
  627. if (parseInt(installed[1]) > parseInt(minRequired[1])) verdict = true;
  628. else if (
  629. parseInt(installed[1]) == parseInt(minRequired[1]) &&
  630. parseInt(installed[3]) >= parseInt(minRequired[3])
  631. ) verdict = true;
  632. return verdict;
  633. }
  634. };
  635. };