View comments | RSS feed

NetStream.publish()

Availability

Usage

public publish(name : String [, howToPublish : String] ) : Void

Parameters

name A string value that identifies the stream. If you pass false, the publish operation stops. Subscribers to this stream must pass this same name when they call NetStream.play(). You don't need to include a file extension for the stream name.

howToPublish An optional string that specifies how to publish the stream. Valid values are "record", "append", and "live". The default value is "live".

Returns

Nothing.

Description

Method; sends streaming audio, video, and text messages from the client to the Flash Media Server, optionally recording the stream during transmission. This method is available only to the publisher of the specified stream.

You don't use this command when you want to let a subscriber play a stream that has already been published and recorded. For example, assume you have recorded a stream named "allAboutMe." To enable someone to play it back, you need only open a stream for the subscriber to use:

var publish_ns:NetStream = new NetStream(my_nc);
var subscribe_ns:NetStream = new NetStream(my_nc);
subscribe_ns.play("allAboutMe");

When you record a stream, Flash creates an FLV file and stores it in a subdirectory of the Flash Media Server applications directory on the server. Each stream is stored in a directory whose name is the same as the instanceName value passed to NetConnection.connect(). Flash creates these directories automatically; you don't have to create one for each instance name. For example:

/* Connect to a specific instance of an app that is stored in
a directory named "lectureSeries" in your applications directory.
A file named "lecture.flv" is stored in a subdirectory named
"...\yourAppsFolder\lectureSeries\streams\Monday". */

var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://server.domain.com/lectureSeries/Monday");
var my_ns:NetStream = new NetStream(my_nc);
my_ns.publish("lecture", "record");

/* Connect to a different instance of the same app 
but issue an identical publish command.
A file named "lecture.flv" is stored in a subdirectory named
"...\yourAppsFolder\lectureSeries\streams\Tuesday". */
var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://server.domain.com/lectureSeries/Tuesday");
var my_ns:NetStream = new NetStream(my_nc);
my_ns.publish("lecture", "record");

If you don't pass a value for instanceName, name.flv is stored in a subdirectory named "...\yourAppsFolder\appName\streams\_definst_" (for "default instance"). For more information on using instance names, see NetConnection.connect(). For information on playing back FLV files, see NetStream.play().

This method can invoke NetStream.onStatus with a number of different information objects. For example, if someone is already publishing on a stream with the specified name, NetStream.onStatus is called with a code property of NetStream.Publish.BadName. For more information, see NetStream.onStatus.

Example

The following example shows how to publish and record a video, and then play it back:

var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://myServer.myDomain.com/appName/appInstance");
var src_ns:NetStream = new NetStream(my_nc);
src_ns.publish("stephen", "record");
src_ns.attachVideo(Camera.get());

// to stop publishing and recording
src_ns.publish(false);

// to play the recorded stream
src_ns.play("stephen");

See also

NetConnection.connect(), NetStream.play(), Video.attachVideo()


Comments


No screen name said on Jul 4, 2006 at 1:50 AM :
I've got a question. Is here a way to save rercorded FLV file to any other folder on server? For example I want to save FLV files on root C: disk? Is it possible? Thanx!
_spinks_ said on Aug 23, 2006 at 7:24 PM :
It might a bit late, but saving the flv files in a different directory can be done by using virtual directories and the File class (server side actionscript). The method is simple: publish the flv using names such as 'foo.flv', and after you finished recording call a function on the serverside (which you wil have to make) which moves/copies/renames the file to the folder you needed.
You can use paths such as 'd:/foo/bar.flv' but I find it much neat using the virtual directories =) you can find information about virtual directories in this reffrerence under the first page of File class.
No screen name said on Dec 17, 2006 at 11:26 PM :
Hello, I am using flash media server 2. I have basically copied and pasted the code example you have above but the FLV file does not appear in my application directory. The ONLY thing in my application directory is main.asc.

In the web management interface under the application stream it says *flv:stephen...stored. So where is it stored?

Also, if I say src_ns.play("stephen"); ...nothing happens.

Looking forward to your answers.

Andrew
No screen name said on Apr 5, 2007 at 1:30 AM :
Judging to this sample code, no server side code is needed, right? I'm
trying this sample myself, but no flv appears on the server. Must one write
server side code, or must it be something else? A permission thing? The
server is running Suse.

Regards

Karel
No screen name said on Aug 1, 2007 at 3:22 AM :
What should be do if we want to both record and also hear the audio live? NetStream.publish with "Record" will save it on the flash media server.
NetStream.publish with "Live" allows others to listen when the recording is going on but it will not save it in the file on FlashMedia server.
In NetStream, I do not see any "flush" kind of method.
No screen name said on Jan 1, 2008 at 5:55 PM :
Hi, is it possible to use NetStream to record audio/video to the local file system. If someone can post any working code that would be greatly appreciated.
mike hype said on Jan 23, 2008 at 5:41 PM :
regarding the flv not being written to disk (in a linux environment). Check your onStatus for messages - I had errors that the file couldn't be saved, which was down to the applications/myApplication directory being owned by root, when you need to have it owned by the user the server operates under.

Presuming you have a user fms in group fms, you would need to navigate to the applications directory and on the command line e.g:

chown fms:fms myApplication

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/fms/2/docs/00000589.html