forked from bobagold/rtmp-publisher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RtmpPublisher.mxml
108 lines (98 loc) · 3.35 KB
/
RtmpPublisher.mxml
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
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="500" minHeight="350" creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.FlexGlobals;
private var streamer:String;
private var file:String;
private var camera:Camera;
private var microphone:Microphone;
private var connection:NetConnection;
private var stream:NetStream;
private function toggleFeedListener(event:MouseEvent):void {
if(toggleFeed.label == 'Start Feed') {
toggleFeed.label = 'Stop Feed';
stream.publish(file, 'live');
videoDisplay.attachCamera(camera);
toggleVideo.enabled = true;
toggleAudio.enabled = true;
} else {
toggleFeed.label = 'Start Feed';
stream.close();
videoDisplay.attachCamera(null);
toggleVideo.enabled = false;
toggleAudio.enabled = false;
}
}
private function toggleVideoListener(event:MouseEvent):void {
if(toggleVideo.label == 'Start Video') {
toggleVideo.label = 'Stop Video';
videoDisplay.attachCamera(camera);
stream.attachCamera(camera);
} else {
toggleVideo.label = 'Start Video';
videoDisplay.attachCamera(null);
stream.attachCamera(null);
}
}
private function toggleAudioListener(event:MouseEvent):void {
if(toggleAudio.label == 'Start Audio') {
toggleAudio.label = 'Stop Audio';
stream.attachAudio(microphone);
} else {
toggleAudio.label = 'Start Audio';
stream.attachAudio(null);
}
}
private function initListeners():void {
toggleFeed.addEventListener(MouseEvent.CLICK, toggleFeedListener);
toggleVideo.addEventListener(MouseEvent.CLICK, toggleVideoListener);
toggleAudio.addEventListener(MouseEvent.CLICK, toggleAudioListener);
}
private function netStatusHander(event:NetStatusEvent):void {
switch(event.info.code) {
case 'NetConnection.Connect.Success':
stream = new NetStream(connection);
stream.attachCamera(camera);
stream.attachAudio(microphone);
break;
}
}
private function init():void {
streamer = FlexGlobals.topLevelApplication.parameters.streamer;
file = FlexGlobals.topLevelApplication.parameters.file;
if(file == null) {
Alert.show('Missing flashvars: file');
return;
}
if(streamer == null) {
Alert.show('Missing flashvars: streamer');
return;
}
initListeners();
camera = Camera.getCamera();
microphone = Microphone.getMicrophone();
connection = new NetConnection();
connection.connect(streamer);
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHander);
}
]]>
</fx:Script>
<s:Panel x="0" y="0" width="100%" height="100%" title="RTMP Publisher">
<mx:VideoDisplay width="100%" height="100%" id="videoDisplay">
</mx:VideoDisplay>
<s:controlBarContent>
<s:Button label="Start Feed" id="toggleFeed"></s:Button>
<s:Spacer width="100%" height="100%"/>
<s:Button label="Stop Video" id="toggleVideo" enabled="false"></s:Button>
<s:Button label="Stop Audio" id="toggleAudio" enabled="false"></s:Button>
</s:controlBarContent>
</s:Panel>
</s:Application>