annotate johndyer-mediaelement-13fa20a/src/flash/FlashMediaElement.as @ 25:4a4bd554b4c1 tip

Closing this sub branch.
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Mon, 25 Mar 2013 14:02:54 +0000
parents 032bc65ebafc
children
rev   line source
gyorgy@0 1 package
gyorgy@0 2 {
gyorgy@0 3 import flash.display.*;
gyorgy@0 4 import flash.events.*;
gyorgy@0 5 import flash.media.*;
gyorgy@0 6 import flash.net.*;
gyorgy@0 7 import flash.text.*;
gyorgy@0 8 import flash.system.*;
gyorgy@0 9
gyorgy@0 10 import flash.media.Video;
gyorgy@0 11 import flash.net.NetConnection;
gyorgy@0 12 import flash.net.NetStream;
gyorgy@0 13
gyorgy@0 14 import flash.filters.DropShadowFilter;
gyorgy@0 15 import flash.utils.Timer;
gyorgy@0 16 import flash.external.ExternalInterface;
gyorgy@0 17 import flash.geom.Rectangle;
gyorgy@0 18
gyorgy@0 19 import htmlelements.IMediaElement;
gyorgy@0 20 import htmlelements.VideoElement;
gyorgy@0 21 import htmlelements.AudioElement;
gyorgy@0 22
gyorgy@0 23 public class FlashMediaElement extends MovieClip {
gyorgy@0 24
gyorgy@0 25 private var _mediaUrl:String;
gyorgy@0 26 private var _autoplay:Boolean;
gyorgy@0 27 private var _preload:String;
gyorgy@0 28 private var _debug:Boolean;
gyorgy@0 29 private var _isVideo:Boolean;
gyorgy@0 30 private var _video:Video;
gyorgy@0 31 private var _timerRate:Number;
gyorgy@0 32 private var _stageWidth:Number;
gyorgy@0 33 private var _stageHeight:Number;
gyorgy@0 34 private var _enableSmoothing:Boolean;
gyorgy@0 35 private var _allowedPluginDomain:String;
gyorgy@0 36 private var _isFullScreen:Boolean = false;
gyorgy@0 37 private var _startVolume:Number;
gyorgy@0 38
gyorgy@0 39 // native video size (from meta data)
gyorgy@0 40 private var _nativeVideoWidth:Number = 0;
gyorgy@0 41 private var _nativeVideoHeight:Number = 0;
gyorgy@0 42
gyorgy@0 43 // visual elements
gyorgy@0 44 private var _output:TextField;
gyorgy@0 45 private var _fullscreenButton:SimpleButton;
gyorgy@0 46
gyorgy@0 47 // media
gyorgy@0 48 private var _mediaElement:IMediaElement;
gyorgy@0 49
gyorgy@0 50 // connection to fullscreen
gyorgy@0 51 private var _connection:LocalConnection;
gyorgy@0 52 private var _connectionName:String;
gyorgy@0 53
gyorgy@0 54 //private var fullscreen_btn:SimpleButton;
gyorgy@0 55
gyorgy@0 56 // CONTROLS
gyorgy@0 57 private var _showControls:Boolean;
gyorgy@0 58 private var _controlBar:MovieClip;
gyorgy@0 59 private var _controlBarBg:MovieClip;
gyorgy@0 60 private var _playButton:SimpleButton;
gyorgy@0 61 private var _pauseButton:SimpleButton;
gyorgy@0 62 private var _duration:TextField;
gyorgy@0 63 private var _currentTime:TextField;
gyorgy@0 64
gyorgy@0 65
gyorgy@0 66 public function FlashMediaElement() {
gyorgy@0 67
gyorgy@0 68 // show allow this player to be called from a different domain than the HTML page hosting the player
gyorgy@0 69 Security.allowDomain("*");
gyorgy@0 70
gyorgy@0 71 // get parameters
gyorgy@0 72 var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
gyorgy@0 73 _mediaUrl = (params['file'] != undefined) ? String(params['file']) : "";
gyorgy@0 74 _autoplay = (params['autoplay'] != undefined) ? (String(params['autoplay']) == "true") : false;
gyorgy@0 75 _debug = (params['debug'] != undefined) ? (String(params['debug']) == "true") : false;
gyorgy@0 76 _isVideo = (params['isvideo'] != undefined) ? ((String(params['isvideo']) == "false") ? false : true ) : true;
gyorgy@0 77 _timerRate = (params['timerrate'] != undefined) ? (parseInt(params['timerrate'], 10)) : 250;
gyorgy@0 78 _showControls = (params['controls'] != undefined) ? (String(params['controls']) == "true") : false;
gyorgy@0 79 _enableSmoothing = (params['smoothing'] != undefined) ? (String(params['smoothing']) == "true") : false;
gyorgy@0 80 _startVolume = (params['startvolume'] != undefined) ? (parseFloat(params['startvolume'])) : 0.8;
gyorgy@0 81 _preload = (params['preload'] != undefined) ? params['preload'] : "none";
gyorgy@0 82
gyorgy@0 83 if (isNaN(_timerRate))
gyorgy@0 84 _timerRate = 250;
gyorgy@0 85
gyorgy@0 86 // setup stage and player sizes/scales
gyorgy@0 87 stage.align = StageAlign.TOP_LEFT;
gyorgy@0 88 stage.scaleMode = StageScaleMode.NO_SCALE;
gyorgy@0 89 _stageWidth = stage.stageWidth;
gyorgy@0 90 _stageHeight = stage.stageHeight;
gyorgy@0 91
gyorgy@0 92 //_autoplay = true;
gyorgy@0 93 //_mediaUrl = "http://mediafiles.dts.edu/chapel/mp4/20100609.mp4";
gyorgy@0 94 //_mediaUrl = "../media/Parades-PastLives.mp3";
gyorgy@0 95 //_mediaUrl = "../media/echo-hereweare.mp4";
gyorgy@0 96
gyorgy@0 97 //_mediaUrl = "http://video.ted.com/talks/podcast/AlGore_2006_480.mp4";
gyorgy@0 98 //_mediaUrl = "rtmp://stream2.france24.yacast.net/france24_live/en/f24_liveen";
gyorgy@0 99
gyorgy@0 100 //_debug=true;
gyorgy@0 101
gyorgy@0 102 // position and hide
gyorgy@0 103 _fullscreenButton = getChildByName("fullscreen_btn") as SimpleButton;
gyorgy@0 104 _fullscreenButton.visible = false;
gyorgy@0 105 _fullscreenButton.addEventListener(MouseEvent.CLICK, fullscreenClick, false);
gyorgy@0 106 _fullscreenButton.x = stage.stageWidth - _fullscreenButton.width - 10;
gyorgy@0 107 _fullscreenButton.y = 10;
gyorgy@0 108
gyorgy@0 109 // create media element
gyorgy@0 110 if (_isVideo) {
gyorgy@0 111 _mediaElement = new VideoElement(this, _autoplay, _preload, _timerRate, _startVolume);
gyorgy@0 112 _video = (_mediaElement as VideoElement).video;
gyorgy@0 113 _video.width = _stageWidth;
gyorgy@0 114 _video.height = _stageHeight;
gyorgy@0 115 _video.smoothing = _enableSmoothing;
gyorgy@0 116 //_video.scaleMode = VideoScaleMode.MAINTAIN_ASPECT_RATIO;
gyorgy@0 117 addChild(_video);
gyorgy@0 118 } else {
gyorgy@0 119 _mediaElement = new AudioElement(this, _autoplay, _preload, _timerRate, _startVolume);
gyorgy@0 120 }
gyorgy@0 121
gyorgy@0 122 // debugging
gyorgy@0 123 _output = new TextField();
gyorgy@0 124 _output.textColor = 0xeeeeee;
gyorgy@0 125 _output.width = stage.stageWidth - 100;
gyorgy@0 126 _output.height = stage.stageHeight;
gyorgy@0 127 _output.multiline = true;
gyorgy@0 128 _output.wordWrap = true;
gyorgy@0 129 _output.border = false;
gyorgy@0 130 _output.filters = [new DropShadowFilter(1, 0x000000, 45, 1, 2, 2, 1)];
gyorgy@0 131
gyorgy@0 132 _output.text = "Initializing...\n";
gyorgy@0 133 addChild(_output);
gyorgy@0 134 _output.visible = _debug;
gyorgy@0 135
gyorgy@0 136 // controls!
gyorgy@0 137 _controlBar = getChildByName("controls_mc") as MovieClip;
gyorgy@0 138 _controlBarBg = _controlBar.getChildByName("controls_bg_mc") as MovieClip;
gyorgy@0 139 _playButton = _controlBar.getChildByName("play_btn") as SimpleButton;
gyorgy@0 140 _playButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent) {
gyorgy@0 141 _mediaElement.play();
gyorgy@0 142 });
gyorgy@0 143 _pauseButton = _controlBar.getChildByName("pause_btn") as SimpleButton;
gyorgy@0 144 _pauseButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent) {
gyorgy@0 145 _mediaElement.pause();
gyorgy@0 146 });
gyorgy@0 147 _pauseButton.visible = false;
gyorgy@0 148 _duration = _controlBar.getChildByName("duration_txt") as TextField;
gyorgy@0 149 _currentTime = _controlBar.getChildByName("currentTime_txt") as TextField;
gyorgy@0 150
gyorgy@0 151 _controlBar.visible = _showControls;
gyorgy@0 152 addChild(_controlBar);
gyorgy@0 153
gyorgy@0 154 // put back on top
gyorgy@0 155 addChild(_fullscreenButton);
gyorgy@0 156 //_fullscreenButton.alpha = 0;
gyorgy@0 157 _fullscreenButton.visible = false;
gyorgy@0 158
gyorgy@0 159 _output.appendText("stage: " + stage.stageWidth + "x" + stage.stageHeight + "\n");
gyorgy@0 160 _output.appendText("file: " + _mediaUrl + "\n");
gyorgy@0 161 _output.appendText("autoplay: " + _autoplay.toString() + "\n");
gyorgy@0 162 _output.appendText("preload: " + _preload.toString() + "\n");
gyorgy@0 163 _output.appendText("isvideo: " + _isVideo.toString() + "\n");
gyorgy@0 164 _output.appendText("smoothing: " + _enableSmoothing.toString() + "\n");
gyorgy@0 165 _output.appendText("timerrate: " + _timerRate.toString() + "\n");
gyorgy@0 166 _output.appendText("displayState: " +(stage.hasOwnProperty("displayState")).toString() + "\n");
gyorgy@0 167
gyorgy@0 168 // attach javascript
gyorgy@0 169 _output.appendText("ExternalInterface.available: " + ExternalInterface.available.toString() + "\n");
gyorgy@0 170 _output.appendText("ExternalInterface.objectID: " + ((ExternalInterface.objectID != null)? ExternalInterface.objectID.toString() : "null") + "\n");
gyorgy@0 171
gyorgy@0 172 if (_mediaUrl != "") {
gyorgy@0 173 _mediaElement.setSrc(_mediaUrl);
gyorgy@0 174 }
gyorgy@0 175
gyorgy@0 176 positionControls();
gyorgy@0 177
gyorgy@0 178 if (ExternalInterface.available) { // && !_showControls
gyorgy@0 179
gyorgy@0 180 _output.appendText("Adding callbacks...\n");
gyorgy@0 181 try {
gyorgy@0 182 if (ExternalInterface.objectID != null && ExternalInterface.objectID.toString() != "") {
gyorgy@0 183
gyorgy@0 184 // add HTML media methods
gyorgy@0 185 ExternalInterface.addCallback("playMedia", playMedia);
gyorgy@0 186 ExternalInterface.addCallback("loadMedia", loadMedia);
gyorgy@0 187 ExternalInterface.addCallback("pauseMedia", pauseMedia);
gyorgy@0 188 ExternalInterface.addCallback("stopMedia", stopMedia);
gyorgy@0 189
gyorgy@0 190 ExternalInterface.addCallback("setSrc", setSrc);
gyorgy@0 191 ExternalInterface.addCallback("setCurrentTime", setCurrentTime);
gyorgy@0 192 ExternalInterface.addCallback("setVolume", setVolume);
gyorgy@0 193 ExternalInterface.addCallback("setMuted", setMuted);
gyorgy@0 194
gyorgy@0 195 ExternalInterface.addCallback("setFullscreen", setFullscreen);
gyorgy@0 196 ExternalInterface.addCallback("setVideoSize", setVideoSize);
gyorgy@0 197
gyorgy@0 198 // fire init method
gyorgy@0 199 ExternalInterface.call("mejs.MediaPluginBridge.initPlugin", ExternalInterface.objectID);
gyorgy@0 200 }
gyorgy@0 201
gyorgy@0 202 _output.appendText("Success...\n");
gyorgy@0 203
gyorgy@0 204 } catch (error:SecurityError) {
gyorgy@0 205 _output.appendText("A SecurityError occurred: " + error.message + "\n");
gyorgy@0 206 } catch (error:Error) {
gyorgy@0 207 _output.appendText("An Error occurred: " + error.message + "\n");
gyorgy@0 208 }
gyorgy@0 209
gyorgy@0 210 }
gyorgy@0 211
gyorgy@0 212 if (_preload != "none") {
gyorgy@0 213 _mediaElement.load();
gyorgy@0 214
gyorgy@0 215 if (_autoplay) {
gyorgy@0 216 _mediaElement.play();
gyorgy@0 217 }
gyorgy@0 218 } else if (_autoplay) {
gyorgy@0 219 _mediaElement.load();
gyorgy@0 220 _mediaElement.play();
gyorgy@0 221 }
gyorgy@0 222
gyorgy@0 223
gyorgy@0 224
gyorgy@0 225
gyorgy@0 226 // connection to full screen
gyorgy@0 227 //_connection = new LocalConnection();
gyorgy@0 228 //_connection.client = this;
gyorgy@0 229 //_connection.connect(ExternalInterface.objectID + "_player");
gyorgy@0 230
gyorgy@0 231 // listen for rezie
gyorgy@0 232 stage.addEventListener(Event.RESIZE, resizeHandler);
gyorgy@0 233
gyorgy@0 234 // test
gyorgy@0 235 stage.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
gyorgy@0 236
gyorgy@0 237 // resize
gyorgy@0 238 stage.addEventListener(FullScreenEvent.FULL_SCREEN, stageFullScreen);
gyorgy@0 239 }
gyorgy@0 240
gyorgy@0 241 function clickHandler(e:MouseEvent):void {
gyorgy@0 242 //_output.appendText("click: " + e.stageX.toString() +","+e.stageY.toString() + "\n");
gyorgy@0 243 sendEvent("click", "");
gyorgy@0 244 }
gyorgy@0 245
gyorgy@0 246 function resizeHandler(e:Event):void {
gyorgy@0 247 //_video.scaleX = stage.stageWidth / _stageWidth;
gyorgy@0 248 //_video.scaleY = stage.stageHeight / _stageHeight;
gyorgy@0 249 //positionControls();
gyorgy@0 250
gyorgy@0 251 repositionVideo();
gyorgy@0 252 }
gyorgy@0 253
gyorgy@0 254 // START: Fullscreen
gyorgy@0 255
gyorgy@0 256 // for local connection
gyorgy@0 257 public function goFullscreen():void {
gyorgy@0 258 setFullscreen(true);
gyorgy@0 259 }
gyorgy@0 260
gyorgy@0 261
gyorgy@0 262 function setFullscreen(gofullscreen:Boolean) {
gyorgy@0 263
gyorgy@0 264 try {
gyorgy@0 265 //_fullscreenButton.visible = false;
gyorgy@0 266
gyorgy@0 267 if (gofullscreen) {
gyorgy@0 268 var screenRectangle:Rectangle = new Rectangle(_video.x, _video.y, flash.system.Capabilities.screenResolutionX, flash.system.Capabilities.screenResolutionY);
gyorgy@0 269 stage.fullScreenSourceRect = screenRectangle;
gyorgy@0 270
gyorgy@0 271 stage.displayState = StageDisplayState.FULL_SCREEN;
gyorgy@0 272 _isFullScreen = true;
gyorgy@0 273
gyorgy@0 274 } else {
gyorgy@0 275 stage.displayState = StageDisplayState.NORMAL;
gyorgy@0 276 _isFullScreen = false;
gyorgy@0 277 }
gyorgy@0 278
gyorgy@0 279 } catch (error:Error) {
gyorgy@0 280
gyorgy@0 281 // show the button when the security error doesn't let it work
gyorgy@0 282 _fullscreenButton.visible = true;
gyorgy@0 283
gyorgy@0 284 _isFullScreen = false;
gyorgy@0 285
gyorgy@0 286 _output.appendText("error setting fullscreen: " + error.toString() + "\n");
gyorgy@0 287 }
gyorgy@0 288 }
gyorgy@0 289
gyorgy@0 290 function fullscreenClick(e:MouseEvent) {
gyorgy@0 291 _fullscreenButton.visible = false;
gyorgy@0 292
gyorgy@0 293 try {
gyorgy@0 294 _controlBar.visible = true;
gyorgy@0 295 setFullscreen(true);
gyorgy@0 296 repositionVideo(true);
gyorgy@0 297 } catch (error:Error) {
gyorgy@0 298 }
gyorgy@0 299 }
gyorgy@0 300
gyorgy@0 301 function stageFullScreen(e:FullScreenEvent) {
gyorgy@0 302 _output.appendText("fullscreen event: " + e.fullScreen.toString() + "\n");
gyorgy@0 303
gyorgy@0 304 _fullscreenButton.visible = false;
gyorgy@0 305 _isFullScreen = e.fullScreen;
gyorgy@0 306
gyorgy@0 307 if (!e.fullScreen) {
gyorgy@0 308 _controlBar.visible = _showControls;
gyorgy@0 309 }
gyorgy@0 310 }
gyorgy@0 311 // END: Fullscreen
gyorgy@0 312
gyorgy@0 313 function playMedia() {
gyorgy@0 314 _output.appendText("play\n");
gyorgy@0 315 _mediaElement.play();
gyorgy@0 316 }
gyorgy@0 317
gyorgy@0 318 function loadMedia() {
gyorgy@0 319 _output.appendText("load\n");
gyorgy@0 320 _mediaElement.load();
gyorgy@0 321 }
gyorgy@0 322
gyorgy@0 323 function pauseMedia() {
gyorgy@0 324 _output.appendText("pause\n");
gyorgy@0 325 _mediaElement.pause();
gyorgy@0 326 }
gyorgy@0 327
gyorgy@0 328 function setSrc(url:String) {
gyorgy@0 329 _output.appendText("setSrc: " + url + "\n");
gyorgy@0 330 _mediaElement.setSrc(url);
gyorgy@0 331 }
gyorgy@0 332
gyorgy@0 333 function stopMedia() {
gyorgy@0 334 _output.appendText("stop\n");
gyorgy@0 335 _mediaElement.stop();
gyorgy@0 336 }
gyorgy@0 337
gyorgy@0 338 function setCurrentTime(time:Number) {
gyorgy@0 339 _output.appendText("seek: " + time.toString() + "\n");
gyorgy@0 340 _mediaElement.setCurrentTime(time);
gyorgy@0 341 }
gyorgy@0 342
gyorgy@0 343 function setVolume(volume:Number) {
gyorgy@0 344 _output.appendText("volume: " + volume.toString() + "\n");
gyorgy@0 345 _mediaElement.setVolume(volume);
gyorgy@0 346 }
gyorgy@0 347
gyorgy@0 348 function setMuted(muted:Boolean) {
gyorgy@0 349 _output.appendText("muted: " + muted.toString() + "\n");
gyorgy@0 350 _mediaElement.setMuted(muted);
gyorgy@0 351 }
gyorgy@0 352
gyorgy@0 353 function setVideoSize(width:Number, height:Number) {
gyorgy@0 354 _output.appendText("setVideoSize: " + width.toString() + "," + height.toString() + "\n");
gyorgy@0 355
gyorgy@0 356 _stageWidth = width;
gyorgy@0 357 _stageHeight = height;
gyorgy@0 358
gyorgy@0 359 if (_video != null) {
gyorgy@0 360 repositionVideo();
gyorgy@0 361 _fullscreenButton.x = stage.stageWidth - _fullscreenButton.width - 10;
gyorgy@0 362 }
gyorgy@0 363
gyorgy@0 364 _output.appendText("result: " + _video.width.toString() + "," + _video.height.toString() + "\n");
gyorgy@0 365 }
gyorgy@0 366
gyorgy@0 367 function repositionVideo(fullscreen:Boolean = false):void {
gyorgy@0 368
gyorgy@0 369 if (_nativeVideoWidth <= 0 || _nativeVideoHeight <= 0)
gyorgy@0 370 return;
gyorgy@0 371
gyorgy@0 372 _output.appendText("positioning video\n");
gyorgy@0 373
gyorgy@0 374 // calculate ratios
gyorgy@0 375 var stageRatio, nativeRatio;
gyorgy@0 376
gyorgy@0 377 if(fullscreen == true) {
gyorgy@0 378 stageRatio = flash.system.Capabilities.screenResolutionX/flash.system.Capabilities.screenResolutionY;
gyorgy@0 379 nativeRatio = _nativeVideoWidth/_nativeVideoHeight;
gyorgy@0 380
gyorgy@0 381 // adjust size and position
gyorgy@0 382 if (nativeRatio > stageRatio) {
gyorgy@0 383 _video.width = flash.system.Capabilities.screenResolutionX;
gyorgy@0 384 _video.height = _nativeVideoHeight * flash.system.Capabilities.screenResolutionX / _nativeVideoWidth;
gyorgy@0 385 _video.y = flash.system.Capabilities.screenResolutionY/2 - _video.height/2;
gyorgy@0 386 } else if (stageRatio > nativeRatio) {
gyorgy@0 387 _video.height = flash.system.Capabilities.screenResolutionY;
gyorgy@0 388 _video.width = _nativeVideoWidth * flash.system.Capabilities.screenResolutionY / _nativeVideoHeight;
gyorgy@0 389 _video.x = flash.system.Capabilities.screenResolutionX/2 - _video.width/2;
gyorgy@0 390 } else if (stageRatio == nativeRatio) {
gyorgy@0 391 _video.height = flash.system.Capabilities.screenResolutionY;
gyorgy@0 392 _video.width = flash.system.Capabilities.screenResolutionX;
gyorgy@0 393 _video.x = 0;
gyorgy@0 394 _video.y = 0;
gyorgy@0 395 }
gyorgy@0 396 } else {
gyorgy@0 397 stageRatio = _stageWidth/_stageHeight;
gyorgy@0 398 nativeRatio = _nativeVideoWidth/_nativeVideoHeight;
gyorgy@0 399
gyorgy@0 400 // adjust size and position
gyorgy@0 401 if (nativeRatio > stageRatio) {
gyorgy@0 402 _video.width = _stageWidth;
gyorgy@0 403 _video.height = _nativeVideoHeight * _stageWidth / _nativeVideoWidth;
gyorgy@0 404 _video.y = _stageHeight/2 - _video.height/2;
gyorgy@0 405 } else if (stageRatio > nativeRatio) {
gyorgy@0 406 _video.height = _stageHeight;
gyorgy@0 407 _video.width = _nativeVideoWidth * _stageHeight / _nativeVideoHeight;
gyorgy@0 408 _video.x = _stageWidth/2 - _video.width/2;
gyorgy@0 409 } else if (stageRatio == nativeRatio) {
gyorgy@0 410 _video.height = _stageHeight;
gyorgy@0 411 _video.width = _stageWidth;
gyorgy@0 412 _video.x = 0;
gyorgy@0 413 _video.y = 0;
gyorgy@0 414 }
gyorgy@0 415 }
gyorgy@0 416
gyorgy@0 417 positionControls();
gyorgy@0 418 }
gyorgy@0 419
gyorgy@0 420 // SEND events to JavaScript
gyorgy@0 421 public function sendEvent(eventName:String, eventValues:String) {
gyorgy@0 422
gyorgy@0 423 // special video event
gyorgy@0 424 if (eventName == HtmlMediaEvent.LOADEDMETADATA && _isVideo) {
gyorgy@0 425 _nativeVideoWidth = (_mediaElement as VideoElement).videoWidth;
gyorgy@0 426 _nativeVideoHeight = (_mediaElement as VideoElement).videoHeight;
gyorgy@0 427
gyorgy@0 428 repositionVideo();
gyorgy@0 429 }
gyorgy@0 430
gyorgy@0 431 // update controls
gyorgy@0 432 switch (eventName) {
gyorgy@0 433 case "pause":
gyorgy@0 434 case "paused":
gyorgy@0 435 case "ended":
gyorgy@0 436 _playButton.visible = true;
gyorgy@0 437 _pauseButton.visible = false;
gyorgy@0 438 break;
gyorgy@0 439 case "play":
gyorgy@0 440 case "playing":
gyorgy@0 441 _playButton.visible = false;
gyorgy@0 442 _pauseButton.visible = true;
gyorgy@0 443 break;
gyorgy@0 444 }
gyorgy@0 445 _duration.text = secondsToTimeCode(_mediaElement.duration());
gyorgy@0 446 _currentTime.text = secondsToTimeCode(_mediaElement.currentTime());
gyorgy@0 447
gyorgy@0 448
gyorgy@0 449 if (ExternalInterface.objectID != null && ExternalInterface.objectID.toString() != "") {
gyorgy@0 450
gyorgy@0 451 //_output.appendText("event:" + eventName + " : " + eventValues);
gyorgy@0 452 trace("event", eventName, eventValues);
gyorgy@0 453
gyorgy@0 454 if (eventValues == null)
gyorgy@0 455 eventValues == "";
gyorgy@0 456
gyorgy@0 457 if (_isVideo) {
gyorgy@0 458 eventValues += (eventValues != "" ? "," : "") + "isFullScreen:" + _isFullScreen;
gyorgy@0 459 }
gyorgy@0 460
gyorgy@0 461 eventValues = "{" + eventValues + "}";
gyorgy@0 462
gyorgy@0 463 /*
gyorgy@0 464 OLD DIRECT METHOD
gyorgy@0 465 ExternalInterface.call(
gyorgy@0 466 "function(id, name) { mejs.MediaPluginBridge.fireEvent(id,name," + eventValues + "); }",
gyorgy@0 467 ExternalInterface.objectID,
gyorgy@0 468 eventName);
gyorgy@0 469 */
gyorgy@0 470
gyorgy@0 471 // use set timeout for performance reasons
gyorgy@0 472 //if (!_showControls) {
gyorgy@0 473 ExternalInterface.call("setTimeout", "mejs.MediaPluginBridge.fireEvent('" + ExternalInterface.objectID + "','" + eventName + "'," + eventValues + ")",0);
gyorgy@0 474 //}
gyorgy@0 475 }
gyorgy@0 476 }
gyorgy@0 477
gyorgy@0 478 function secondsToTimeCode(seconds:Number):String {
gyorgy@0 479 var timeCode:String = "";
gyorgy@0 480 seconds = Math.round(seconds);
gyorgy@0 481 var minutes:Number = Math.floor(seconds / 60);
gyorgy@0 482 timeCode = (minutes >= 10) ? minutes.toString() : "0" + minutes.toString();
gyorgy@0 483 seconds = Math.floor(seconds % 60);
gyorgy@0 484 timeCode += ":" + ((seconds >= 10) ? seconds.toString() : "0" + seconds.toString());
gyorgy@0 485 return timeCode; //minutes.toString() + ":" + seconds.toString();
gyorgy@0 486 }
gyorgy@0 487
gyorgy@0 488 function positionControls() {
gyorgy@0 489 _controlBarBg.width = stage.stageWidth;
gyorgy@0 490 _controlBar.y = stage.stageHeight - _controlBar.height;
gyorgy@0 491 _duration.x = stage.stageWidth - _duration.width - 10;
gyorgy@0 492 _currentTime.x = stage.stageWidth - _duration.width - 10 - _currentTime.width - 10;
gyorgy@0 493 }
gyorgy@0 494 }
gyorgy@0 495 }