Bonjour à tous,

Un gros soucis se pose à moi, et après plusieurs jours de tests je ne trouve pas de solution.

Je suis actuellement en train de développer une application mobile sur Android permettant de lire une vidéo en local.

Pour cela j'utilise la classe SimpleStageVideo disponible sur le site d'Adobe : http://www.adobe.com/devnet/flashpla...age_video.html

Lors du lancement tout se passe bien, toutefois lorsque je passe sur une autre application en pleine lecture puis que je reviens sur ma vidéo, celle-ci passe au dessus des autres éléments de mon interface (à savoir le menu de navigation) et surtout elle s'agrandit.

J'ai essayé de faire un resize sur un événement de type activate (pour intercepter le retour sur l'application)

J'ai également essayé de supprimer le conteneur, puis de réinjecter la vidéo dans mon interface (même si cela est couteux en ressources ... ).

Cela n'a pas fonctionné.

Je pense que lors de mon évènement "activate", le UIComponent ne s'est pas encore totalement reconstruit, et de ce fait le resize ne fonctionne pas sur une bonne taille d'écran utilisable (puisque du coup elle ne considère pas les menus).

Pour tester ma théorie, j'ai testé en passant en mode debug. En executant plus lentement mon code, la vidéo se remet à la bonne taille...

J'ai donc essayé de mettre des timers, mais là encore ce fut une tentative vaine.

Comment est-il possible lors du retour à mon application que ma vidéo reste à la bonne taille, et ne surplombe pas le reste des menus ?

Ci-suit les codes en question :

// La Vue Permettant de Visionner la Vidéo

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
          		xmlns:components="bouton.components.*"
          		xmlns:s="library://ns.adobe.com/flex/spark" title="viewVideo" activate="view1_activateHandler(event)" creationComplete="view1_creationCompleteHandler(event)" backgroundAlpha="0" actionBarVisible="false" tabBarVisible="false">
 
     	<fx:Script>
          		<![CDATA[
               			import flash.events.MouseEvent;
               			import mx.core.UIComponent;
               			import mx.events.FlexEvent;
               			import valueObjects.SimpleStageVideo;
 
               			private var conn:SQLConnection;
               			private var createStmt:SQLStatement;
               			public var dbFile:File;
 
               			public var fichierCharge:File;
 
               			public var numeroBouton:int = 0;
               			private var test:SimpleStageVideo = new SimpleStageVideo();
               			private var container:UIComponent = new UIComponent();
 
               			protected function view1_creationCompleteHandler(event:FlexEvent):void
               			{
                    				var chemin:File = new File(data.url); 
                    				test.setData(chemin);
 
 
                    				//container.stage = this.stage;
                    				container.height = stage.height;
                    				container.width = stage.width;
                    				container.addChildAt(test, 0);
                    				addElementAt(container, 0); 
                    				trace(""+container.width+" : "+container.height+" : "+container.x+" : "+container.y);
               			}
 
 
 
               			protected function view1_activateHandler(event:Event):void
               			{
                    				test.resize(); 
               			}
 
               			private function resizeF(event:Event):void
               			{
                    				test.resize();
               			}
 
          		]]>
     	</fx:Script>
     	<s:HGroup  id="barremenu" gap="0" horizontalAlign="left" styleName="header_style" verticalAlign="top" width="100%" contentBackgroundColor="#FFFFFF" contentBackgroundAlpha="1" paddingBottom="50" >
          		<s:Image scaleMode="letterbox" smooth="true" smoothingQuality="high" 
                    				 source="assets/header_droi.jpg" />
 
          		<components:Boutton_Retour click="boutton_retour1_clickHandler(event)" enabled="true" height="100%" contentBackgroundColor="#FFFFFF" contentBackgroundAlpha="1"/>
          		<components:Boutton_Accueil_Retour click="boutton_accueil1_clickHandler(event)" enabled="true" height="100%" contentBackgroundColor="#FFFFFF" contentBackgroundAlpha="1" /> 
          		<s:Image scaleMode="stretch" smooth="true" smoothingQuality="high"
                    				 source="assets/header_milieu.jpg" fillMode="repeat" width="60%" height="99%" />
          		<s:Image  scaleMode="stretch" smooth="true" smoothingQuality="high" 
                    				  source="assets/ipad.jpg" />
     	</s:HGroup>
