Skip to content

Commit b52ebc8

Browse files
committed
simpler and smarter test rtmp publisher
1 parent 6b92cd6 commit b52ebc8

File tree

3 files changed

+32
-66
lines changed

3 files changed

+32
-66
lines changed

test/rtmp-publisher/RtmpPublisher.mxml

Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
xmlns:mx="library://ns.adobe.com/flex/mx"
55
minWidth="500" minHeight="350" creationComplete="init()">
66

7-
<fx:Declarations>
8-
<!-- Place non-visual elements (e.g., services, value objects) here -->
9-
</fx:Declarations>
10-
117
<fx:Script>
128
<![CDATA[
139
import mx.controls.Alert;
1410
import mx.core.FlexGlobals;
11+
import mx.events.FlexEvent;
12+
import spark.skins.spark.PanelSkin;
13+
1514
private var streamer:String;
1615
private var file:String;
1716
private var camera:Camera;
@@ -20,98 +19,65 @@
2019
private var stream:NetStream;
2120
private var h264Settings:H264VideoStreamSettings;
2221
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);
3028
} else {
31-
toggleFeed.label = 'Start Feed';
29+
publishButton.label = 'Publish';
3230
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;
5834
}
5935
}
6036
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-
6737
private function netStatusHander(event:NetStatusEvent):void {
6838
switch(event.info.code) {
6939
case 'NetConnection.Connect.Success':
7040
stream = new NetStream(connection);
7141
stream.attachCamera(camera);
7242
stream.attachAudio(microphone);
7343
h264Settings = new H264VideoStreamSettings();
74-
h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_1_2);
44+
h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_3_1);
7545
stream.videoStreamSettings = h264Settings;
46+
stream.publish(file, 'live');
7647
break;
7748
}
7849
}
7950
8051
private function init():void {
8152
streamer = FlexGlobals.topLevelApplication.parameters.streamer;
53+
if(streamer == null) {
54+
Alert.show('Missing flashvars: streamer');
55+
return;
56+
}
57+
8258
file = FlexGlobals.topLevelApplication.parameters.file;
8359
if(file == null) {
8460
Alert.show('Missing flashvars: file');
8561
return;
8662
}
87-
if(streamer == null) {
88-
Alert.show('Missing flashvars: streamer');
89-
return;
90-
}
91-
initListeners();
63+
64+
publishButton.addEventListener(MouseEvent.CLICK, publishButtonListener);
9265
9366
camera = Camera.getCamera();
67+
camera.setMode(640, 480, 30);
68+
camera.setQuality(131072, 70);
69+
70+
videoDisplay.attachCamera(camera);
71+
9472
microphone = Microphone.getMicrophone();
9573
microphone.setSilenceLevel(0);
9674
microphone.codec = "Speex";
9775
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-
10476
}
10577
]]>
10678
</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>
11783
</s:Application>

test/rtmp-publisher/RtmpPublisher.swf

-397 Bytes
Binary file not shown.

test/rtmp-publisher/publisher.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
streamer: 'rtmp://localhost/myapp',
99
file:'mystream'
1010
};
11-
swfobject.embedSWF("RtmpPublisher.swf", "rtmp-publisher", "500", "400", "9.0.0", null, flashVars);
11+
swfobject.embedSWF("RtmpPublisher.swf", "rtmp-publisher", "640", "480", "9.0.0", null, flashVars);
1212
</script>
1313
</head>
1414
<body>

0 commit comments

Comments
 (0)