@@ -7,27 +7,29 @@ package com.videojs{
77 import flash.display.Bitmap ;
88 import flash.display.Loader ;
99 import flash.display.Sprite ;
10+ import flash.display.Stage ;
1011 import flash.events.Event ;
1112 import flash.events.IOErrorEvent ;
1213 import flash.events.SecurityErrorEvent ;
14+ import flash.events.StageVideoEvent ;
1315 import flash.external.ExternalInterface ;
1416 import flash.geom.Rectangle ;
15- import flash.media.Video ;
17+ import flash.media.StageVideo ;
1618 import flash.net.URLRequest ;
1719 import flash.system.LoaderContext ;
1820
1921 public class VideoJSView extends Sprite {
2022
21- private var _uiVideo : Video ;
23+ private var _uiVideo : StageVideo ;
2224 private var _uiPosterContainer : Sprite ;
2325 private var _uiPosterImage : Loader ;
2426 private var _uiBackground : Sprite ;
2527
2628 private var _model : VideoJSModel;
2729
28- public function VideoJSView (){
30+ public function VideoJSView (stage : Stage ){
2931
30- _model = VideoJSModel. getInstance ();
32+ _model = VideoJSModel. getInstance (stage );
3133 _model . addEventListener (VideoJSEvent. POSTER_SET , onPosterSet);
3234 _model . addEventListener (VideoJSEvent. BACKGROUND_COLOR_SET , onBackgroundColorSet);
3335 _model . addEventListener (VideoJSEvent. STAGE_RESIZE , onStageResize);
@@ -50,16 +52,18 @@ package com.videojs{
5052
5153 addChild (_uiPosterContainer );
5254
53- _uiVideo = new Video ();
54- _uiVideo . width = _model . stageRect. width ;
55- _uiVideo . height = _model . stageRect. height ;
56- _uiVideo . smoothing = true ;
57- addChild (_uiVideo );
55+ _uiVideo = stage . stageVideos[ 0 ];
56+ _uiVideo . addEventListener (StageVideoEvent. RENDER_STATE , onStageVideoRender);
5857
5958 _model . videoReference = _uiVideo ;
6059
6160 }
6261
62+ private function onStageVideoRender (e :StageVideoEvent ):void {
63+ ExternalInterface . call ("console.log" , "Decoder: " + e. status );
64+ sizeVideoObject();
65+ }
66+
6367 /**
6468 * Loads the poster frame, if one has been specified.
6569 *
@@ -93,6 +97,7 @@ package com.videojs{
9397 private function sizeVideoObject ():void {
9498
9599 var __targetWidth : int , __targetHeight : int ;
100+ var __targetY : int , __targetX : int ;
96101
97102 var __availableWidth : int = _model . stageRect. width ;
98103 var __availableHeight : int = _model . stageRect. height ;
@@ -126,12 +131,10 @@ package com.videojs{
126131 __targetHeight = __availableHeight ;
127132 }
128133
129- _uiVideo . width = __targetWidth ;
130- _uiVideo . height = __targetHeight ;
131-
132- _uiVideo . x = Math . round ((_model . stageRect. width - _uiVideo . width ) / 2 );
133- _uiVideo . y = Math . round ((_model . stageRect. height - _uiVideo . height ) / 2 );
134-
134+ __targetX = Math . round ((_model . stageRect. width - __targetWidth ) / 2 );
135+ __targetY = Math . round ((_model . stageRect. height - __targetHeight ) / 2 );
136+
137+ _uiVideo . viewPort = new Rectangle (__targetX , __targetY , __targetWidth , __targetHeight );
135138
136139 }
137140
0 commit comments