The i-Technology Media!
Register | Log in
   
 
.NET  ·  AJAX  ·  CLOUD  ·  ECLIPSE  ·  FLEX  ·  OPEN WEB  ·  iPHONE  ·  JAVA  ·  LINUX  ·  OPEN SOURCE  ·  ORACLE  ·  PBDJ  ·  SEARCH  ·  SILVERLIGHT  ·  SOA  ·  VIRTUALIZATION  ·  WEB 2.0  ·  WIRELESS  ·  XML
YOUR FEEDBACK
Cloud Envelops Exchange & SharePoint
the usr wrote: So... how about your prediction that SCO would prevail? 11/20/2008 565 - FINAL...
Nov. 22, 2008 07:46 AM
Cloud Computing Conference
November 19-21 San Jose, CA
Register Today and SAVE !..
Did you read today's front page stories & breaking news?
Live Google News by SYS-CON!

TOP THREE LINKS YOU MUST CLICK ON


Flash
Building a Simple Live Video Broadcaster and Receiver
Learn how to leverage the power of Flash Communication Server MX to add video and audio communications to your Flash apps

By: Stefan Richter
Oct. 12, 2005 03:00 PM
  • 1
  • 2
  • 3
  • next ›
  • last »

Macromedia Flash Communication Server MX (popularly referred to as Flashcom) is becoming an increasingly popular platform for the efficient delivery of streaming video to large audiences. Many content delivery networks such as Speedera and Vitalstream have teamed up with Macromedia to offer their clients a platform to stream prerecorded videos easily and efficiently. However, the Flash Communication Server capabilities do by no means end there. The platform is also an ideal choice to deliver live-event broadcasts in real time across the globe - all through a familiar and very accessible Macromedia Flash front end.

In this article I will walk you through the development of a simple live broadcast application which captures your local microphone and camera sources and publishes them with the help of Flash Communication Server over the Internet. You will also learn how to build a player that is capable of subscribing to the broadcast and playing it back to your viewers.

Note: The sample FLA files are not needed to complete this tutorial but are provided for reference in case of any problems.

Creating the Server-side Application
To set up an application on your Flash Communication Server, all you need to do is to create a folder inside your server's application directory. Most applications will also require some server-side code, usually in the form of a main.asc file. However, since this is a very basic application, you do not need any server-side code at all.

To create your application, simply create a new folder inside your Flash Communication Server application directory, and call it livecast. On Windows, this folder's default location is C:\Program Files\Macromedia\Flash Communication Server MX\applications\.

Note: There is no need to restart your server or vhost at this point. Remember, however, that every time you make changes to any server-side code you must restart the application that you have modified, or else you will not see your code changes reflected in your application logic.

Building the Live Video Broadcaster
Both applications that you are about to build are very similar. Each one will connect to your Flash Communication Server application and stream audio and video data. The main difference between the two files is that the broadcaster will publish the video and audio whereas the receiver - you guessed it - receives it. Therefore the broadcaster will contain a little more code than the receiver, because it needs to access your camera and microphone as well as handle the NetConnection and NetStream objects.

Building the live video broadcaster involves the following steps:

  1. Creating a new FLA file
  2. Laying out the user interface
  3. Connecting to your Flash Communication Server application
  4. Creating a NetStream object and publishing your stream
Step 1: Create a New FLA File
Open Flash MX 2004 and choose File > New or press Control+N to create a new FLA file. Rename your existing layer to UI. Create a new layer above your existing layer and name it actions. Save your FLA file in a directory of your choice and name it broadcaster.fla.

Step 2: Lay Out the User Interface
Select Window > Development Panels > Components or press Control+F7 to open the components panel. Next drag the following components onto the Stage:

  • Two TextInput components
  • One TextArea component
  • Three Label components
  • Two Button components
Open your library (by selecting Window > Library or pressing Control+L) and add a new video object to it. To create a new video object, click the little button in the top right corner of your Library panel and select New Video (see Figure 1).

You will see a new symbol Embedded Video 1, in your library. Drag it onto the Stage and give it an instance name of myvid. Later you will display your local camera feed inside this video object. I also drew a thin outline around the video object in my application to make it visible before a video is being displayed. This border is optional.

