| By Stefan Richter | Article Rating: |
|
| October 12, 2005 03:00 PM EDT | Reads: |
26,422 |
For more information on setQuality, setRate and all the other Flash Communication Server-related objects and methods you should consult the excellent Flash Communication Server Documentation and Live Docs.
You are now ready for your first test run. Press Control+Enter or select Control > Test Movie to see what happens. Enter a valid rtmp address into the first text box (for example, rtmp:/livecast for local servers or rtmp://yourserver.com/livecast for remote servers), as well as a stream name into the text box below below. Click Connect. Your screen should look somewhat similar to Figure 3 (the cheeky grin is optional).
Did it work? Great. Pat yourself on the back-now let's build the live video receiver.
Building the Live Video Receiver
The receiver is simply an adaptation of the broadcasting application. Make sure you save the broadcaster.fla file and then save a copy under the new name of receiver.fla.
Here's what your receiver needs to do:
- Connect to Flash Communication Server.
- Create a receiving NetStream object.
- Display the stream. Sounds like you merely need to strip back some functionality rather than add anything new.
Also, the connect_pb.onRelease function can be stripped of the following line:
startstop_pb.enabled = false;
In fact, you can remove any references to startstop_pb.
The NetConnection object's onStatus handler also needs some minor modifications. After a "NetConnection.Connect.Success" message is received, you need to create a NetStream object, add an onStatus handler to it (in order to see some trace output on the Stage) and attach the stream to your video object (myvid.attachVideo(ns)) in order to display the feed. There is no need to anything similar to the microphone or sound object, because the sound that is broadcast is contained within the same NetStream object. Therefore attachVideo in this case actually means attaching video and sound.
connect_pb.onRelease = function(){
if(this.label == "Connect"){
status_txt.text += "Connecting..." + newline;
this.label = "Disconnect";
nc.connect(rtmp_txt.text);
} else {
status_txt.text += "Disconnecting." + newline;
this.label = "Connect";
nc.close();
}
}
To finish, add the ns.play command at the end. Here's the completed code:
As you can see instead of attaching a camera and microphone to the NetStream object we instead call the play method and pass it the current value of streamname_txt as its first parameter. Of course this parameter (the name of the stream which should be played back) needs to match the name of the stream you will be broadcasting through the broadcaster application.
nc = new NetConnection();
nc.onStatus = function(info) {
status_txt.text += "NC.onStatus> info.code: " + info.code + newline;
if (info.code == "NetConnection.Connect.Success") {
status_txt.text = "Connected to " + this.uri + newline;
ns = new NetStream(nc);
ns.onStatus = function(info) {
status_txt.text += "NS.onStatus> info.code: " + info.code + newline;
}
myvid.attachVideo(ns);
ns.play(streamname_txt.text, -1)
}
}
Time for another pat on the shoulder - you are now ready to go on the air.
Lights, Camera, Action
Publish both movies, then open them side by side. You can either use two browser windows or two standalone Flash Player applications - the choice is yours.
Press the Connect button in both applications, followed by the Start Broadcast button in your broadcaster application. If you followed my directions, then your screen should look similar to Figure 4 (minus that funny-looking guy with glasses).
If you are having problems connecting to your server or the application isn't working as expected, then don't worry - you can download the completed source files from page 1 of this tutorial, and you can modify those to suit your needs.
First, however, make sure that you are using the correct rtmp string and that the server you are trying to connect to is actually running. Don't laugh, it happens all the time.
Where to Go from Here
The example in this tutorial should give you a good basis for additional features. You may want to add a slider component to change your camera's broadcast settings on the fly. Or how about adding a NetStream.send command to send text information across the live stream? Or even simpler, try adding a microphone mute button, which enables you to start and stop audio transmissions independently from the video stream.
Please visit my forum at www.flashcomguru.com/forum/default.asp where you will find a thread accompanying this article.
Published October 12, 2005 Reads 26,422
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Stefan Richter
Stefan Richter is a Certified Flash Developer and Team Macromedia member who has been involved with Flash Communication Server since its early days. As VP of Application Development and cofounder of POPview, he has developed a variety of Rich Internet Applications using Flash Communication Server, Flash MX 2004 and Coldfusion. You can find more of Stefan's articles at www.flashcomguru.com.
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Adobe Flex Developer Earns $100K in New York City
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Ph.D. in Twitter Anyone?
- Eolas Sues the Internet
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Special Report on the Emerging Cloud Computing Trend
- Adobe Cans Another 9% of its Workforce
- My Thoughts on Ulitzer
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Ulitzer Live! New Media Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Executives Feature on Cloud Computing Expo Power Panel
- Software Flexibility in the Cloud - Part 4 of 5
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Where Are RIA Technologies Headed in 2008?
- Cover Story: How to Increase the Frame Rates of Your Flash Movies
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Your First Adobe Flex Application with a ColdFusion Backend
- Adobe Flex 2: Advanced DataGrid
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe/Macromedia - Microsoft, Look Out!
- How To Create a Photo Slide Show ...
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- Has the Technology Bounceback Begun?
- "Real-World Flex" by Adobe's Christophe Coenraets







































