
Chapter 3 34
4 In the initStreams function, make a connection to the server. Create the output stream for
sending the video data to the server, and the input stream for the data coming back from the
server. Then attach the input stream to the
Replay_video video clip.
function initStreams() {
// Make a connection to the application on the server
client_nc = new NetConnection();
// Note that this call includes the protocol, rtmp, the
// app name, doc_record, and the room, room_01
client_nc.connect("rtmp:/doc_record/room_01");
// Handle status message
client_nc.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code);
}
// Create output stream
out_ns = new NetStream(client_nc);
// Create input stream
in_ns = new NetStream(client_nc);
Replay_video.attachVideo(in_ns);
}
// Connect to server and set up streams
initStreams();
5
Create the event handler for the Record button. If the user selected the button when the label
was Record, then attach video data from the camera to the output stream and publish it. If the
button label is Stop, close the stream.
function doRecord() {
if (Record_btn.getLabel() == "Record") {
// Start publishing the camera output as a recorded stream
out_ns.attachVideo(Camera.get());
out_ns.publish("my_recorded_stream", "record");
// Don’t allow the user to play when recording
Play_btn.setEnabled(false);
// Change the button label
Record_btn.setLabel("Stop");
} else if (Record_btn.getLabel() == "Stop") {
// Close output stream
out_ns.close();
// Now that you’re finished recording, allow the user to play
Play_btn.setEnabled(true);
// Change the button label
Record_btn.setLabel("Record");
}
}
Commenti su questo manuale