Name one of your buttons on the Stage connect_pb and give it a label of Connect. Name the second button startstop_pb and give this one a label of Start Broadcast.

Give your label components the text properties of rtmp address for the first component, stream name for the second component, and status output for the third component. The label components simply clarify the purpose of your text input and text area components. You can omit the labels altogether if you want, because they play no significant role in the actual application logic.

Give the two TextInput components instance names of rtmp_txt and streamname_txt, respectively.

Name the text area component status_txt; you will be using it to output status and trace information.

Align all these elements as you see fit, or use my layout (see Figure 2).

Step 3: Connect to Your Flash Communication Server Application
To successfully connect to a Flash Communication Server application instance, you must:

  1. Create a NetConnection object.
  2. Define an onStatus() method for it.
  3. Call the NetConnection object's connect() method.
Select Frame 1 of the actions layer and add the following code to it:

startstop_pb.enabled = false;

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";
startstop_pb.enabled = false;
nc.close();
}
}

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;
startstop_pb.enabled = true;
} else if (info.code == "NetConnection.Connect.Closed") {
startstop_pb.enabled = false;
startstop_pb.label = "Start Broadcast";
myvid.attachVideo(null);
myvid.clear();
}
}
  • 1
  • 2
  • 3
  • next ›
  • last »
Published Oct. 12, 2005— Reads 25,179
Copyright © 2008 SYS-CON Media. All Rights Reserved.
About 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.

Add Your Feedback

In order to post a comment you need to be registered and logged in.

Register | Log in

Please wait while we process your request...





SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE

ADVERTISE   |   MAGAZINE SUBSCRIPTIONS   |   FREE BREAKING-NEWSLETTERS!   |   SYS-CON.TV   |   BLOG-N-PLAY!   |   WEBCAST   |   EDUCATION   |   RESEARCH

.NET Developer's Journal - .NETDJ   |   ColdFusion Developer's Journal - CFDJ   |   Eclipse Developer's Journal - EDJ   |   Enterprise Open Source Magazine - EOS
Open Web Developer's Journal - OPENWEB   |   iPhone Developer's Journal - iPHONE   |   Virtualization - Virtualization   |   Java Developer's Journal - JDJ   |   Linux.SYS-CON.com
PowerBuilder Developer's Journal - PBDJ   |   SEO / SEM Journal - SJ   |   SOAWorld Magazine - SOAWM   |   IT Solutions Guide - ITSG   |   Symbian Developer's Journal - SDJ
WebLogic Developer's Journal - WLDJ   |   WebSphere Journal - WJ   |   Wireless Business & Technology - WBT   |   XML-Journal - XMLJ   |   Internet Video - iTV
Flex Developer's Journal - Flex   |   AJAXWorld Magazine - AWM   |   Silverlight Developer's Journal - SLDJ   |   PHP.SYS-CON.com   |   Web 2.0 Journal - WEB2
Apache   |   CMS   |   CRM   |   HP   |   Oracle Journal   |   Perl   |   Python   |   Red Hat   |   Ruby on Rails   |   SAP   |   SaaS

SYS-CON MEDIA:   ABOUT US   |   CONTACT US   |   COMPANY NEWS   |   CAREERS   |   SITE MAP
SYS-CON EVENTS:   |  AJAXWorld Conference & Expo  |  iPhone Developer Summit  |  OpenWeb Developer Summit  |  SOA World Conference & Expo  |  Virtualization Conference & Expo
INTERNATIONAL SITES:   India  |  U.K.  |  Canada  |  Germany  |  France  |  Australia  |  Italy  |  Spain  |  Netherlands  |  Brazil  |  Belgium
 Terms of Use & Our Privacy Statement     About Newsfeeds / Video Feeds
Copyright ©1994-2008 SYS-CON Publications, Inc. All Rights Reserved. All marks are trademarks of SYS-CON Media.
Reproduction in whole or in part in any form or medium without express written permission of SYS-CON Publications, Inc. is prohibited.
 
close this window