|
4 | 4 | xmlns:mx="library://ns.adobe.com/flex/mx"
|
5 | 5 | minWidth="500" minHeight="350" creationComplete="init()">
|
6 | 6 |
|
7 |
| - <fx:Declarations> |
8 |
| - <!-- Place non-visual elements (e.g., services, value objects) here --> |
9 |
| - </fx:Declarations> |
10 |
| - |
11 | 7 | <fx:Script>
|
12 | 8 | <![CDATA[
|
13 | 9 | import mx.controls.Alert;
|
14 | 10 | import mx.core.FlexGlobals;
|
| 11 | + import mx.events.FlexEvent; |
| 12 | + import spark.skins.spark.PanelSkin; |
| 13 | +
|
15 | 14 | private var streamer:String;
|
16 | 15 | private var file:String;
|
17 | 16 | private var camera:Camera;
|
|
20 | 19 | private var stream:NetStream;
|
21 | 20 | private var h264Settings:H264VideoStreamSettings;
|
22 | 21 |
|
23 |
| - private function toggleFeedListener(event:MouseEvent):void { |
24 |
| - if(toggleFeed.label == 'Start Feed') { |
25 |
| - toggleFeed.label = 'Stop Feed'; |
26 |
| - stream.publish(file, 'live'); |
27 |
| - videoDisplay.attachCamera(camera); |
28 |
| - toggleVideo.enabled = true; |
29 |
| - toggleAudio.enabled = true; |
| 22 | + private function publishButtonListener(event:MouseEvent):void { |
| 23 | + if(publishButton.label == 'Publish') { |
| 24 | + publishButton.label = 'Stop'; |
| 25 | + connection = new NetConnection(); |
| 26 | + connection.connect(streamer); |
| 27 | + connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHander); |
30 | 28 | } else {
|
31 |
| - toggleFeed.label = 'Start Feed'; |
| 29 | + publishButton.label = 'Publish'; |
32 | 30 | stream.close();
|
33 |
| - videoDisplay.attachCamera(null); |
34 |
| - toggleVideo.enabled = false; |
35 |
| - toggleAudio.enabled = false; |
36 |
| - } |
37 |
| - } |
38 |
| -
|
39 |
| - private function toggleVideoListener(event:MouseEvent):void { |
40 |
| - if(toggleVideo.label == 'Start Video') { |
41 |
| - toggleVideo.label = 'Stop Video'; |
42 |
| - videoDisplay.attachCamera(camera); |
43 |
| - stream.attachCamera(camera); |
44 |
| - } else { |
45 |
| - toggleVideo.label = 'Start Video'; |
46 |
| - videoDisplay.attachCamera(null); |
47 |
| - stream.attachCamera(null); |
48 |
| - } |
49 |
| - } |
50 |
| -
|
51 |
| - private function toggleAudioListener(event:MouseEvent):void { |
52 |
| - if(toggleAudio.label == 'Start Audio') { |
53 |
| - toggleAudio.label = 'Stop Audio'; |
54 |
| - stream.attachAudio(microphone); |
55 |
| - } else { |
56 |
| - toggleAudio.label = 'Start Audio'; |
57 |
| - stream.attachAudio(null); |
| 31 | + connection.close(); |
| 32 | + stream = null; |
| 33 | + connection = null; |
58 | 34 | }
|
59 | 35 | }
|
60 | 36 |
|
61 |
| - private function initListeners():void { |
62 |
| - toggleFeed.addEventListener(MouseEvent.CLICK, toggleFeedListener); |
63 |
| - toggleVideo.addEventListener(MouseEvent.CLICK, toggleVideoListener); |
64 |
| - toggleAudio.addEventListener(MouseEvent.CLICK, toggleAudioListener); |
65 |
| - } |
66 |
| -
|
67 | 37 | private function netStatusHander(event:NetStatusEvent):void {
|
68 | 38 | switch(event.info.code) {
|
69 | 39 | case 'NetConnection.Connect.Success':
|
70 | 40 | stream = new NetStream(connection);
|
71 | 41 | stream.attachCamera(camera);
|
72 | 42 | stream.attachAudio(microphone);
|
73 | 43 | h264Settings = new H264VideoStreamSettings();
|
74 |
| - h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_1_2); |
| 44 | + h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_3_1); |
75 | 45 | stream.videoStreamSettings = h264Settings;
|
| 46 | + stream.publish(file, 'live'); |
76 | 47 | break;
|
77 | 48 | }
|
78 | 49 | }
|
79 | 50 |
|
80 | 51 | private function init():void {
|
81 | 52 | streamer = FlexGlobals.topLevelApplication.parameters.streamer;
|
| 53 | + if(streamer == null) { |
| 54 | + Alert.show('Missing flashvars: streamer'); |
| 55 | + return; |
| 56 | + } |
| 57 | +
|
82 | 58 | file = FlexGlobals.topLevelApplication.parameters.file;
|
83 | 59 | if(file == null) {
|
84 | 60 | Alert.show('Missing flashvars: file');
|
85 | 61 | return;
|
86 | 62 | }
|
87 |
| - if(streamer == null) { |
88 |
| - Alert.show('Missing flashvars: streamer'); |
89 |
| - return; |
90 |
| - } |
91 |
| - initListeners(); |
| 63 | +
|
| 64 | + publishButton.addEventListener(MouseEvent.CLICK, publishButtonListener); |
92 | 65 |
|
93 | 66 | camera = Camera.getCamera();
|
| 67 | + camera.setMode(640, 480, 30); |
| 68 | + camera.setQuality(131072, 70); |
| 69 | +
|
| 70 | + videoDisplay.attachCamera(camera); |
| 71 | +
|
94 | 72 | microphone = Microphone.getMicrophone();
|
95 | 73 | microphone.setSilenceLevel(0);
|
96 | 74 | microphone.codec = "Speex";
|
97 | 75 | microphone.encodeQuality = 6;
|
98 |
| - camera.setMode(704, 576, 25); |
99 |
| - camera.setQuality(131072, 70); |
100 |
| - connection = new NetConnection(); |
101 |
| - connection.connect(streamer); |
102 |
| - connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHander); |
103 |
| -
|
104 | 76 | }
|
105 | 77 | ]]>
|
106 | 78 | </fx:Script>
|
107 |
| - <s:Panel x="0" y="0" width="100%" height="100%" title="RTMP Publisher"> |
108 |
| - <mx:VideoDisplay width="100%" height="100%" id="videoDisplay"> |
109 |
| - </mx:VideoDisplay> |
110 |
| - <s:controlBarContent> |
111 |
| - <s:Button label="Start Feed" id="toggleFeed"></s:Button> |
112 |
| - <s:Spacer width="100%" height="100%"/> |
113 |
| - <s:Button label="Stop Video" id="toggleVideo" enabled="false"></s:Button> |
114 |
| - <s:Button label="Stop Audio" id="toggleAudio" enabled="false"></s:Button> |
115 |
| - </s:controlBarContent> |
116 |
| - </s:Panel> |
| 79 | + <s:BorderContainer x="0" y="0" width="100%" height="100%"> |
| 80 | + <mx:VideoDisplay width="100%" height="100%" id="videoDisplay"></mx:VideoDisplay> |
| 81 | + <s:Button label="Publish" id="publishButton" horizontalCenter="0" verticalCenter="220"></s:Button> |
| 82 | + </s:BorderContainer> |
117 | 83 | </s:Application>
|
0 commit comments