-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathVideoIO.as
5036 lines (4505 loc) · 167 KB
/
VideoIO.as
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2010-2011, Kundan Singh. See website for LICENSING.*/
/* Copyright (c) 2010-2011, VoIP Researcher.*/
/* Copyright (c) 2011-2012, Intencity Cloud Technologies.*/
package {
import flash.display.DisplayObject;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.DataEvent;
import flash.external.ExternalInterface;
import flash.net.LocalConnection;
import flash.system.Security;
import mx.core.Application;
import mx.events.DynamicEvent;
import mx.events.FlexEvent;
import mx.events.PropertyChangeEvent;
import mx.events.VideoEvent;
import mx.utils.ObjectUtil;
/**
* The main application for Flash-VideoIO hides the internal implementation of VideoIOInternal
* and translates the API using ExternalInterface. This model allows clear separation between
* the application interface and the implementation.
*/
public class VideoIO extends Application {
// a reference to the internal implementation class
private var component:Class = VideoIOInternal;
// a reference to an instance of type VideoIOInternal.
private var obj:Object = null;
// facebook specific interfaces.
private var fbConnection1:LocalConnection;
private var fbConnectionName1:String;
private var fbConnection2:LocalConnection;
private var fbConnectionName2:String;
// enable notification or not?
private var isChild:Boolean = false;
// The URL of the project for facebook.
private static const BASE_URL:String = "http://myprojectguide.kundansingh.com/p/face-talk";
/**
* The constructor sets the absolute layout with transparent background, no border, and
* installes the listener for start up on "addedToStage" event.
*/
public function VideoIO() {
this.layout = "absolute";
this.setStyle("backgroundAlpha", 0);
this.setStyle("borderStyle", "none");
this.setStyle("borderThickness", 0);
this.setStyle("borderVisible", false);
addEventListener("addedToStage", creationCompleteHandler);
}
/**
* When the application is added to stage this initialization function is run.
* It creates a new VideoIOInternal object with 100% dimension, and adds it as a
* child object. It also installs various ExternalInterface functions.
*/
private function creationCompleteHandler(event:Event):void
{
obj = new component();
obj.percentWidth = obj.percentHeight = 100;
// whether this is a child application or the top-level application.
if (CONFIG::sdk4) {
isChild = (mx.core.FlexGlobals.topLevelApplication != this);
}
else {
isChild = (Application.application != this);
}
trace("isChild=" + isChild);
if (!isChild) {
// Facebook specific initialization
fbInitialize(null);
// minimum dimension to popup SecurityPanel
//TODO: does not work on Chrome with Flash Player 10.3
//obj.minWidth = 215;
//obj.minHeight = 138;
}
try {
// Listen for all interesting events from the internal implementation.
obj.addEventListener(FlexEvent.CREATION_COMPLETE, componentCompleteHandler, false, 0, true);
obj.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, propertyChangeHandler, false, 0, true);
obj.addEventListener("callback", callbackHandler, false, 0, true);
obj.addEventListener("postingNotify", postingNotifyHandler, false, 0, true);
obj.addEventListener("showingSettings", showingSettingsHandler, false, 0, true);
obj.addEventListener("hidingSettings", showingSettingsHandler, false, 0, true);
obj.addEventListener("receiveData", receiveDataHandler, false, 0, true);
if (ExternalInterface.available) {
// For top-level application, install the Javascript API.
if (!isChild) {
ExternalInterface.addCallback("setProperty", setProperty);
ExternalInterface.addCallback("getProperty", getProperty);
ExternalInterface.addCallback("callProperty", callProperty);
}
}
else {
trace("ExternalInterface is not available");
}
} catch (e:SecurityError) {
trace("security exception: " + e.message);
}
// For top-level application, process the "flashVars"
if (!isChild) {
for (var name:String in parameters) {
var value:String = parameters[name];
if (value == "true" || value == "false")
setProperty(name, (value == "true")); // boolean
else
setProperty(name, value); // string
}
}
// add the object as child of main application
addChild(DisplayObject(obj));
}
/**
* When "setProperty" is invoked from Javascript or parent application, it passes it
* to the internal implementation.
*/
public function setProperty(name:String, value:Object):void
{
if (obj.hasOwnProperty(name)) {
trace("setProperty(" + name + "," + (name != "snapshot" ? value : "hidden") + ")");
obj[name] = (value != '' ? value : null);
}
else {
trace("setProperty(name=" + name + ") ignored");
}
}
/**
* When "getProperty" is invoked from Javascript or parent application, it passes it
* to the internal implementation.
*/
public function getProperty(name:String):Object
{
var result:Object = obj.hasOwnProperty(name) ? obj[name] : null;
trace("getProperty(" + name + ")=>" + (name != "snapshot" ? result : "hidden"));
return result;
}
/**
* When "callProperty" is invoked from Javascript or parent application, it passes it
* to the internal implementation.
*/
public function callProperty(name:String, ...args):void
{
try {
trace("callProperty(" + name + ",...)");
var func:Function = obj[name] as Function;
func.apply(obj, args);
} catch (e:Error) {
trace("callProperty(" + name + ",...) exception\n" + e.getStackTrace());
}
}
/**
* When the internal implementation is created, it dispatches the onCreationComplete
* event to parent application and onCreationComplete callback to javascript.
*/
private function componentCompleteHandler(event:Event):void
{
try {
if (isChild) {
dispatchEvent2(new Event("onCreationComplete"));
}
else if (ExternalInterface.available && ExternalInterface.objectID != null) {
var param:Object = {objectID: ExternalInterface.objectID};
trace("invoking JavaScript onCreationComplete objectID=" + ExternalInterface.objectID);
if (fbConnectionName1 == null)
ExternalInterface.call("onCreationComplete", param);
else
fbConnection1.send(fbConnectionName1, "callFBJS", "onCreationComplete", [param]);
}
} catch (e:Error) {
trace(e.getStackTrace());
}
}
/**
* When the internal implementation's property changes, it dispatches the onPropertyChange
* event to parent application and onPropertyChange callback to javascript.
*/
private function propertyChangeHandler(event:PropertyChangeEvent):void
{
try {
var type:String = typeof(obj[event.property]);
if (type == "string" || type == "boolean" || type == "number") {
if (isChild) {
var ev:DynamicEvent = new DynamicEvent("onPropertyChange");
ev.property = event.property;
ev.oldValue = event.oldValue;
ev.newValue = event.newValue;
dispatchEvent2(ev);
}
else if (ExternalInterface.available && ExternalInterface.objectID != null) {
var param:Object = {
objectID: ExternalInterface.objectID,
property: event.property,
oldValue: event.oldValue,
newValue: event.newValue
};
trace("invoking JavaScript onPropertyChange objectID=" + ExternalInterface.objectID
+ " property=" + event.property
+ " oldValue=" + event.oldValue
+ " newValue=" + event.newValue);
if (fbConnectionName1 == null)
ExternalInterface.call("onPropertyChange", param);
else
fbConnection1.send(fbConnectionName1, "callFBJS", "onPropertyChange", [param]);
}
}
} catch (e:Error) {
trace(e.getStackTrace());
}
}
/**
* When the internal implementation invokes a callback, it dispatches the onCallback
* event to parent application and onCallback callback to javascript.
*/
private function callbackHandler(event:DynamicEvent):void
{
try {
if (isChild) {
var ev:DynamicEvent = new DynamicEvent("onCallback");
ev.method = event.method;
ev.args = event.args;
dispatchEvent2(ev);
}
else if (ExternalInterface.available && ExternalInterface.objectID != null) {
var param:Object = {
objectID: ExternalInterface.objectID,
method: event.method,
args: event.args
};
trace("invoking JavaScript onCallback objectID=" + ExternalInterface.objectID
+ " method=" + event.method
+ " args=" + event.args);
if (fbConnectionName1 == null)
ExternalInterface.call("onCallback", param);
else
fbConnection1.send(fbConnectionName1, "callFBJS", "onCallback", [param]);
}
} catch (e:Error) {
trace(e.getStackTrace());
}
}
/**
* When the internal implementation dispatches postingNotify , it dispatches the onPostingNotify
* event to parent application and onPostingNotify callback to javascript.
*/
private function postingNotifyHandler(event:DynamicEvent):void
{
try {
if (isChild) {
var ev:DynamicEvent = new DynamicEvent("onPostingNotify");
ev.user = event.user;
ev.text = event.text;
dispatchEvent2(ev);
}
else if (ExternalInterface.available && ExternalInterface.objectID != null) {
var param:Object = {
objectID: ExternalInterface.objectID,
user: event.user,
text: event.text
};
trace("invoking JavaScript onPostingNotify objectID=" + ExternalInterface.objectID
+ " user=" + event.user
+ " text=" + event.text);
if (fbConnectionName1 == null)
ExternalInterface.call("onPostingNotify", param);
else
fbConnection1.send(fbConnectionName1, "callFBJS", "onPostingNotify", [param]);
}
} catch (e:Error) {
trace(e.getStackTrace());
}
}
/**
* When the internal implementation dispatches receiveData, it dispatches the onReceiveData
* event to parent application and onReceiveData callback to javascript.
*/
private function receiveDataHandler(event:DataEvent):void
{
try {
if (isChild) {
var ev:DynamicEvent = new DynamicEvent("onReceiveData");
ev.data = event.data;
dispatchEvent2(ev);
}
else if (ExternalInterface.available && ExternalInterface.objectID != null) {
var param:Object = {
objectID: ExternalInterface.objectID,
data: event.data
};
trace("invoking JavaScript onReceiveData objectID=" + ExternalInterface.objectID
+ " data=" + event.data);
if (fbConnectionName1 == null)
ExternalInterface.call("onReceiveData", param);
else
fbConnection1.send(fbConnectionName1, "callFBJS", "onReceiveData", [param]);
}
} catch (e:Error) {
trace(e.getStackTrace());
}
}
/**
* When the internal implementation dispatches showingSettings or hidingSettings,
* it dispatches the onShowingSettings event to parent application and onShowingSettings
* callback to javascript. The showing (Boolean) property determines the showing or
* hiding mode.
*/
private function showingSettingsHandler(event:Event):void
{
try {
if (isChild) {
var ev:DynamicEvent = new DynamicEvent("onShowingSettings");
ev.showing = (event.type != "hidingSettings");
dispatchEvent2(ev);
}
else if (ExternalInterface.available && ExternalInterface.objectID != null) {
var param:Object = {
objectID: ExternalInterface.objectID,
showing: (event.type != "hidingSettings")
};
trace("invoking JavaScript onShowingSettings objectID=" + ExternalInterface.objectID
+ " showing=" + (event.type != "hidingSettings"));
if (fbConnectionName1 == null)
ExternalInterface.call("onShowingSettings", param);
else
fbConnection1.send(fbConnectionName1, "callFBJS", "onShowingSettings", [param]);
}
} catch (e:Error) {
trace(e.getStackTrace());
}
}
/**
* To initialize for Facebook interface, we need to load the crossdomain and allow the facebook domains.
* Finally we need to map the setProperty and getProperty functions.
*/
private function fbInitialize(event:Event):void
{
try {
if (('fb_local_connection' in LoaderInfo(this.root.loaderInfo).parameters)
|| ('fb_fbjs_connection' in LoaderInfo(this.root.loaderInfo).parameters)) {
Security.loadPolicyFile(BASE_URL + "/crossdomain.xml");
Security.allowDomain("apps.facebook.com");
Security.allowDomain("*.facebook.com");
}
}
catch (e:Error) {
trace("Error in Facebook security domain");
}
try {
if ('fb_local_connection' in LoaderInfo(this.root.loaderInfo).parameters) {
fbConnection1 = new LocalConnection();
fbConnectionName1 = LoaderInfo(this.root.loaderInfo).parameters.fb_local_connection;
trace("Facebook local connection " + fbConnectionName1);
}
}
catch (e:Error) {
trace("Error in Facebook local connection");
trace(e.getStackTrace());
}
try {
if ('fb_fbjs_connection' in LoaderInfo(this.root.loaderInfo).parameters) {
fbConnection2 = new LocalConnection();
fbConnectionName2 = LoaderInfo(this.root.loaderInfo).parameters.fb_fbjs_connection;
fbConnection2.allowDomain("*");
fbConnection2.client = {
"setProperty": function(name:String, value:Object):void {
this.setProperty(name, value);
},
"getProperty": function(name:String):Object {
return this.getProperty(name);
}
};
fbConnection2.connect(fbConnectionName2);
trace("Facebook JS connection " + fbConnectionName2);
}
}
catch (e:Error) {
trace("Error in Facebook JS connection");
trace(e.getStackTrace());
}
}
/**
* When dispatching an event, also dispatch using the loader info of the system manager
* so that if this is a child application then the parent receives the event.
*/
private function dispatchEvent2(event:Event):void
{
//trace("dispatchEvent type=" + event.type);
dispatchEvent(event);
if (this.systemManager != null && this.systemManager.loaderInfo != null
&& this.systemManager.loaderInfo.sharedEvents != null)
this.systemManager.loaderInfo.sharedEvents.dispatchEvent(event);
}
}
}
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.events.AsyncErrorEvent;
import flash.events.ContextMenuEvent;
import flash.events.DataEvent;
import flash.events.ErrorEvent;
import flash.events.FocusEvent;
import flash.events.FullScreenEvent;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.events.StatusEvent;
import flash.events.TimerEvent;
import flash.geom.Matrix;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.SoundMixer;
import flash.media.SoundTransform;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.ObjectEncoding;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.system.Capabilities;
import flash.system.Security;
import flash.system.SecurityPanel;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.utils.Timer;
import flash.utils.ByteArray;
import mx.binding.utils.BindingUtils;
import mx.containers.Canvas;
import mx.controls.Alert;
import mx.controls.Image;
import mx.controls.VideoDisplay;
import mx.core.Application;
import mx.core.UIComponent;
import mx.events.FlexEvent;
import mx.events.MetadataEvent;
import mx.events.PropertyChangeEvent;
import mx.events.PropertyChangeEventKind;
import mx.events.ResizeEvent;
import mx.events.VideoEvent;
import mx.events.DynamicEvent;
import mx.graphics.codec.JPEGEncoder;
import mx.utils.Base64Encoder;
import mx.utils.Base64Decoder;
import mx.controls.Button;
// Following are dynamically used based on Flash Player version
// import flash.net.GroupSpecifier;
// import flash.net.NetGroup;
/**
* Dispatched when the camera active state changes.
*/
[Event(name="cameraChange", type="flash.events.Event")]
/**
* Dispatched when the microphone active state changes.
*/
[Event(name="micChange", type="flash.events.Event")]
/**
* Dispatched when "privacyEvent" is set to true and Flash Player is about to
* show the security settings dialog box. This is also dispatched when "showSettings"
* method is called to explicitly show the settings dialog box.
*/
[Event(name="showingSettings", type="flash.events.Event")]
/**
* Dispatched when "privacyEvent" is set to true and Flash Player earlier showed
* the security settings dialog box either implicitly or explicitly on "showSettings",
* then now the application received the focusIn event to indicate that the
* security dialog box is no longer active.
*/
[Event(name="hidingSettings", type="flash.events.Event")]
/**
* Dispatched when the server calls a method. The method and args properties are useful.
*/
[Event(name="callback", type="mx.events.DynamicEvent")]
/**
* Dispatched when the NetGroup.Posting.Notify is received. The user and text properties are useful.
*/
[Event(name="postingNotify", type="mx.events.DynamicEvent")]
/**
* Dispatched when the sendData is received on a stream. This is done when the remote side
* called sendData method to send some data. The data property contains the received data.
*/
[Event(name="receiveData", type="flash.events.DataEvent")]
/**
* The VideoIO class handles various audio/video recording and playback modes.
*/
class VideoIOInternal extends Canvas
{
// the product page URL
private static const COMPONENT_URL:String = "https://github.com/theintencity/flash-videoio";
// the version string
private static const COMPONENT_VERSION:String = "Powered by Flash-VideoIO " + CONFIG::version;
private var _src:String;
private var _url:String;
private var _scheme:String;
private var _args:Array;
private var _play:String;
private var _publish:String;
private var _record:Boolean;
private var _recordMode:String = "record";
private var _playMode:String = "live";
private var _live:Boolean;
private var _mirrored:Boolean = true;
private var _farID:String;
private var _nearID:String;
// other flags for the video
private var _poster:String;
private var _autoplay:Boolean = true;
private var _loop:Boolean = false;
private var _controls:UIComponent;
private var _preload:Boolean = false;
private var _detectActivity:Boolean = true;
// internal objects and flags
private var nc:NetConnection;
private var _local:NetStream;
private var _remote:NetStream;
private var _dispatchDisconnect:Boolean = false;
private var _playing:Boolean = false;
private var _recording:Boolean = false;
private var _bidirection:Boolean = false;
private var _camera:Boolean = false;
private var _microphone:Boolean = false;
private var _display:Boolean = true;
private var _deviceAllowed:Boolean = false;
private var _privacyEvent:Boolean = false;
private var _gain:Number = 0.5;
private var _level:Number = 0;
private var _rate:int = 16;
private var _codec:String = "Speex";
private var _encodeQuality:int = 6;
private var _framesPerPacket:int = 1;
private var _silenceLevel:int = 0;
private var _echoSuppression:Boolean = true;
private var _echoCancel:Boolean = true;
private var _sound:Boolean = true;
private var _volume:Number = 0.5;
private var _cameraObject:Camera = null;
private var _microphoneObject:Microphone = null;
private var _micLevelTimer:Timer;
private var _smoothing:Boolean = true;
private var _cameraWidth:int = 320;
private var _cameraHeight:int = 240;
private var _cameraFPS:int = 12;
private var _cameraBandwidth:int = 0;
private var _cameraQuality:int = 0;
private var _keyFrameInterval:int = 15;
private var _cameraLoopback:Boolean = false;
private var _videoCodec:String = "Sorenson";
private var _video:Video;
private var _videoDisplay:VideoDisplay;
private var _currentTimer:Timer;
private var _currentTime:Number;
private var _duration:Number;
private var _bytesLoaded:Number;
private var _bytesTotal:Number;
private var _videoWidth:Number;
private var _videoHeight:Number;
private var _liveDelay:Number;
private var _currentFPS:Number;
private var _zoom:String = "in";
private var _playerState:String;
private var _bandwidth:Number = 0;
private var _quality:Number = 0.0;
private var _bufferTime:Number = -1.0;
private var _bufferTimeMax:Number = -1.0;
private var _image:Image;
private var _posterBackgroundAlpha:Number;
private var _fullscreen:Boolean = false;
private var _enableFullscreen:Boolean = true;
private var _enableFullscreenOnDoubleClick:Boolean = false;
private var _lastSendTime:Number=0;
private var publishWidth:Number;
private var publishHeight:Number;
// private var _sip:String = "idle";
// group communication
private var _group:String;
private var _groupspec:Object;
private var _netGroup:Object;
// Since NetGroup and GroupSpecifier should be available for earlier Flash Player version
// private var _groupspec:GroupSpecifier;
// private var _netGroup:NetGroup;
private var _snapshot:String;
private var settingsTimer:Timer;
private var stageChildren:int = 0;
private var _proxyType:String = "none";
private var _objectEncoding:uint = ObjectEncoding.DEFAULT;
private var _cameraName:String = "default";
private var _microphoneName:String = "default";
//--------------------------------------
// CONSTRUCTOR
//--------------------------------------
public function VideoIOInternal()
{
super();
trace("Created " + VideoIOInternal.COMPONENT_VERSION);
horizontalScrollPolicy = verticalScrollPolicy = "off";
setStyle("backgroundAlpha", 1.0);
setStyle("borderStyle", "solid");
setStyle("borderThickness", 0);
addEventListener("cameraChange", cameraChangeHandler);
addEventListener("micChange", micChangeHandler);
addEventListener(Event.ADDED_TO_STAGE, addHandler);
addEventListener(Event.REMOVED_FROM_STAGE, removeHandler);
this.doubleClickEnabled = true;
addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler);
installContextMenu();
}
//--------------------------------------
// GETTERS/SETTERS
//--------------------------------------
public const __doc__src:String =
'The "src" read-write string property represents the source URL of the component that controls ' +
'the publish, playback or live mode. For example\n' +
' rtmp://localhost/call/123?publish=live -- connect and publish local stream\n' +
' rtmp://localhost/call/123?play=live&arg=mypass -- play remote stream with auth\n' +
' http://server/path/file1.flv -- play the web downloaded video file\n' +
' rtmp://server/path/file1 -- play the streamed video file\n' +
' ?live=true -- just display local video\n' +
' rtmp://localhost/record?publish=file1&record=true -- record to file1.flv\n' +
'For local demo you can use these URLs\n' +
' rtmp://localhost/call/123?publish=live -- sender stream of call\n' +
' rtmp://localhost/call/123?play=live -- receiver stream of call\n' +
' rtmp://localhost/call/123?publish=test2&record=true -- record test2.flv\n' +
' http://localhost:8080/123/test2.flv -- play test2.flv\n' +
' rtmp://localhost/call/123?play=test2\n';
[Bindable('propertyChange')]
/**
* The src property controls the connect URL and publish, play or live mode.
*/
public function get src():String
{
return _src;
}
public function set src(value:String):void
{
var oldValue:String = _src;
_src = value;
if (oldValue != value) {
var result:Object = { url:null, scheme:null, args:[], farID:null,
publish:null, play:null, record:false, recordMode:null, playMode:null, live:false, name:null};
var params:String = '';
if (value != null) {
var index:int = value.indexOf(':');
result.scheme = (index >= 0 ? value.substr(0, index).toLowerCase() : null);
if (result.scheme == 'http' || result.scheme == 'https') {
result.url = value;
}
else {
index = value.indexOf('?');
params = (index >= 0 ? value.substr(index+1) : '');
result.url = (index >= 0 ? value.substr(0, index) : value);
}
}
for each (var part:String in params.split('&')) {
index = part.indexOf('=');
var name:String = (index >= 0 ? part.substr(0, index) : part);
var val:String = (index >= 0 ? part.substr(index+1) : null);
if (name == "publish" || name == "play" || name =="farID" || name == "group" || name == "recordMode" || name == "playMode")
result[name] = val;
else if (name == "live" || name == "record" || name == "bidirection")
result[name] = (val != "false");
else if (name == "arg")
result.args.push(val);
}
// initialize all read-only propeties
setProperty("args", result.args);
setProperty("scheme", result.scheme);
setProperty("farID", result.farID);
setProperty("group", result.group);
setProperty("bytesLoaded", new Number(0));
setProperty("bytesTotal", new Number(0));
setProperty("videoWidth", NaN);
setProperty("videoHeight", NaN);
setProperty("liveDelay", NaN);
setProperty("currentFPS", NaN);
setProperty("playerState", null);
if ('bidirection' in result)
setProperty("bidirection", result.bidirection);
this.level = 0;
this.playMode = (result.scheme == "http" || result.scheme == "https" ? "web" : (result.playMode == "vod" ? "vod" : "live"));
this.recordMode = result.recordMode == "append" ? "append" : "record";
this.record = result.record || (result.recordMode == "append" || result.recordMode == "record");
this.url = result.url;
if (result.publish || result.play) {
if (this.bidirection) {
this.publish = result.publish;
this.play = result.play;
}
else if (result.publish) {
this.play = null;
this.publish = result.publish;
}
else if (result.play) {
this.publish = null;
this.live = false;
this.play = result.play;
}
}
else {
this.publish = null;
this.play = null;
this.live = result.live;
}
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "src", oldValue, value));
}
}
public const __doc__poster:String =
'The "poster" read-write string property represents the initial image to display before video ' +
'is started to publish or play. This should be an http URL. Example\n' +
' http://kundansingh.com/images/face.jpg\n';
[Bindable('propertyChange')]
/**
* The poster (or initial image) to display before video is started or
* connected.
*/
public function get poster():String
{
return _poster;
}
public function set poster(value:String):void
{
var oldValue:String = _poster;
_poster = value;
if (oldValue != value) {
if (oldValue != null)
detachPoster();
if (value != null)
attachPoster();
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "poster", oldValue, value));
}
}
public const __doc__posterBackgroundAlpha:String =
'The "posterBackgroundAlpha" read-write number property represents the background alpha ' +
'of the poster image. If the value is 0 or NaN the background is not displayed. Otherwise ' +
'the same poster images is faded using the value alpha, streched and displayed as background\n';
[Bindable('propertyChange')]
/**
* The posterBackgroundAlpha is greater than 0 indicates that a background is displayed
* as a faded poster using this alpha.
*/
public function get posterBackgroundAlpha():Number
{
return _posterBackgroundAlpha;
}
public function set posterBackgroundAlpha(value:Number):void
{
var oldValue:Number = _posterBackgroundAlpha;
_posterBackgroundAlpha = value;
if (oldValue != value) {
if (!isNaN(oldValue))
detachPosterBackground();
if (!isNaN(value))
attachPosterBackground();
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "posterBackgroundAlpha", oldValue, value));
}
}
public const __doc__preload:String =
'The "preload" read-write boolean property controls whether the video should be pre-loaded ' +
'before it is played.\n';
[Bindable('propertyChange')]
/**
* The preload property controls whether the video should be pre-loaded before
* the user starts play.
*/
public function get preload():Boolean
{
return _preload;
}
public function set preload(value:Boolean):void
{
var oldValue:Boolean = _preload;
_preload = value;
if (oldValue != value) {
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "src", oldValue, value));
}
}
public const __doc__autoplay:String =
'The "autoplay" read-write boolean property controls whether the video should be played ' +
'automatically when the "src" property is assigned and video is loaded, or should it wait ' +
'for explicit play command using the "playing" property. The default is true indicating ' +
'automatic play when ready.\n';
[Bindable('propertyChange')]
/**
* The autoplay property controls whether the video should be played automatically
* when started.
*/
public function get autoplay():Boolean
{
return _autoplay;
}
public function set autoplay(value:Boolean):void
{
var oldValue:Boolean = _autoplay;
_autoplay = value;
if (oldValue != value) {
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "autoplay", oldValue, value));
}
}
public const __doc__loop:String =
'The "loop" read-write boolean property controls whether the video should loop to begining ' +
'when it reaches the end.\n';
[Bindable('propertyChange')]
/**
* The loop property controls whether the video should be looped after completed.
*/
public function get loop():Boolean
{
return _loop;
}
public function set loop(value:Boolean):void
{
var oldValue:Boolean = _loop;
_loop = value;
if (oldValue != value) {
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "loop", oldValue, value));
}
}
public const __doc__controls:String =
'The "controls" read-write boolean property controls whether the video control panel should ' +
'be displayed or not. Default is false. The current implementation displays a video control ' +
'panel at the bottom of the user interface view. The control panel automatically hides if ' +
'there is no mouse activity for some time, and the mouse is not over the control panel. If ' +
'the mouse is rolled over the control panel, the view remains visible. Later, if the user moves ' +
'the mouse anywhere on the video view, the control panel re-appears if it was hidden before. ' +
'By the default, the control panel displays various control buttons based on the current state. ' +
'For example, if the "play" property is set, then the play/pause, speaker and volume ' +
'controls are displayed, whereas if the "publish" property is set, then the record/stop, ' +
'camera, microphone and gain controls are displayed.\n';
[Bindable('propertyChange')]
/**
* The controls property controls whether the video should display user controls or not.
*/
public function get controls():Boolean
{
return (_controls != null);
}
public function set controls(value:Boolean):void
{
var oldValue:Boolean = (_controls != null);
if (value && _controls == null) {
_controls = new VideoControl();
this.addChild(_controls);
}
else if (!value && _controls != null) {
this.removeChild(_controls);
_controls = null;
}
if (oldValue != value) {
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "controls", oldValue, value));
}
}
public const __doc__detectActivity:String =
'The "detectActivity" read-write boolean property controls whether the mouse activity is ' +
'detected, e.g., to automatically hide the control bar. Default is "true".\n';
[Bindable('propertyChange')]
/**
* The detectActivity property controls whether the mouse activity is detected or not?
*/
public function get detectActivity():Boolean
{
return _detectActivity;
}
public function set detectActivity(value:Boolean):void
{
var oldValue:Boolean = _detectActivity;
_detectActivity = value;
if (oldValue != value) {
if (_controls != null && (_controls is VideoControl)) {
if (value)
VideoControl(_controls).startHideTimer();
else
VideoControl(_controls).stopHideTimer();
}
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "detectActivity", oldValue, value));
}
}
public const __doc__args:String =
'The "args" read-only array of values represents the connection arguments captured from ' +
'the "src" URL\'s "arg" parameters. For example if "src" is set to ' +
'"rtmp://server/record?publish=live&arg=myuser&arg=mypass" then the "args" property will ' +
'be ["myuser","mypass"].\n';
/**
* The read-only args property defines the connect() arguments if any.
* This is set using zero of more arg params in the "src" URL.
*/
public function get args():Array
{
return _args;
}
public const __doc__scheme:String =
'The "scheme" read-only string property indicates the scheme of the "src" URL. ' +
'It is set automatically when the "src" property is set.\n';
/**
* The read-only URL scheme property of the URL.
* This is set using the scheme of the "src" URL.