Adobe 65029121 - Flash Media Streaming Server Developer's Manual

Developer's guide
Hide thumbs Also See for 65029121 - Flash Media Streaming Server:

Advertisement

Quick Links

ADOBE
FLASH
MEDIA
®
®
SERVER
DEVELOPER GUIDE

Advertisement

Table of Contents
loading

Summary of Contents for Adobe 65029121 - Flash Media Streaming Server

  • Page 1 ADOBE FLASH MEDIA ® ® SERVER DEVELOPER GUIDE...
  • Page 2 The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorpo- rated.
  • Page 3: Table Of Contents

    Contents Chapter 1: Getting started Overview ................. 1 Set up a development environment .
  • Page 4: Chapter 1: Getting Started

    An application that runs on Flash Media Server has a client-server architecture. The client application is developed in Adobe Flash or Adobe Flex and runs in Flash Player, AIR, or Flash Lite 3. It can capture and display audio and video and handle user interaction.
  • Page 5 The client displays a user interface, such as controls to start, stop, or pause a video. The user Client user interface interface can run in Flash Player, AIR, or Flash Lite 3 and can be developed with Adobe Flash or Adobe Flex. The client contains ActionScript code that handles user interaction and connects to the Client-side ActionScript server.
  • Page 6: Set Up A Development Environment

    From the Start menu, select All Programs > Adobe > Flash Media Server 3 > Start Adobe Flash Media Server 3. From the Start menu, select All Programs > Adobe > Flash Media Server 3 > Start Flash Media Administration Server 3.
  • Page 7: Hello World Application

    FLASH MEDIA SERVER Developer Guide Hello World application Overview Note: The following sections apply to Flash Media Interactive Server and Flash Media Development Server. This example uses Flash CS3 to show how to connect a Flash file to a server-side script and how to request infor- mation from the server.
  • Page 8 FLASH MEDIA SERVER Developer Guide Write the client-side script This script provides two button actions, either connecting to or disconnecting from the server. When connecting, the script calls the server with a string (“World”), which triggers a response that displays the returned string (“Hello, World!”).
  • Page 9: Create An Application

    FLASH MEDIA SERVER Developer Guide Write the server-side script Choose File > New > ActionScript Communications File. Define the server-side function and the connection logic: application.onConnect = function( client ) { client.serverHelloMsg = function( helloStr ) { return "Hello, " + helloStr + "!"; application.acceptConnection( client );...
  • Page 10 RootInstall/applications/skatingClips. The server-side code would be in a file called main.asc or skatingClips.asc in the skatingClips folder. To configure the location of the applications directory, edit the fms.ini or the Vhost.xml configuration file; see Adobe Flash Media Server Configuration and Administration Guide.
  • Page 11: Test An Application

    Use the Administration Console to start, stop, reload, and view applications, with Start > All Programs > Adobe Flash Media Server 3 > Flash Media Administration Console. When your client connects to the server, that application is loaded and can be seen in the Administration Console.
  • Page 12 You can view a log file with any text editor. While an application is running, you can view its live log file from the Administration Console: From the Windows desktop, click Start > All Programs > Adobe Flash Media Server 3 > Flash Media Adminis- tration Console.
  • Page 13: Deploy An Application

    FLASH MEDIA SERVER Developer Guide application.allowDebug = true; Note: If used, set this value to false before deploying the application. To start a debugging session: Start Flash Media Server and Flash Media Administration Server. Start the Administration Console. Log in to the Administration Server with the username and password set during installation. Start your application on Flash Media Server.
  • Page 14 Note: If the main script refers to scripts in a subdirectory, the hierarchy must be maintained in the archive file. To maintain this hierarchy, Adobe recommends that you run the FAR utility in the same directory where the main script is located.
  • Page 15: Chapter 2: Streaming Services

    You can modify the sample clients for production use or create your own. The live and vod services are signed (approved) by Adobe. Flash Media Streaming Server only supports signed services—it cannot run other applications. Flash Media Interactive Server and Flash Media Development Server support signed services as well as any other applications you create.
  • Page 16: Using The Vod Service

    Open the fms.ini file (located in RootInstall/conf) and add a new entry to set the content path for the new service, for example, LIVE2_DIR = C:\Program Files\Adobe\Flash Media Server 3\applications\live2 Open the Application.xml file in RootInstall/applications/live2 and change the virtual directory entry to <Streams>/;${LIVE2_DIR}</Streams>...
  • Page 17: Creating Clients For Streaming Services

    VOD2_DIR directory entry list: <Streams>/;${VOD2_DIR}</Streams> Restart Adobe Flash Media Server. Place recorded media files into the folder you specified in the fms.ini file (in this example, C:\Program Files\Adobe\Flash Media Server 3\applications\vod2\media The media files are now accessible from the URL rtmp://flashmediaserver/vod2/filename Note: You do not have to specify the media subdirectory in the URL;...
  • Page 18 ADOBE FLASH MEDIA SERVER Developer Guide Allow connections from specific domains By default, clients can connect to the live and vod services from any domain. To limit the domains from which clients can connect, edit text files in the service’s applications folder.
  • Page 19: Chapter 3: Developing Media Applications

    Live video is typically used for live events, such as corporate meetings, education, sports events, and concerts, or delivered continually, for example, by a television or radio station. You can use Adobe Flash Media Encoder, available from Adobe.com, to encode and stream live video.
  • Page 20 Example Description protocol: rtmp: The protocol used to connect to Adobe Flash Media Server, which is the Adobe Real- Time Messaging Protocol. Possible values are rtmp, rtmpe, rtmps, rtmpt, and rtmpte. For more information, see the Technical Overview. //host //www.example.com The host name of a local or remote computer.
  • Page 21 ADOBE FLASH MEDIA SERVER Developer Guide The following table shows three examples of different virtual directory configurations, including mapping to a local drive and a network drive, and how the configurations determine the directory to which a recorded stream is published.
  • Page 22 In Adobe Flash CS3 Professional, choose File > New > Flash File (ActionScript 3.0), and click OK. Choose Window > Components to open the Components panel.
  • Page 23 ADOBE FLASH MEDIA SERVER Developer Guide Write the class constructor, registering an event listener on each button: public function HelloServer() { // register listeners for mouse clicks on the two buttons connectBtn.addEventListener(MouseEvent.CLICK, connectHandler); closeBtn.addEventListener(MouseEvent.CLICK, closeHandler); to call an event handler named...
  • Page 24: Managing Connections

    ADOBE FLASH MEDIA SERVER Developer Guide Okay, let's connect now connected is: true event.info.level: status event.info.code: NetConnection.Connect.Success Congratulations! you're connected The line shows the value of the property, meaning whether connected is: true NetConnection.connected Flash Player is connected to the server over RTMP. The next two lines describe the...
  • Page 25 ADOBE FLASH MEDIA SERVER Developer Guide In the server-side code, the application can accept or reject connections from clients, shut down the application, and perform other tasks to manage the connection. When a client connects, the application receives an event. Likewise, when the client disconnects, the application receives an application.onConnect...
  • Page 26: Recorded Streams

    Recorded streams Playing recorded streams One of the most popular uses of Adobe Flash Media Server is to stream recorded audio and video files that are stored on the server to many clients. To play a recorded stream, pass a URI to to locate the recorded file, as in the following: NetStream.play()
  • Page 27 The frame rate at which the video was encoded. framerate “Add metadata to a live stream” for a list of property names Adobe suggests for users adding metadata to live video streaming from client to server. Video player example If you have built a Flash video player interface for progressive download video, you may have used the FLVPlayback component to design the video player interface.
  • Page 28 ADOBE FLASH MEDIA SERVER Developer Guide Run the sample in Flash The easiest way to run the sample is to install it on the same computer as your development server. Place the Streams.as file in a sample directory for client applications.
  • Page 29 ADOBE FLASH MEDIA SERVER Developer Guide connected is: true event.info.level: status event.info.code: NetStream.Play.Reset connected is: true event.info.level: status event.info.code: NetStream.Play.Start metadata: duration=30 width=292 height=292 framerate=30 [SWF] C:\samples\Streams\bin\Streams-debug.swf - 3,387 bytes after decompression connected is: true event.info.level: status event.info.code: NetStream.Buffer.Full connected is: true event.info.level: status...
  • Page 30 ADOBE FLASH MEDIA SERVER Developer Guide trace("connected is: " + nc.connected ); trace("event.info.level: " + event.info.level); trace("event.info.code: " + event.info.code); switch (event.info.code) case "NetConnection.Connect.Success": trace("Congratulations! you're connected"); connectStream(nc); // createPlayList(nc); // instead you can also call createPlayList() here break; case "NetConnection.Connect.Failed": case "NetConnection.Connect.Rejected":...
  • Page 31: Handling Errors

    Checking video files before playing Use the FLVCheck tool to check a recorded video file for errors before playing it. Errors in the video file might prevent it from playing correctly. For more information, see Adobe Flash Media Server Configuration and Adminis- tration Guide.
  • Page 32 ADOBE FLASH MEDIA SERVER Developer Guide To be resilient, your application needs to listen for and handle events that affect connections and streams. netStatus As you test and run your application, you can also use the Administration Console to troubleshoot various connection and stream events.
  • Page 33: Playlists

    ADOBE FLASH MEDIA SERVER Developer Guide Write the client code ❖ In your event handler, check for the code and take some action: netStatus StreamNotFound private function onNetStatus(event:NetStatusEvent):void { switch (event.info.code) { case "NetStream.Play.StreamNotFound": trace("The server could not find the stream you specified");...
  • Page 34: Multiple Bit Rate Switching

    About multiple bit rate switching Adobe Flash Media Server can encode and deliver On2 V6 and Sorenson Spark encoded video. Flash Player 8 and 9 support both codecs, while Flash Player 7 and earlier versions support only the Sorenson Spark codec.
  • Page 35: Detecting Bandwidth

    Play a video and set the buffer size based on the detected bandwidth. In Adobe Flash Media Server 3, bandwidth detection is built in to the server. The new bandwidth detection, called native bandwidth detection, provides better performance and scalability. To use native bandwidth detection, make sure bandwidth detection is enabled, and write client code that calls functions built in to Adobe Flash Media Server.
  • Page 36 ADOBE FLASH MEDIA SERVER Developer Guide public function onBWDone(... rest):void { var p_bw:Number; if (rest.length > 0) p_bw = rest[0]; // your application should do something here // when the bandwidth check is complete trace("bandwidth = " + p_bw + " Kbps.");...
  • Page 37 <BandwidthDetection enabled="true"> Bandwidth detection is enabled by default. You can use an Application.xml file specific to your application or one that applies to a virtual host (see Adobe Flash Media Server Configuration Guide for details). Write the client code Define an event handler named...
  • Page 38 Latency between the Origin and Edge server can affect the bandwidth measurement. A. Origin server B. Edge server C. Client To use server-side bandwidth detection, use the specialized main.asc file Adobe provides for bandwidth detection. You can find the main.asc file in the \ComponentsAS2\FLVPlayback folder in the Samples.zip file provided with Flash CS3, which you can download at www.adobe.com/go/learn_fl_samples.
  • Page 39: Detecting Stream Length

    The server-side Stream class allows you to detect the length of a recorded stream. The Stream class has a static method, , that returns the length in seconds of an audio or video stream. The length is measured by Adobe length() Flash Media Server and differs from the duration that returns, which is set by a user or a tool.
  • Page 40 ADOBE FLASH MEDIA SERVER Developer Guide Write the server-side code A client might need to retrieve the length of a stream stored on the server, for example, if a Flash CS3 presentation displays the length of a video to let the user decide whether to play it.
  • Page 41 ADOBE FLASH MEDIA SERVER Developer Guide trace("connected is: " + nc.connected ); trace("event.info.level: " + event.info.level); trace("event.info.code: " + event.info.code); switch (event.info.code) case "NetConnection.Connect.Success": trace("Congratulations! you're connected"); connectStream(nc); break; case "NetConnection.Connect.Rejected": case "NetConnection.Connect.Failed": trace ("Oops! the connection was rejected"); break;...
  • Page 42: Buffering Streams Dynamically

    NetStream.pause() while viewers are watching a commercial, for example, and then unpause the stream when the main video starts. For more information, see the entry in the Adobe Flash Media Server ActionScript 2.0 Language NetStream.pause() Reference or in the ActionScript 3.0 Language and Components Reference.
  • Page 43 ADOBE FLASH MEDIA SERVER Developer Guide break; case "NetConnection.Connect.Rejected": trace("The connection was rejected"); break; case "NetStream.Buffer.Full": ns.bufferTime = 10; trace("Expanded buffer to 10"); break; case "NetStream.Buffer.Empty": ns.bufferTime = 2; trace("Reduced buffer to 2"); break; Write a custom method to play a stream. In the method, set an initial buffer time, for example, 2 seconds: private function connectStream(nc:NetConnection):void { ns = new NetStream(nc);...
  • Page 44: Chapter 4: Developing Live Video Applications

    Adobe Flash Media Server clients can capture live audio and video from a microphone or camera and share the live content with other clients. This feature allows you to capture live events in real time and stream them to a large audience or create live audio and video conferences.
  • Page 45 ADOBE FLASH MEDIA SERVER Developer Guide Write the client-side code Create an ActionScript class. In your class, create a NetConnection object, add a event handler, and netStatus connect to the server. Add the ActivityEvent handler: private function activityHandler(event:ActivityEvent):void { trace("activityHandler: " + event);...
  • Page 46: Record Live Video

    ADOBE FLASH MEDIA SERVER Developer Guide // called when the client publishes application.onPublish = function(client, myStream) { trace(myStream.name + " is publishing into application " + application.name); // This is an example of using the multi-point publish feature to republish // streams to another application instance on the local server.
  • Page 47: Add Metadata To A Live Stream

    Each metadata item is a property with a name and a value set in the object. You can use any name, but metadata Adobe recommends that you use common names, so that the metadata you set can be easily read. Call the method in a client-side script to clear metadata from NetStream.send(@clearDataFrame, onMetaData)
  • Page 48 ADOBE FLASH MEDIA SERVER Developer Guide Metadata property name Data type Description audiodatarate Number The audio bit rate. framerate Number The frames per second at which the video was recorded. creationdate String The creation date of the file. createdby String The creator of the file.
  • Page 49 ADOBE FLASH MEDIA SERVER Developer Guide x=200 y=300 When the server starts to record the video, it begins to write its own metadata properties to the file, including . If the recording is 20 seconds long, the server adds to the metadata, overwriting the value...
  • Page 50 ADOBE FLASH MEDIA SERVER Developer Guide metaData.width = 400; metaData.height = 200; stream.send("@setDataFrame", "onMetaData", metaData); break; Write the client event handler class You also need to write a client event handler class that handles the event. onMetaData ❖ Write the...
  • Page 51: Publish From Server To Server

    ADOBE FLASH MEDIA SERVER Developer Guide Retrieve metadata from live video To display the metadata set in the live stream, you need to handle the event. Handling the metadata set onMetaData in a live stream is the same as extracting the metadata set by the server or a tool in a recorded file.
  • Page 52 ADOBE FLASH MEDIA SERVER Developer Guide Server 1 rebroadcasts the live stream to Server 2 and Server 3 with a method. NetStream.publish() Subscribers connecting to Server 2 and Server 3 receive the same live stream. The application receives an event when the client stops publishing.
  • Page 53 ADOBE FLASH MEDIA SERVER Developer Guide Handle events that occur on the NetStream object you used to publish from your server to the remote server: ns.onStatus = function(info) { if (info.code) == "NetStream.Publish.Start") { trace("The stream is now publishing"); trace("Buffer time is : " + this.bufferTime);...
  • Page 54: Chapter 5: Developing Social Media Applications

    Chapter 5: Developing social media applications In addition to streaming video applications, Adobe Flash Media Interactive Server and Adobe Flash Media Devel- opment Server can host social media and other real-time communication applications. Users can capture live audio and video, upload them to the server, and share them with others. These server editions also provide access to remote shared objects that synchronize data between many users, and so is ideal for developing online games.
  • Page 55 ADOBE FLASH MEDIA SERVER Developer Guide To create persistent local shared objects, call the client-side Persistent local shared objects method. Persistent local shared objects have the extension .sol. You can specify a SharedObject.getLocal() storage directory for the object by passing a value for the...
  • Page 56 ADOBE FLASH MEDIA SERVER Developer Guide You must use to update values in the shared object. The remote shared object has a setProperty() data property that contains attributes and values. However, in ActionScript 3.0, you cannot write values directly to it, as in: so.data.x = sharedBall.x;...
  • Page 57 Developer Guide Design the user interface In Adobe Flash CS3 Professional, choose File > New > Flash File (ActionScript 3.0), and click OK. From the toolbox, select the Rectangle tool. Drag to the lower-right corner, then select the Oval tool.
  • Page 58: Allow And Deny Access To Assets

    ADOBE FLASH MEDIA SERVER Developer Guide if( so != null ) so.setProperty("x", sharedBall.x); so.setProperty("y", sharedBall.y); When the remote shared object is updated, it dispatches a event. sync Write a event handler that updates all clients with the new ball position:...
  • Page 59: Authenticate Clients

    ADOBE FLASH MEDIA SERVER Developer Guide By default, are set to , which means the client can access every stream and shared readAccess writeAccess object on the server. Allow access to streams ❖ In main.asc, add an function that specifies a directory name on the server in your main.asc file: onConnect() application.onConnect = function(client, name) {...
  • Page 60 An Access plug-in intercepts incoming requests before passing them on to Flash Media Interactive Server. You can program an Access plug-in to use any form of authentication. For more information, see Adobe Flash Media inter- active Server Plug-in Developer Guide.
  • Page 61 If you know the domains from which the legitimate clients will be connecting, you can whitelist those domains. Conversely, you can blacklist known bad domains. You can enter a static list of the domain names in the Adaptor.xml file. For more information, see Adobe Flash Media Server Configuration and Administration Guide.
  • Page 62 ADOBE FLASH MEDIA SERVER Developer Guide application.onConnect = function(pClient) { var isIPOK = true; getBannedIPList(); for (var index=0; index<this.bannedIPList.length; index++) { var currentIP = this.bannedIPList[index]; if (pClient.ip == currentIP) { isIPOK = false; trace("ip was rejected"); break; if (isIPOK) { this.acceptConnection(pClient);...
  • Page 63: Authenticate Users

    ADOBE FLASH MEDIA SERVER Developer Guide Authenticate users Authenticate using an external resource For a limited audience, it is feasible to request credentials (login and password) and challenge them using an external resource, such as a database, LDAP server, or other access-granting service.
  • Page 64 ADOBE FLASH MEDIA SERVER Developer Guide delete pendingConnections[FMSid]; Authenticate using a token This technique is an alternative to a username/password style of authentication, where the token can be granted based on a property of the client. The control flow is as follows: The client SWF requests an authentication token from a third party.
  • Page 65 ActivityEvent class 41 checkBandwidth function 32 about 44 Administration Console 8 Client class 8 adding to live streams 44 Adobe Flash CS3 Professional 3 ip property 56 properties 45 Adobe Flash Media Development readAccess property 55 retrieving 48 Server 1...
  • Page 66 INDEX 63 remote 14, 51 temporary 51 SharedBall example 53 Stream class 36 streaming services 12 streams buffering 39 formats 2 pausing 39 playing 23 virtual naming 36 SWF files publishing 11 verifying authenticity of 58 URI, format for connecting to server 16 UTF-8 encoding 8 Vhost.xml file 36...

This manual is also suitable for:

Flash media server

Table of Contents