PageRenderTime 6648ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/flowplayer/branches/3_0_3_dev/src/actionscript/org/flowplayer/view/Launcher.as

http://flowplayer-core.googlecode.com/
ActionScript | 718 lines | 582 code | 107 blank | 29 comment | 115 complexity | 4d5a02b14ca3e5064f5f3f21b47f04fe MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0
  1. /*
  2. * Copyright (c) 2008, 2009 Flowplayer Oy
  3. *
  4. * This file is part of Flowplayer.
  5. *
  6. * Flowplayer is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Flowplayer is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Flowplayer. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package org.flowplayer.view {
  20. import org.flowplayer.model.Canvas;
  21. import org.flowplayer.model.Loadable;
  22. import org.flowplayer.model.ProviderModel;
  23. import org.flowplayer.config.Config;
  24. import org.flowplayer.config.ConfigLoader;
  25. import org.flowplayer.config.ExternalInterfaceHelper;
  26. import org.flowplayer.config.VersionInfo;
  27. import org.flowplayer.controller.NetStreamControllingStreamProvider;
  28. import org.flowplayer.controller.PlayListController;
  29. import org.flowplayer.controller.ResourceLoader;
  30. import org.flowplayer.controller.ResourceLoaderImpl;
  31. import org.flowplayer.flow_internal;
  32. import org.flowplayer.model.Callable;
  33. import org.flowplayer.model.Clip;
  34. import org.flowplayer.model.ClipEvent;
  35. import org.flowplayer.model.DisplayPluginModel;
  36. import org.flowplayer.model.DisplayProperties;
  37. import org.flowplayer.model.DisplayPropertiesImpl;
  38. import org.flowplayer.model.EventDispatcher;
  39. import org.flowplayer.model.Logo;
  40. import org.flowplayer.model.PlayButtonOverlay;
  41. import org.flowplayer.model.PlayerError;
  42. import org.flowplayer.model.PlayerEvent;
  43. import org.flowplayer.model.Playlist;
  44. import org.flowplayer.model.Plugin;
  45. import org.flowplayer.model.PluginError;
  46. import org.flowplayer.model.PluginEvent;
  47. import org.flowplayer.model.PluginModel;
  48. import org.flowplayer.model.State;
  49. import org.flowplayer.util.Arrange;
  50. import org.flowplayer.util.Log;
  51. import org.flowplayer.util.TextUtil;
  52. import org.flowplayer.util.URLUtil;
  53. import org.flowplayer.view.Panel;
  54. import org.flowplayer.view.Screen;
  55. import org.osflash.thunderbolt.Logger;
  56. import flash.display.DisplayObject;
  57. import flash.display.DisplayObjectContainer;
  58. import flash.display.Sprite;
  59. import flash.events.Event;
  60. import flash.events.KeyboardEvent;
  61. import flash.events.MouseEvent;
  62. import flash.events.TimerEvent;
  63. import flash.net.URLRequest;
  64. import flash.net.navigateToURL;
  65. import flash.system.Capabilities;
  66. import flash.system.Security;
  67. import flash.text.TextField;
  68. import flash.text.TextFieldAutoSize;
  69. import flash.ui.Keyboard;
  70. import flash.utils.Dictionary;
  71. import flash.utils.Timer;
  72. use namespace flow_internal;
  73. public class Launcher extends StyleableSprite implements ErrorHandler {
  74. private var _panel:Panel;
  75. private var _screen:Screen;
  76. private var _config:Config;
  77. private var _flowplayer:Flowplayer;
  78. private var _pluginRegistry:PluginRegistry;
  79. private var _animationEngine:AnimationEngine;
  80. private var _playButtonOverlay:PlayButtonOverlay;
  81. private var _controlsModel:DisplayPluginModel;
  82. private var _providers:Dictionary = new Dictionary();
  83. private var _fullscreenManager:FullscreenManager;
  84. private var _canvasLogo:Sprite;
  85. private var _pluginLoader:PluginLoader;
  86. private var _error:TextField;
  87. private var _pluginsInitialized:Number = 0;
  88. private var _numLoadablePlugins:int = -1;
  89. private var _enteringFullscreen:Boolean;
  90. private var _copyrightNotice:TextField;
  91. [Frame(factoryClass="org.flowplayer.view.Preloader")]
  92. public function Launcher() {
  93. super("#canvas", this);
  94. addEventListener(Event.ADDED_TO_STAGE, initPhase1);
  95. }
  96. private function initPhase1(event:Event):void {
  97. createFlashVarsConfig();
  98. Log.configure(_config.getLogConfiguration());
  99. if (_config.playerId) {
  100. Security.allowDomain(URLUtil.pageUrl);
  101. }
  102. _config.getPlaylist().onBeforeBegin(function(event:ClipEvent):void { hideErrorMessage(); });
  103. loader = createNewLoader();
  104. rootStyle = _config.canvas.style;
  105. stage.addEventListener(Event.RESIZE, onStageResize);
  106. setSize(stage.stageWidth, stage.stageHeight);
  107. if (! VersionInfo.commercial) {
  108. log.debug("Adding logo to canvas");
  109. createLogoForCanvas();
  110. }
  111. log = new Log(this);
  112. EventDispatcher.playerId = _config.playerId;
  113. log.debug("security sandbox type: " + Security.sandboxType);
  114. log.info(VersionInfo.versionInfo());
  115. log.debug("creating Panel");
  116. createPanel();
  117. _pluginRegistry = new PluginRegistry(_panel);
  118. log.debug("Creating animation engine");
  119. createAnimationEngine(_pluginRegistry);
  120. log.debug("creating play button overlay");
  121. createPlayButtonOverlay();
  122. log.debug("creating screen");
  123. createScreen();
  124. loadPluginsIfConfigured();
  125. }
  126. private function initPhase2(pluginsLoadedEvent:Event = null):void {
  127. log.info("initPhase2, all plugins loaded");
  128. _pluginLoader.removeEventListener(Event.COMPLETE, this.initPhase2);
  129. log.debug("creating PlayListController");
  130. _providers = _pluginLoader.providers;
  131. var playListController:PlayListController = createPlayListController();
  132. addPlayListListeners();
  133. createFullscreenManager(playListController.playlist);
  134. log.debug("creating Flowplayer API");
  135. createFlowplayer(playListController);
  136. addScreenToPanel();
  137. if (!validateLicenseKey()) {
  138. createLogoForCanvas();
  139. resizeCanvasLogo();
  140. }
  141. log.debug("creating logo");
  142. createLogo();
  143. contextMenu = new ContextMenuBuilder(_config.playerId, _config.contextMenu).build();
  144. log.debug("initializing ExternalInterface");
  145. if (useExternalInterfade()) {
  146. _flowplayer.initExternalInterface();
  147. }
  148. log.debug("calling onLoad to plugins");
  149. _pluginRegistry.onLoad(_flowplayer);
  150. }
  151. private function initPhase3(event:Event = null):void {
  152. log.info("initPhase3, all plugins initialized");
  153. log.debug("Adding visible plugins to panel");
  154. addPluginsToPanel(_pluginRegistry);
  155. log.debug("arranging screen");
  156. arrangeScreen();
  157. log.debug("dispatching onLoad");
  158. if (useExternalInterfade()) {
  159. _flowplayer.dispatchEvent(PlayerEvent.load("player"));
  160. }
  161. log.debug("starting configured streams");
  162. startStreams();
  163. stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  164. addListeners();
  165. }
  166. private function resizeCanvasLogo():void {
  167. _canvasLogo.alpha = 1;
  168. _canvasLogo.width = 150;
  169. _canvasLogo.scaleY = _canvasLogo.scaleX;
  170. arrangeCanvasLogo();
  171. }
  172. private function useExternalInterfade():Boolean {
  173. log.debug("useExternalInteface: " + (_config.playerId != null));
  174. return _config.playerId != null;
  175. }
  176. private function onStageResize(event:Event = null):void {
  177. setSize(stage.stageWidth, stage.stageHeight);
  178. arrangeCanvasLogo();
  179. }
  180. private function arrangeCanvasLogo():void {
  181. if (!_canvasLogo) return;
  182. _canvasLogo.x = 15;
  183. _canvasLogo.y = stage.stageHeight - (_controlsModel ? _controlsModel.dimensions.height.toPx(stage.stageHeight) + 10 : 10) - _canvasLogo.height - _copyrightNotice.height;
  184. _copyrightNotice.x = 12;
  185. _copyrightNotice.y = _canvasLogo.y + _canvasLogo.height;
  186. }
  187. private function loadPluginsIfConfigured():void {
  188. var plugins:Array = _config.getLoadables();
  189. log.info("will load following plugins: ");
  190. for (var i:Number = 0; i < plugins.length; i++) {
  191. log.info("" + plugins[i]);
  192. }
  193. _pluginLoader = new PluginLoader(URLUtil.playerBaseUrl(loaderInfo), _pluginRegistry, this, useExternalInterfade(), onPluginLoad, onPluginLoadError);
  194. _pluginLoader.addEventListener(Event.COMPLETE, initPhase2);
  195. if (plugins.length == 0) {
  196. log.debug("configuration has no plugins");
  197. initPhase2();
  198. } else {
  199. log.debug("loading plugins and providers");
  200. _pluginLoader.load(plugins);
  201. }
  202. }
  203. private function onPluginLoad(event:PluginEvent):void {
  204. var plugin:PluginModel = event.target as PluginModel;
  205. log.info("plugin " + plugin + " initialized");
  206. checkPluginsInitialized();
  207. }
  208. private function onPluginLoadError(event:PluginEvent):void {
  209. if (! event.hasError(PluginError.INIT_FAILED)) return;
  210. var plugin:PluginModel = event.target as PluginModel;
  211. log.warn("load/init error on " + plugin);
  212. _pluginRegistry.removePlugin(plugin);
  213. checkPluginsInitialized();
  214. }
  215. private function checkPluginsInitialized():void {
  216. var numPlugins:int = getLoadablePluginCount();
  217. if (++_pluginsInitialized == numPlugins) {
  218. log.info("all plugins initialized");
  219. initPhase3();
  220. }
  221. log.info(_pluginsInitialized + " out of " + numPlugins + " plugins initialized (or have failed to load completely)");
  222. }
  223. private function getLoadablePluginCount():int {
  224. return countLoadablePlugins();
  225. // if (_numLoadablePlugins == -1) {
  226. // _numLoadablePlugins = countLoadablePlugins();
  227. // }
  228. // return _numLoadablePlugins;
  229. }
  230. private function countLoadablePlugins():int {
  231. var count:Number = 0;
  232. var loadables:Array = _config.getLoadables();
  233. for (var i:Number = 0; i < loadables.length; i++) {
  234. var plugin:PluginModel = Loadable(loadables[i]).plugin;
  235. var isNonAdHocPlugin:Boolean = (plugin is DisplayPluginModel && DisplayPluginModel(plugin).getDisplayObject() is Plugin) ||
  236. plugin is ProviderModel && ProviderModel(plugin).getProviderObject() is Plugin;
  237. if (Loadable(loadables[i]).loadFailed) {
  238. log.debug("load failed for " + loadables[i]);
  239. count++;
  240. } else if (! plugin) {
  241. log.debug("this plugin is not loaded yet");
  242. count++;
  243. } else if (isNonAdHocPlugin) {
  244. log.debug("will wait for onLoad from plugin " + plugin);
  245. count++;
  246. } else {
  247. log.debug("will NOT wait for onLoad from plugin " + Loadable(loadables[i]).plugin);
  248. }
  249. }
  250. // +1 comes from the playbuttonoverlay
  251. return count + (_playButtonOverlay ? 1 : 0);
  252. }
  253. private function playerSwfName():String {
  254. var url:String = loaderInfo.url;
  255. var lastSlash:Number = url.lastIndexOf("/");
  256. return url.substring(lastSlash + 1, url.indexOf(".swf") + 4);
  257. }
  258. private function validateLicenseKey():Boolean {
  259. try {
  260. return LicenseKey.validate(root.loaderInfo.url, _flowplayer.version, _config.licenseKey, useExternalInterfade());
  261. } catch (e:Error) {
  262. log.warn("License key not accepted, will show flowplayer logo");
  263. }
  264. return false;
  265. }
  266. private function createFullscreenManager(playlist:Playlist):void {
  267. _fullscreenManager = new FullscreenManager(stage, playlist, _panel, _pluginRegistry, _animationEngine);
  268. }
  269. public function showError(message:String):void {
  270. if (! _panel) return;
  271. if (! _config.showErrors) return;
  272. if (_error && _error.parent == this) {
  273. removeChild(_error);
  274. }
  275. _error = TextUtil.createTextField(false);
  276. _error.background = true;
  277. _error.backgroundColor = 0;
  278. _error.textColor = 0xffffff;
  279. _error.autoSize = TextFieldAutoSize.CENTER;
  280. _error.multiline = true;
  281. _error.wordWrap = true;
  282. _error.text = message;
  283. _error.selectable = true;
  284. _error.width = stage.stageWidth - 40;
  285. Arrange.center(_error, stage.stageWidth, stage.stageHeight);
  286. addChild(_error);
  287. createErrorMessageHideTimer();
  288. }
  289. private function createErrorMessageHideTimer():void {
  290. var errorHideTimer:Timer = new Timer(4000, 1);
  291. errorHideTimer.addEventListener(TimerEvent.TIMER_COMPLETE, hideErrorMessage);
  292. errorHideTimer.start();
  293. }
  294. private function hideErrorMessage(event:TimerEvent = null):void {
  295. if (_error && _error.parent == this) {
  296. if (_animationEngine) {
  297. _animationEngine.fadeOut(_error, 1000, function():void { removeChild(_error); });
  298. } else {
  299. removeChild(_error);
  300. }
  301. }
  302. }
  303. public function handleError(error:PlayerError, info:Object = null, throwError:Boolean = true):void {
  304. if (_flowplayer) {
  305. _flowplayer.dispatchError(error, info);
  306. } else {
  307. // initialization is not complete, create a dispatches just to dispatch this error
  308. new PlayerEventDispatcher().dispatchError(error, info);
  309. }
  310. doHandleError(error.code + ": " + error.message + ( info ? ": " + info : ""), throwError);
  311. }
  312. private function doHandleError(message:String, throwError:Boolean = true):void {
  313. if (_config && _config.playerId) {
  314. Logger.error(message);
  315. }
  316. showError(message);
  317. if (throwError && Capabilities.isDebugger) {
  318. throw new Error(message);
  319. }
  320. }
  321. private function createAnimationEngine(pluginRegistry:PluginRegistry):void {
  322. _animationEngine = new AnimationEngine(_panel, pluginRegistry);
  323. }
  324. private function addPluginsToPanel(_pluginRegistry:PluginRegistry):void {
  325. for each (var pluginObj:Object in _pluginRegistry.plugins) {
  326. if (pluginObj is DisplayPluginModel) {
  327. var model:DisplayPluginModel = pluginObj as DisplayPluginModel;
  328. log.debug("adding plugin '"+ model.name +"' to panel: " + model.visible + ", plugin object is " + model.getDisplayObject());
  329. if (model.visible) {
  330. if (model.zIndex == -1) {
  331. model.zIndex = 100;
  332. }
  333. _panel.addView(model.getDisplayObject(), undefined, model);
  334. }
  335. if (model.name == "controls") {
  336. _controlsModel = model;
  337. }
  338. }
  339. }
  340. if (_controlsModel) {
  341. arrangeCanvasLogo();
  342. }
  343. }
  344. private function addScreenToPanel():void {
  345. // if controls visible and screen was not explicitly configured --> place screen on top of controls
  346. var screen:DisplayProperties = _pluginRegistry.getPlugin("screen") as DisplayProperties;
  347. screen.display = "none";
  348. screen.getDisplayObject().visible = false;
  349. _panel.addView(screen.getDisplayObject(), null, screen);
  350. }
  351. private function arrangeScreen():void {
  352. var screen:DisplayProperties = _pluginRegistry.getPlugin("screen") as DisplayProperties;
  353. if (_controlsModel && _controlsModel.visible) {
  354. if (isControlsAlwaysAutoHide() || (_controlsModel.position.bottom.px > 0)) {
  355. log.debug("controls is autoHide or it's in a non-default vertical position, configuring screen to take all available space");
  356. setScreenBottomAndHeight(screen, 100, 0);
  357. } else {
  358. var controlsHeight:Number = _controlsModel.getDisplayObject().height;
  359. var occupiedHeight:Number = screenTopOrBottomConfigured() ? getScreenTopOrBottomPx(screen) : controlsHeight;
  360. log.debug("occupied by controls or screen's configured bottom/top is " + occupiedHeight);
  361. var heightPct:Number = 0;
  362. if (screenTopOrBottomConfigured() && (screen.position.top.pct >= 0 || screen.position.bottom.pct >= 0)) {
  363. heightPct = 100 - Math.abs(50 - (screen.position.top.pct >= 0 ? screen.position.top.pct : screen.position.bottom.pct))*2;
  364. setScreenBottomAndHeight(screen, heightPct, controlsHeight);
  365. } else {
  366. heightPct = ((stage.stageHeight - occupiedHeight) / stage.stageHeight) * 100;
  367. setScreenBottomAndHeight(screen, heightPct, controlsHeight);
  368. }
  369. }
  370. }
  371. log.debug("arranging screen to pos " + screen.position);
  372. screen.display = "block";
  373. screen.getDisplayObject().visible = true;
  374. _pluginRegistry.updateDisplayProperties(screen);
  375. _panel.update(screen.getDisplayObject(), screen);
  376. _panel.draw(screen.getDisplayObject());
  377. }
  378. private function getScreenTopOrBottomPx(screen:DisplayProperties):Number {
  379. var screenConf:Object = _config.getObject("screen");
  380. if (screenConf.hasOwnProperty("top")) return screen.position.top.toPx(stage.stageHeight);
  381. if (screenConf.hasOwnProperty("bottom")) return screen.position.bottom.toPx(stage.stageHeight);
  382. return 0;
  383. }
  384. private function setScreenBottomAndHeight(screen:DisplayProperties, heightPct:Number, bottom:Number = 0):void {
  385. if (! screenTopOrBottomConfigured()) {
  386. log.debug("screen vertical pos not configured, setting bottom to value " + bottom);
  387. screen.bottom = bottom;
  388. } else {
  389. log.debug("using configured top/bottom for screen");
  390. }
  391. var heightConfigured:Boolean = _config.getObject("screen") && _config.getObject("screen").hasOwnProperty("height");
  392. if (! heightConfigured) {
  393. log.debug("screen height not configured, setting it to value " + heightPct + "%");
  394. screen.height = heightPct + "%";
  395. } else {
  396. log.debug("using configured height for screen");
  397. }
  398. }
  399. private function screenTopOrBottomConfigured():Boolean {
  400. var screen:Object = _config.getObject("screen");
  401. if (! screen) return false;
  402. if (screen.hasOwnProperty("top")) return true;
  403. if (screen.hasOwnProperty("bottom")) return true;
  404. return false;
  405. }
  406. private function isControlsAlwaysAutoHide():Boolean {
  407. if (!_controlsModel) return false;
  408. if (!_controlsModel.config) return false;
  409. log.debug("controlsModel.config.auotoHide == always", (_controlsModel.config.autoHide == 'always'));
  410. return _controlsModel.config.autoHide == 'always';
  411. }
  412. private function createFlowplayer(playListController:PlayListController):void {
  413. _flowplayer = new Flowplayer(stage, playListController, _pluginRegistry, _panel,
  414. _animationEngine, this, this, _config, _fullscreenManager, _pluginLoader, URLUtil.playerBaseUrl(loaderInfo));
  415. playListController.playerEventDispatcher = _flowplayer;
  416. _flowplayer.onBeforeFullscreen(onFullscreen);
  417. // _flowplayer.onFullscreenExit(onFullscreen);
  418. }
  419. private function onFullscreen(event:PlayerEvent):void {
  420. log.debug("entering fullscreen, disabling display clicks");
  421. _enteringFullscreen = true;
  422. var delay:Timer = new Timer(1000, 1);
  423. delay.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
  424. delay.start();
  425. }
  426. private function onTimerComplete(event:TimerEvent):void {
  427. log.debug("fullscreen wait delay complete, display clicks are enabled again");
  428. _enteringFullscreen = false;
  429. }
  430. private function createFlashVarsConfig():void {
  431. for (var prop:String in stage.loaderInfo.parameters) {
  432. log.debug(prop + ": " + (stage.loaderInfo.parameters[prop]));
  433. }
  434. if (! stage.loaderInfo.parameters) {
  435. return;
  436. }
  437. _config = ConfigLoader.flow_internal::parseConfig(stage.loaderInfo.parameters["config"], playerSwfName(), VersionInfo.controlsVersion, VersionInfo.audioVersion);
  438. }
  439. private function createPlayListController():PlayListController {
  440. if (! _providers) {
  441. _providers = new Dictionary();
  442. }
  443. var httpProvider:NetStreamControllingStreamProvider = new NetStreamControllingStreamProvider();
  444. httpProvider.playerConfig = _config;
  445. _providers["http"] = httpProvider;
  446. return new PlayListController(_config.getPlaylist(), _providers, _config, createNewLoader());
  447. }
  448. private function createScreen():void {
  449. _screen = new Screen(_config.getPlaylist(), _animationEngine, _playButtonOverlay, _pluginRegistry);
  450. var screenModel:DisplayProperties = _config.getScreenProperties();
  451. initView(_screen, screenModel, null, false);
  452. if (_playButtonOverlay) {
  453. PlayButtonOverlayView(_playButtonOverlay.getDisplayObject()).setScreen(_screen, hasClip);
  454. }
  455. // addViewLiteners(_screen);
  456. }
  457. private function createPlayButtonOverlay():void {
  458. _playButtonOverlay = _config.getPlayButtonOverlay();
  459. if (! _playButtonOverlay) return;
  460. _playButtonOverlay.onLoad(onPluginLoad);
  461. _playButtonOverlay.onError(onPluginLoadError);
  462. log.debug("playlist has clips? " + hasClip);
  463. var overlay:PlayButtonOverlayView = new PlayButtonOverlayView(! playButtonOverlayWidthDefined(), _playButtonOverlay, _pluginRegistry, _config.getPlaylist());
  464. initView(overlay, _playButtonOverlay, null, false);
  465. }
  466. private function playButtonOverlayWidthDefined():Boolean {
  467. if (! _config.getObject("play")) return false;
  468. return _config.getObject("play").hasOwnProperty("width");
  469. }
  470. private function get hasClip():Boolean {
  471. var firstClip:Clip = _config.getPlaylist().current;
  472. var hasClip:Boolean = ! firstClip.isNullClip && (firstClip.url || firstClip.provider != 'http');
  473. return hasClip;
  474. }
  475. private function createLogo():void {
  476. var logo:Logo = _config.getLogo() || new Logo();
  477. var logoView:LogoView = new LogoView(_panel, logo, _flowplayer);
  478. initView(logoView, logo, logoView.draw, false);
  479. }
  480. private function initView(view:DisplayObject, props:DisplayProperties, resizeListener:Function = null, addToPanel:Boolean = true):void {
  481. if (props.name != "logo" || VersionInfo.commercial) {
  482. _pluginRegistry.registerDisplayPlugin(props, view);
  483. }
  484. if (addToPanel) {
  485. _panel.addView(view, resizeListener, props);
  486. }
  487. if (props is Callable) {
  488. ExternalInterfaceHelper.initializeInterface(props as Callable, view);
  489. }
  490. }
  491. private function addListeners():void {
  492. _screen.addEventListener(MouseEvent.CLICK, onViewClicked);
  493. addEventListener(MouseEvent.ROLL_OVER, onMouseOver);
  494. addEventListener(MouseEvent.ROLL_OUT, onMouseOut);
  495. // add some color so that the ROLL_OVER/ROLL_OUT events are always triggered
  496. graphics.beginFill(0, 0);
  497. graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
  498. graphics.endFill();
  499. }
  500. private function onMouseOut(event:MouseEvent):void {
  501. _flowplayer.dispatchEvent(PlayerEvent.mouseOut());
  502. }
  503. private function onMouseOver(event:MouseEvent):void {
  504. _flowplayer.dispatchEvent(PlayerEvent.mouseOver());
  505. }
  506. private function createPanel():void {
  507. _panel = new Panel();
  508. addChild(_panel);
  509. }
  510. private function startStreams():void {
  511. var canStart:Boolean = true;
  512. if (_flowplayer.state != State.WAITING) {
  513. log.debug("streams have been started in player.onLoad(), will not start streams here.");
  514. canStart = false;
  515. }
  516. if (! hasClip) {
  517. log.info("Configuration has no clips to play.");
  518. canStart = false;
  519. }
  520. var playButton:PlayButtonOverlayView = _playButtonOverlay ? PlayButtonOverlayView(_playButtonOverlay.getDisplayObject()) : null;
  521. if (canStart) {
  522. if (_flowplayer.currentClip.autoPlay) {
  523. log.debug("clip is autoPlay");
  524. _flowplayer.play();
  525. } else if (_flowplayer.currentClip.autoBuffering) {
  526. log.debug("clip is autoBuffering");
  527. _flowplayer.startBuffering();
  528. } else {
  529. if (playButton) {
  530. playButton.stopBuffering();
  531. playButton.showButton();
  532. }
  533. }
  534. } else {
  535. // cannot start playing here, stop buffering indicator, don't show the button
  536. if (playButton) {
  537. playButton.stopBuffering();
  538. }
  539. }
  540. }
  541. private function addPlayListListeners():void {
  542. var playlist:Playlist = _config.getPlaylist();
  543. playlist.onError(onClipError);
  544. }
  545. private function onClipError(event:ClipEvent):void {
  546. doHandleError(event.info + ", " + event.info2 + ", " + event.info3 + ", clip: '" + Clip(event.target) + "'");
  547. }
  548. private function onViewClicked(event:MouseEvent):void {
  549. if (_enteringFullscreen) return;
  550. log.debug("onViewClicked, target " + event.target + ", current target " + event.currentTarget);
  551. if (_playButtonOverlay && isParent(DisplayObject(event.target), _playButtonOverlay.getDisplayObject())) {
  552. _flowplayer.toggle();
  553. } else if (isParent(DisplayObject(event.target), _screen)) {
  554. log.debug("screen clicked");
  555. var clip:Clip = _flowplayer.playlist.current;
  556. if (clip.linkUrl) {
  557. log.debug("opening linked page");
  558. _flowplayer.pause();
  559. navigateToURL(new URLRequest(clip.linkUrl), clip.linkWindow);
  560. return;
  561. }
  562. _flowplayer.toggle();
  563. }
  564. event.stopPropagation();
  565. }
  566. private function isParent(child:DisplayObject, parent:DisplayObject):Boolean {
  567. if (DisplayObject(child).parent == parent) return true;
  568. if (! (parent is DisplayObjectContainer)) return false;
  569. for (var i:Number = 0;i < DisplayObjectContainer(parent).numChildren; i++) {
  570. var curChild:DisplayObject = DisplayObjectContainer(parent).getChildAt(i);
  571. if (isParent(child, curChild)) {
  572. return true;
  573. }
  574. }
  575. return false;
  576. }
  577. private function onKeyDown(event:KeyboardEvent):void {
  578. log.debug("keydown");
  579. if (_enteringFullscreen) return;
  580. if (_flowplayer.dispatchBeforeEvent(PlayerEvent.keyPress(event.keyCode))) {
  581. _flowplayer.dispatchEvent(PlayerEvent.keyPress(event.keyCode));
  582. if (event.keyCode == Keyboard.SPACE) {
  583. _flowplayer.toggle();
  584. }
  585. }
  586. }
  587. override protected function onRedraw():void {
  588. if (bgImageHolder && getChildIndex(bgImageHolder) > getChildIndex(_panel)) {
  589. swapChildren(bgImageHolder, _panel);
  590. }
  591. }
  592. private function createLogoForCanvas():void {
  593. if (_canvasLogo) return;
  594. _copyrightNotice = LogoUtil.createCopyrightNotice(8);
  595. addChild(_copyrightNotice);
  596. _canvasLogo = new CanvasLogo();
  597. _canvasLogo.width = 85;
  598. _canvasLogo.scaleY = _canvasLogo.scaleX;
  599. _canvasLogo.alpha = .4;
  600. _canvasLogo.addEventListener(MouseEvent.CLICK,
  601. function(event:MouseEvent):void { navigateToURL(new URLRequest("http://flowplayer.org"), "_self"); });
  602. _canvasLogo.buttonMode = true;
  603. log.debug("adding logo to display list");
  604. addChild(_canvasLogo);
  605. onStageResize();
  606. }
  607. private function createNewLoader():ResourceLoader {
  608. return new ResourceLoaderImpl(_config.playerId ? null : URLUtil.playerBaseUrl(loaderInfo), this);
  609. }
  610. }
  611. }