</s:View>
// Ma Classe SimpleStageVideo
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
 
package valueObjects
{
     	import flash.display.Loader;
     	import flash.display.Shape;
     	import flash.display.Sprite;
     	import flash.display.Stage;
     	import flash.display.StageAlign;
     	import flash.display.StageScaleMode;
     	import flash.events.Event;
     	import flash.events.MouseEvent;
     	import flash.events.NetStatusEvent;
     	import flash.events.StageVideoAvailabilityEvent;
     	import flash.events.StageVideoEvent;
     	import flash.events.VideoEvent;
     	import flash.filesystem.File;
     	import flash.geom.Rectangle;
     	import flash.media.StageVideo;
     	import flash.media.StageVideoAvailability;
     	import flash.media.Video;
     	import flash.net.NetConnection;
     	import flash.net.NetStream;
     	import flash.net.URLRequest;
     	import flash.text.TextField;
     	import flash.text.TextFieldAutoSize;
 
     	import mx.core.UIComponent;
 
     	import spark.components.Image;
     	import spark.components.NavigatorContent;
 
 
     	[SWF(frameRate="1", backgroundColor="#000000")]
     	public class SimpleStageVideo extends Sprite
     	{
          		public var chemin:File;
          		private var FILE_NAME:String = "";
          		private static const INTERVAL:Number = 500;
          		private static const BORDER:Number = 20;
 
          		private var legend:TextField = new TextField();
          		private var sv:StageVideo;
          		private var nc:NetConnection;
          		private var ns:NetStream;
          		private var rc:Rectangle;
          		private var video:Video;
          		private var thumb:Shape;
          		private var interactiveThumb:Sprite;
          		private var totalTime:Number;
 
          		private var videoWidth:int;
          		private var videoHeight:int;
          		private var outputBuffer:String = new String();
          		private var rect:Rectangle = new Rectangle(0, 0, 0, BORDER);
          		private var videoRect:Rectangle = new Rectangle(0, 0, 0, 0);
          		private var gotStage:Boolean;
          		private var stageVideoInUse:Boolean;
          		private var classicVideoInUse:Boolean;
          		private var accelerationType:String;
          		private var infos:String = new String();
          		private var available:Boolean;
          		private var inited:Boolean;
          		private var played:Boolean;
          		private var container:Sprite;
          		private var displayButtonPause:Boolean;
          		public var imagePause:UIComponent;
          		public var pLoad:Loader;
          		private var testResize:Boolean = false;
          		private var widthStage:int = 0;
 
 
 
          		/**
          		 * 
          		 * 
          		 */ 
          		public function SimpleStageVideo()
          		{
               			// Make sure the app is visible and stage available
               			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
               			//addEventListener(Event.ACTIVATE, onActivate);
          		}
 
          		private function onActivate(event:Event):void
          		{
 
               			video.addEventListener(Event.RENDER, functionResize);
 
          		}
 
          		private function functionResize(event:Event):void
          		{
               			resize();
          		}
 
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function onAddedToStage(event:Event):void
          		{
 
 
               			// Scaling
               			stage.scaleMode = StageScaleMode.NO_SCALE;
               			stage.align = StageAlign.TOP_LEFT;
               			widthStage = stage.width;
 
 
               			// Thumb seek Bar
               			thumb = new Shape();
 
               			interactiveThumb = new Sprite();
               			interactiveThumb.addChild(thumb);
               			addChild(interactiveThumb);
 
               			// Connections
               			nc = new NetConnection();
               			nc.connect(null);
               			ns = new NetStream(nc);
               			ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
               			ns.client = this;
 
               			// Screen
               			video = new Video();
               			video.smoothing = true;
 
               			// Video Events
               			// the StageVideoEvent.STAGE_VIDEO_STATE informs you if StageVideo is available or not
               			stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, onStageVideoState);
               			// in case of fallback to Video, we listen to the VideoEvent.RENDER_STATE event to handle resize properly and know about the acceleration mode running
               			video.addEventListener(VideoEvent.RENDER_STATE, videoStateChange);
 
               			// Input Events
               			stage.addEventListener(MouseEvent.DOUBLE_CLICK, onKeyDown);
               			stage.addEventListener(Event.RESIZE,  onResize);
               			stage.addEventListener(MouseEvent.CLICK, onClick);
 
          		}
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function onNetStatus(event:NetStatusEvent):void
          		{
               			if ( event.info == "NetStream.Play.StreamNotFound" )
                    				legend.text = "Video file passed, not available!";
          		}
 
          		public function setData(chem:File):void
          		{
               			chemin = chem; 
               			FILE_NAME = chemin.url;
          		}
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function onFrame(event:Event):void 
          		{
 
               			var ratio:Number = (ns.time / totalTime) * (widthStage+470);
               			rect.width = ratio;
               			thumb.graphics.clear();
               			thumb.graphics.beginFill(0xFF0000);
               			thumb.graphics.drawRect(rect.x, rect.y+350, rect.width+120, rect.height); 
               			//thumb.graphics.drawRect(rect.x, rect.y, rect.width, rect.height); 
               			//testResize = true;
 
          		}
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function onClick(event:MouseEvent):void
          		{
 
               			//ns.pause();
               			if ( event.stageY >= interactiveThumb.y - BORDER && event.stageX <= stage.stageWidth - BORDER )
               			{
                    				var seekTime:Number = (stage.mouseX - BORDER) * ( totalTime / (stage.stageWidth - (BORDER << 1) ) );
                    				ns.seek( seekTime ); 
               			}
          		}
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function onKeyDown(event:MouseEvent):void
          		{ 
 
               			ns.togglePause();
               			// Affichage du bouton d'affichage de la mise en pause de la video 
               			if(displayButtonPause == false)
               			{
                    				pLoad = new Loader();
                    				pLoad.load(new URLRequest("assets/pause.png"));
                    				//imagePause = new UIComponent();
                    				//imagePause.addChild(pLoad);
                    				//imagePause.x = 200;
                    				//imagePause.y = 200;
                    				pLoad.x = (stage.width - (stage.width/3.5));
                    				pLoad.y = (stage.height - (stage.height/3.5));
                    				addChild(pLoad);
                    				displayButtonPause = true;
                    				pLoad.visible = true;
               			} else 
               			{
                    				displayButtonPause = false;
                    				pLoad.visible = false;
                    				removeChild(pLoad);
               			}
          		}
 
          		/**
          		 * Permet l'arret de la video avant la supression de la vue
          		 */
          		public function arretVideo():void 
          		{
               			//video.clear();
               			//sv.attachNetStream(null);
               			ns.close();
               			//video.attachNetStream(null);
               			/*var nce:NetConnection = new NetConnection();
               			nce.connect(null);
               			sv.attachNetStream(new NetStream(nce));
               			//sv.attachNetStream();*/
          		}
 
          		/**
          		 * 
          		 * @param width
          		 * @param height
          		 * @return 
          		 * 
          		 */ 
          		private function getVideoRect(width:uint, height:uint):Rectangle
          		{ 
               			trace("Width" + width);
               			trace("Stage Width" + stage.stageWidth);
               			trace("Height" + height);
               			trace("Stage height" + stage.stageHeight);
 
 
 
               			var videoWidth:uint = width;
               			var videoHeight:uint = height;
               			var scaling:Number = Math.min ( stage.stageWidth / videoWidth, stage.stageHeight / videoHeight );
 
               			videoWidth *= scaling, videoHeight *= scaling;
 
               			var posX:uint = stage.stageWidth - videoWidth >> 1;
               			var posY:uint = stage.stageHeight - videoHeight >> 1;
 
               			videoRect.x = posX;
               			videoRect.y = posY;
               			videoRect.width = videoWidth;
               			videoRect.height = videoHeight;
 
               			trace("Objet video width" + video.width);
               			trace("Objet video height" + video.height);
 
               			trace("Objet video rect width" + videoRect.width);
               			trace("Objet video rect height" + videoRect.height);
 
               			return videoRect;
          		}
 
          		/**
          		 * 
          		 * 
          		 */ 
          		public function resize ():void
          		{ 
               			if ( stageVideoInUse )
               			{
                    				// Get the Viewport viewable rectangle
                    				rc = getVideoRect(sv.videoWidth, sv.videoHeight);
                    				// set the StageVideo size using the viewPort property
                    				sv.viewPort = rc;
               			} else 
               			{
 
                    				// Get the Viewport viewable rectangle
                    				rc = getVideoRect(video.videoWidth, video.videoHeight);
                    				// Set the Video object size
                    				video.width = rc.width;
                    				video.height = rc.height;
                    				video.x = rc.x, video.y = rc.y;
                    				//trace(""+rc.width+" : "+rc.height+" : "+rc.x+" : "+rc.y);
                    				testResize = true;
 
               			}
               			interactiveThumb.x = BORDER, interactiveThumb.y = stage.stageHeight - (BORDER << 1);
               			legend.text = infos;
          		}
 
 
          		/**
          		 * 
          		 * @param evt
          		 * 
          		 */ 
          		public function onMetaData ( evt:Object ):void
          		{
               			totalTime = evt.duration;
               			stage.addEventListener(Event.ENTER_FRAME, onFrame);
          		}
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function onStageVideoState(event:StageVideoAvailabilityEvent):void
          		{ 
               			// Detect if StageVideo is available and decide what to do in toggleStageVideo
               			toggleStageVideo(available = inited = (event.availability == StageVideoAvailability.AVAILABLE));
          		}
 
          		/**
          		 * 
          		 * @param on
          		 * 
          		 */ 
          		private function toggleStageVideo(on:Boolean):void
          		{ 
               			infos = "StageVideo Running (Direct path) : " + on + "\n";
 
               			// If we choose StageVideo we attach the NetStream to StageVideo
               			if (on) 
               			{
                    				stageVideoInUse = true;
                    				if ( sv == null )
                    				{
                         					sv = stage.stageVideos[0];
                         					sv.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);
                    				}
                    				sv.attachNetStream(ns);
                    				if (classicVideoInUse)
                    				{
                         					// If we use StageVideo, we just remove from the display list the Video object to avoid covering the StageVideo object (always in the background)
                         					stage.removeChild ( video );
                         					classicVideoInUse = false;
                    				}
               			} else 
               			{
                    				// Otherwise we attach it to a Video object
                    				if (stageVideoInUse)
                         					stageVideoInUse = false;
                    				classicVideoInUse = true;
                    				video.attachNetStream(ns);
                    				stage.addChildAt(video, 0);
               			}
 
               			if ( !played ) 
               			{
                    				played = true;
                    				ns.play(FILE_NAME);
               			}
          		} 
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function onResize(event:Event):void
          		{
               			resize();
          		}
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function stageVideoStateChange(event:StageVideoEvent):void
          		{ 
               			infos += "StageVideoEvent received\n";
               			infos += "Render State : " + event.status + "\n";
               			trace(infos);
 
               			resize();
 
          		}
 
          		/**
          		 * 
          		 * @param event
          		 * 
          		 */ 
          		private function videoStateChange(event:VideoEvent):void
          		{ 
               			infos += "VideoEvent received\n";
               			infos += "Render State : " + event.status + "\n";
               			trace(infos);
 
               			resize();
 
          		}
     	}
}