LearningFlashMediaServer3
byWilliamB.Sanders
Publisher:O'Reilly
PubDate:March31,2008
PrintISBN-13:978-0-596-51590-4
Pages:273
TableofContents
Overview
Ifyou'reinterestedinrecordingandstreamingmediausing
FlashMediaServer3(FMS3)andAdobe'sReal-TimeMessaging
Protocol,thisunique267-pagePDF-onlybookistheperfect
primer.Itisnotareference,butasystematicguideto
developingFMS3applicationsusingActionScript3.0,with
chaptersthatfocusonspecificaspectsoftheserverandhow
theywork.FMS3isverydifferentfromregularwebservers.
Becauseitsopen-socketservertechnologystaysconnecteduntil
usersquittheapplication,youcanstreamaudio,video,text,
andothermediainrealtime.FMS3isalsoquitedifferentfrom
previousversions,afactthatwebdevelopersfamiliarwithFlash
MediaServer2orFlashCommunicationServer1.5willquickly
discover.Don'tworry.WithLearningFlashMediaServer3anda
littleexperiencewithFlashCS3andActionScript3.0,anyone
cangetuptospeedinnotime.You'lllearnhowtoinstallFMS3,
organizeyourdevelopmentenvironmentwithApacheweb
server,andusethemanagementconsolebeforedivingintothe
whysandhowsof:
Recordingandplayingbackstreamingaudioandvideoin
VP6andH.264formats
UsingthenewFlashMediaEncodertostreamandrecord
video
Cameraandmicrophonesettings
Non-persistentclient-sideremotesharedobjects
Two-wayaudio-videocommunications
Broadcastingandserver-sidebandwidthcontrol
Workingwithserver-sidefiles:thefileclass
Server-sidesharedobjects
Server-sidestreams
SettingupasoftwareloadhandlerusingFMS3'snew
server-sideNetStream
Bringingindataandworkingwithconfigurationfiles
Attheheartofeverychapterisacoresetofcodethatshows
theminimumrequirementsneededfordifferentprocedures.
Beyondthat,LearningFlashMediaServer3providesyouwith
plentyofoptionsforusingFMS3'sdifferentversions--thefullfeatureserver,thestreaming-onlyserver,andthelimited-user
developmentserver.It'sawholenewworldofmedia,andthis
bookputsyourightatthedoorstep.Readytoenter?
LearningFlashMediaServer3
byWilliamB.Sanders
Publisher:O'Reilly
PubDate:March31,2008
PrintISBN-13:978-0-596-51590-4
Pages:273
TableofContents
Copyright
Chapter1.GettingStartedwithFlashMediaServer3
Section1.1.TheNewFlavorsforFlashMediaServer3
Section1.2.WhatIsaMediaServer?
Section1.3.InstallingFMS3
Section1.4.OrganizingYourDevelopmentEnvironment
Section1.5.TestingFMS3Connections
Section1.6.UsingtheFMS3AdministrationConsole
Section1.7.UsingThisBook
Chapter2.RecordingandPlayingBackStreamingAudioand
Video
Section2.1.StreamingandBroadcasting
Section2.2.MinimalistProject
Section2.3.CombinedRecordandPlaybackApplication
Chapter3.SettingYourCameraandMicrophone
Section3.1.CameraandMicrophoneMethodsforSetting
Parameters
Section3.2.MinimalistProject
Section3.3.DynamicallyTestingYourCameraand
MicrophoneSettings
Section3.4.KeyConsiderations
Section3.5.AdjustingCameraandAudiowithFlashMedia
Encoder
Chapter4.NonpersistentClient-SideRemoteSharedObjects
Section4.1.SharingDataonMultipleConnections
Section4.2.InstantiatingRemoteSharedObjects
Section4.3.MinimalistProjectforSharedMovieClip
Section4.4.MinimalistProjectforSharedText
Section4.5.MinimalistProjectforSharedFunction
Section4.6.AnUpgradedTextChat
Chapter5.Two-WayAudio-VideoCommunications
Section5.1.Face-to-FaceCommunication
Section5.2.TheNetStreamBundle
Section5.3.TheNetStreamClassandLiveStreams
Section5.4.TheWorld'sEasiestTwo-WayA/VChat
Application
Section5.5.ABetterTwo-WayChatApplication
Section5.6.Four-WayConferenceApplication
Section5.7.MovingOntoMoreServer-SideApplications
Chapter6.BroadcastingandServer-SideBandwidthControl
Section6.1.CastingManyStreams
Section6.2.SwitchingCameras
Section6.3.TheMinimumStudio
Section6.4.IntroductiontotheServerSide
Section6.5.DynamicCamera,Microphone,andBandwidth
Controls
Section6.6.BandwidthChecker
Section6.7.Conclusion
Chapter7.WorkingWithServer-SideFiles:TheFileClass
Section7.1.RecordingData
Section7.2.TheFileClass
Section7.3.Client-SideFormatting
Section7.4.Server-SideFormatting
Section7.5.Beggar'sDatabase
Chapter8.Server-SideSharedObjects
Section8.1.WhatAreServer-SideSharedObjects?
Section8.2.WorkingwithServer-SideSharedObjects
Section8.3.RemovingUsers
Section8.4.PersistentServer-SideSharedObject
Section8.5.TheIdeaFactory
Chapter9.Server-SideStreams
Section9.1.StreamManagement
Section9.2.AnatomyofStream.play()
Section9.3.PlayingMP3Files
Section9.4.ChangingStreams
Section9.5.Server-SideNetStreamClass
Chapter10.BringinginDataandWorkingwithConfiguration
Files
Section10.1.CuePoints,Metadata,andStreamCompletion
Section10.2.Server-SideLoadVarsClass
Section10.3.MinimalistExampleUsingServer-Side
LoadVars()
Section10.4.Server-SideXMLClass
Section10.5.UsingtheConfigurationFiles
Section10.6.DoingMorewithFlashMediaServer3
Copyright
Copyright©2008,O'ReillyMedia.Allrightsreserved.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reillybooksmaybepurchasedforeducational,business,or
salespromotionaluse.Onlineeditionsarealsoavailablefor
mosttitles().Formoreinformation,
contactourcorporate/institutionalsalesdepartment:(800)
998-9938or
Editor:SteveWeiss
Editor:AudreyDoyle
TheO'ReillylogoisaregisteredtrademarkofO'ReillyMedia,
Inc.LearningFlashMediaServer,theimageofapearl-spotted
barbet,andrelatedtradedressaretrademarksofO'Reilly
Media,Inc.
Manyofthedesignationsusesbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.
Chapter1.GettingStartedwithFlash
MediaServer3
TheNewFlavorsforFlashMediaServer3
WhatIsaMediaServer?
InstallingFMS3
OrganizingYourDevelopmentEnvironment
TestingFMS3Connections
UsingtheFMS3AdministrationConsole
UsingThisBook
1.1.TheNewFlavorsforFlashMedia
Server3
ThereleaseofFlashMediaServer3(FMS3)comesinthree
differentserverconfigurations.FirstisFlashMediaInteractive
Server3(FMIS3),withfullfeaturesforinteractivestreaming,
andincorporatingfeaturesofthepreviousOriginandEdge
editions.SimilartothefullFlashMediaServer2version,FMIS3
hasmorefeatures:Thisneweditiondoesnotrestrictthe
numberofconcurrentconnectionsorbandwidthusage.
ThesecondversionofFMS3istheFlashMediaStreaming
Server3(FMSS3).Thisserverislimitedtostreamingvideoand
audio.Thinkofitassimilartoprogressivedownloading,except
FMSS3usesserverstreaming.Ifyourmaingoalistostream
audioandvideofromasite,thisoptionprovidesamuchlower
costserverthanFMIS3,withnolimitsonconcurrentusersor
bandwidth.UsingtheFlashMediaEncoder2,youcanuse
FMSS3forlivevideostreamingofeitherH.264orOn2VP6
video.
ThethirdversionofFMS3isthefreeFlashMediaDevelopment
Server3(FMDS3).WiththesamefeaturesastheFMIS3server,
thisversionislimitedto10concurrentusersandcannotbe
usedinaproductionenvironment.Youcanuseittodevelop
applicationsthatwillruneitheronyourowncomputeroralocal
areanetwork(LAN),foreithertheFMIS3orFMSS3servers.
Toavoidconfusion,thisbookreferstoallthreeversionssimply
asFMS3.YouwillneedtokeepinmindthattheFMSS3server
cannotbeusedforrecordingvideoorinteractivechats,andhas
otherlimitations.However,usingtheDevelopmentversionof
theserver,youcancreateandtestalloftheexamplesinthis
book.YoucanevenrecordyourownFLVvideofilesandplay
themoneitheroftheothertwoservers.
Chapter1.GettingStartedwithFlash
MediaServer3
TheNewFlavorsforFlashMediaServer3
WhatIsaMediaServer?
InstallingFMS3
OrganizingYourDevelopmentEnvironment
TestingFMS3Connections
UsingtheFMS3AdministrationConsole
UsingThisBook
1.1.TheNewFlavorsforFlashMedia
Server3
ThereleaseofFlashMediaServer3(FMS3)comesinthree
differentserverconfigurations.FirstisFlashMediaInteractive
Server3(FMIS3),withfullfeaturesforinteractivestreaming,
andincorporatingfeaturesofthepreviousOriginandEdge
editions.SimilartothefullFlashMediaServer2version,FMIS3
hasmorefeatures:Thisneweditiondoesnotrestrictthe
numberofconcurrentconnectionsorbandwidthusage.
ThesecondversionofFMS3istheFlashMediaStreaming
Server3(FMSS3).Thisserverislimitedtostreamingvideoand
audio.Thinkofitassimilartoprogressivedownloading,except
FMSS3usesserverstreaming.Ifyourmaingoalistostream
audioandvideofromasite,thisoptionprovidesamuchlower
costserverthanFMIS3,withnolimitsonconcurrentusersor
bandwidth.UsingtheFlashMediaEncoder2,youcanuse
FMSS3forlivevideostreamingofeitherH.264orOn2VP6
video.
ThethirdversionofFMS3isthefreeFlashMediaDevelopment
Server3(FMDS3).WiththesamefeaturesastheFMIS3server,
thisversionislimitedto10concurrentusersandcannotbe
usedinaproductionenvironment.Youcanuseittodevelop
applicationsthatwillruneitheronyourowncomputeroralocal
areanetwork(LAN),foreithertheFMIS3orFMSS3servers.
Toavoidconfusion,thisbookreferstoallthreeversionssimply
asFMS3.YouwillneedtokeepinmindthattheFMSS3server
cannotbeusedforrecordingvideoorinteractivechats,andhas
otherlimitations.However,usingtheDevelopmentversionof
theserver,youcancreateandtestalloftheexamplesinthis
book.YoucanevenrecordyourownFLVvideofilesandplay
themoneitheroftheothertwoservers.
1.2.WhatIsaMediaServer?
Ifyou'veusedFlashCommunicationServerorFlashMedia
Server2andunderstanditsuse,youcanskipthissection.
FlashMediaServer3isthelatestversionofFlashMediaServer
andhasseveralimprovements.However,ifyou'renewto
workingwithopensockettechnology,includingFMS3,readon.
FMS3isanopensocketserver.Thekeydifferencebetween
opensocketserversandWebserversisthatassoonasyou
receiveinformationfromaWebserver,theconnectionis
broken.Itmaylookasifyou'restillconnectedtotheWeb
server,especiallywithaFlashpagethat'sanimatingmaterials.
However,that'snotthewayitworks.IfyouopenaWebpage,
theWebserversendsyouthepagealongwithallassociated
graphics,text,andothermedia;andyourcomputersendsa
messagebackthatsays,"Gotit!"(orsomethingtothateffect),
andtheconnectioncloses.Withanopensocketserver,the
connectionstaysopenuntilyouquittheapplicationortrigger
aneventthatcutstheconnection.Becausetheconnection
remainsopen,youcanstreamaudio,video,text,andanyother
mediaavailableontheInternet,inrealtime.Youjustcan'tdo
thatwitharegularWebserverbecauseithasanentirely
differentarchitecture.
1.2.1.EnterRTMP
WhenyouusearegularWebpage,you'remostlikelyusing
HTTP(HypertextTransferProtocol),whichallowsyoutolookat
Webpages.Tobeabletoworkwithstreamingmedia,Adobe
developedReal-TimeMessagingProtocol(RTMP).Generally,
whenyouuseFMS3,youfirstconnecttoaWebserverviaHTTP
andthentoFlashMediaServerusingRTMP.Becauseofthis
arrangement,you'reworkingsimultaneouslywithdifferent
protocols—onefortheWebsiteandtheotherforthestreaming
media.
1.2.2.SpecialLanguagesandDocumentation
TodealwithallthethingsyoucandowithFMS3,youhavetwo
additionallanguageApplicationProgramInterfaces(APIs).Both
APIsareextensionsofActionScriptandarecalledClient-Side
MediaActionScriptandServer-SideMediaActionScript,orin
thisbook,simplyasCSActionScriptandSSActionScript.With
ActionScript3.0,whichisalsousedinthisbook,theclient-side
ActionScripthasbeenfullyintegratedintothelanguage.Asa
result,thedocumentationnolongercomeswithaspecialclientsideActionScriptdocumentationfile.Instead,theentire
ActionScript3.0languagereferenceisincluded.TheServerSideActionScriptLanguageReferenceisstillincluded,however.
ThefullcontentoftheseAPIsisrichlydescribedinPDFfiles
thatcomewithFMS3.(WhenyouinstallFMS3,thesefilesare
installedonyourcomputerinProgramFiles Adobe
FlashMediaServer3 documentation.)Onceyou've
installedFMS3,youshouldimmediatelyprintthis
documentationandputitinloose-leafbinders,oratleastput
thefilesinafolderonyourdesktopsothatthey'reeasytolook
up.You'llbeusingthedocumentationallthetime.TheFMS3
documentationisgeneralandcomplete;incontrast,thisbookis
notareference.Ratherthisbookisdesignedtogetbeginners
started,withaseriesofspecializedchaptersthatshowhowto
usedifferentfeaturesofFMS3.
1.3.InstallingFMS3
YoucaninstallFMS3oneitheraWindowsorLinuxOS.Fora
Windowsserver,youneedatleastWindows2000,whichmeans
youcaninstallitonyourWindowsHome,XP,orVistaedition.If
you'reinstallingitonyourcompany'sserver,you'llprobablybe
usingWindows2003StandardEdition,Windows2005Server,or
thenewWindows2008Server.ForyourLinuxbox,eitherRed
HatEnterpriseversion3or4willdothetrick.You'llneeda3.2
GHzorfasterPentium4(orsomeotherX86-compatible
processor),1GBofRAM,and50MBofharddrivespace.For
thisbook,Iuseda3GHzPentium4with1GBofRAMrunning
onWindowsXP,WindowsVistaonanotherserver,andRedHat
version4onaLinuxserver.
NOTE
YoucannotinstallFMS3onMacOSorAppleOSserver.
However,youcandevelopFMS3applicationsona
MacintoshandinstallFMS3onthe"MacTel"versionofa
MacintoshrunningWindows.IfyourunbothWindows
andMacOSXatthesametimeonyourMacintosh—
usingParallels—youcanruntheFlashapplicationonthe
MacintoshsideandFMSonthePCside.Also,youcan
installFMS3onaLinuxserver,butyoucannotdevelop
applicationsonaLinuxmachine.(Adobedoesn'tmakea
LinuxversionofFlash.)Thisapparentparadox
recognizesthatthetwomainservertechnologiesare
WindowsandLinux,andthetwomaindevelopment
platformsareWindowsandMacintosh.
Asyouwillsoonsee,thisdoesn'tmeanthatyoucannotdevelop
andtestFMS3appsonyourMacintosh.Rather,itmeansthat
you'lljusthavetoinstallFMS3onaremoteserver(whichwould
includeyourWindowscomputersittingonthesamedesktopor
eveninyourlap).Thebigadvantageofrunningyourapplication
ononecomputerandFMS3onanotheristhatyourprocessor
doesn'thavetoconcentrateontwothingsatonce.Soifyou've
gotaMacintosh,don'tworry.Mostoftheapplicationsdeveloped
forthisbookweredoneusingaMacintoshwiththeFMS3server
connectedviaaLANtoaPCrunningWindowsXP.Ofcourse,if
youhaveanewerMacintoshwiththeIntelprocessor,youcan
runthembothonthesamemachine,aslongasMacOSand
WindowsOSarerunninginparallel.
1.3.1.InstallationStepsforWindows
InstallingFMS3isveryeasyoneitherWindowsOSorLinux.
First,you'lllookatanexampleofhowtoinstallFMS3ona
WindowsXPcomputerusingtheDevelopmentVersionfreely
availableonlineatwww.adobe.com/products/flashmediaserver.
Figure1-1showsthedownloadpage.Besuretoselectthe
correctversionforyourserver(orcomputer).
Figure1-1.SelectingFMS3version
Oncedownloaded,uncompressthefileandopenthe
Flashmedia3_Int_Strm_ALPfolderonyourdesktopor
somewhereequallyconvenient,anddouble-click
FlashMediaServer3.exe,asshowninFigure1-2.
Figure1-2.SetupfileinFMS3folder
Assoonasyoustartthesetupprocess,theFlashMediaServer
3SetupWizardappears,asshowninFigure1-3.
Figure1-3.FMS3SetupWizard
Forthenextstep,you'llneedyourserialnumber,ifyouhave
one;keepithandy.ThenclicktheNextbutton.Thescreen
showninFigure1-4appears,requestingyourserialnumber.
Figure1-4.SerialNumberentrybox
Enteraserialnumbertohavethatnumberdeterminewhether
theserverisconfiguredasFMIS3orFMSS3;ifyoudonotenter
aserialnumber,theserverwillbeconfiguredastheFMDS3
(Development)server.PresstheNextbutton.Figure1-5shows
thepagethatappearsrequestingausernameandpasswordfor
themoduleyouwillneedtoaccessfortheFlashMedia
AdministrationServices:
Figure1-5.Administratorusernameandpasswordentry
Thispageiscrucialbecauseyouhavetorememberboththe
administratornameandpassword—writethemdown.Thename
andpasswordarebothcase-sensitive;sodon'tgetfancy.The
FlashMediaAdministrationConsoleletsyouseewhat'sgoingon
withyourapplicationontheserver,andyouneedtogetitright.
Whenyou'veenteredyouradministratornameandpassword,
clickNexttoopenthewindowtoestablishtheportsettingsfor
boththeFlashMediaServerandtheFlashMediaAdministration
console.Figure1-6showsthewindowwiththedefaultsettings:
Figure1-6.Settingports
Theportconfigurationisgenerallystraightforward.Usethe
defaultportsshowninFigure1-3.Bydefault,FMS3is
configuredtolistentoPort1935;unlessyouhaveaverygood
reason,leaveitatthat.(Onegoodreasontochangeyour
defaultportisifyoursystemalreadyhasanapplicationthat
listenstoPort1935.)However,youcanincludeadditionalports
tolistento.Forexample,youcanlist:
1935,80,443
Thismeansyoucanhaveasequenceofportstolistentoif
you'reusingmorethantheRTMPE(orRTMP)protocols,suchas
RTMPT(tunnelviaHTTP)orRTMPS(tunnelviaHTTPS).
Likewise,theadministrativeservice(FMS3console)listensto
port1111.That'sadifferentservice,andyoudon'twantitto
havethesameportasFMS3.
AsyoudevelopmorecomplexapplicationsinFMS3,youmay
wanttoreconfigureyourports.CheckouttheFlashMedia
Server3TechNotesattheAdobeWebsiteformoreinformation.
Tokeepitsimple,fornowjustusethedefaultsandclickNext.
Thelastpagethatappearsbeforeinstallationhasallofthe
detailsofthekeydirectoriesandtheportvalues.Writethese
downandkeepthemwhereyoucaneasilyfindthem.Figure17showswhatthesummaryincludes:
Figure1-7.Finalcheckbeforeinstallation
Onceyou'veverifiedthatthesettingsaresatisfactory,click
Install.
NowyoushouldseetheinstallergrindingawaytoinstallFMS3.
Whenithassuccessfullycompleteditstasks,thescreenshown
inFigure1-8appears.Youcanchangethedefaultshereifyou
don'twanttoseetheReadMe.pdfnotice,starttheserver,or
havetheserverstartautomaticallyeverytimeyourebootor
turnonyourcomputer.Startingandlettingtheserverrunall
thetimewon'tbeachoreforyourprocessorwhenthere's
nothingforittoserve.So,ifyouleavethedefault
configuration,you'llbeallsettodevelopFMS3applications
everytimeyourcomputerison.
Figure1-8.CompletingSetupWizardscreen
OnceyouhaveeverythinginstalledforFlashMediaServer3on
yourcomputer,youcanlookinStart AllPrograms Adobe
FlashMediaServer3.Thereyouwillseeselectionsofthe
documentation,theFlashMediaAdministrationConsole,
startingandstoppingboththemediaandadministrationservers
andevenanuninstaller.Figure1-9showswhatappearsifyour
installationsucceeded:
Figure1-9.FlashMediaServer3selections
1.3.2.InstallationStepsforLinux
InstallingFMS3onLinuxisprettyeasyaswell.Basically,allyou
needtodoistoextractthefilesfromthecompressedarchive
(FlashMediaServer3.tar.gz)andthenuntartheinstallationfile.I
extractedthefileusingthegraphicuserinterface.
Unpackingtheinstallpackagecreatesadirectoryandplacesthe
packagewithinit.Eventhoughyoucanseetheiconsthatmake
upthepackage,youhavetogointotheTerminaltoinstallthe
software.FromtheTerminal,navigatetothenewdirectory,in
whichyouwillseeafilenamedinstallFMS.
Type:
./installFMS
intheTerminaltoinstallyourserver.Youmustenterand
rememberauniqueAdministrativenameandpassword.You
cansimplyusethedefaultvaluesfortheserverport(1935)and
adminservice(1111),andeverythingshouldworkasexpected.
1.4.OrganizingYourDevelopment
Environment
Ifyoufollowthedefaultinstallation,yourFlashMediaServer3
shouldstartupeverytimeyouturnonyourcomputer.Within
thisenvironmentyouneedtosetupyourworkenvironmentso
thatyoucanconvenientlytestyourapplications.
1.4.1.Server-SideFiles
WhenyouinstallFMS3onWindows,yourtypicalinstallationis
goingtosetupyourserver-sidefileswiththefollowingpath:
C:\ProgramFiles\Adobe\FlashMediaServer3\applicat
Allofyourserver-sideapplicationfoldersgointothefolder
namedapplications.Forexample,Figure1-10showsavisual
viewofthepathswiththreeapplicationsintheapplications
foldernamedideafactory,flvedit,andtextChat.Theapplication
foldersmustbenamedwiththeapplicationname.Thatis,if
yourapplicationisnamed"vidChat",youmustnamethefolder
"vidChat."Thefoldercanbeemptyorcontainotherfiles.Ifyou
havewrittenserver-sidecodeforyourapplication,thefilemust
benamedmain.ascorthesamenameasyourapplication,such
asvidChat.asc.ThroughoutthisbookIusethesamenameas
theapplicationsfortheASCfilestoreduceconfusionwhen
discussingmorethanoneapplicationwithserver-sidecode.
Figure1-10.Pathtoserver-sideapplications
InFigure1-10,theideafactoryandflveditapplicationscontain
ASCfileswiththesamenameastheapplicationfolder,andthe
textChatapplication'sASCfileisnamedmainASC,butitcould
havebeennamedtextChat.asc.Likewise,alloftheothersASC
filescouldhavebeennamedmain.asc.Usewhateversystemis
convenientforyou.Asyoulookatdifferentapplicationsinthis
book,you'llseedifferentfoldersassociatedwithserver-side
files.
1.4.2.Client-SideFiles
Yourclient-sidefilesaretheFlashFLA,AS,andSWFfilesthat
you'reusedtoworkingwithinFlash.Ifyouhaveyourserveron
yourcomputer,theycangoanywhere.Whenyouusethe
Control TestMoviesequencewithyourapplication,your