View comments | RSS feed

Stream.play()

Availability

Flash Communication Server MX 1.0.

Usage

myStream.play(streamName, [startTime, length, reset, remoteConnection, virtualKey])

Parameters

streamName The name of any published live stream, recorded stream (FLV file), or MP3 file.

To play FLV files, the default Flash file format for recorded streams, specify the name of the stream (for example, "myVideo"). To play MP3 files that you've stored on the server, or the ID3 tags of MP3 files, you must precede the stream name with mp3: or id3: (for example, "mp3:bolero" or "id3:bolero"). For more information on playing MP3 files, see Developing Media Applications.

startTime The start time of the stream playback, in seconds. If no value is specified, it is set to -2. If startTime is -2, the server tries to play a live stream with the name specified in streamName. If no live stream is available, the server tries to play a recorded stream with the name specified in streamName. If no recorded stream is found, the server creates a live stream with the name specified in streamName and waits for someone to publish to that stream. If startTime is -1, the server attempts to play a live stream with the name specified in streamName and waits for a publisher if no specified live stream is available. If startTime is greater than or equal to 0, the server plays the recorded stream with the name specified in streamName, starting from the time given. If no recorded stream is found, the play method is ignored. If a negative value other than
-1 is specified, the server interprets it as -2. This is an optional parameter.

length The length of play, in seconds. For a live stream, a value of -1 plays the stream as long as the stream exists. Any positive value plays the stream for the corresponding number of seconds. For a recorded stream, a value of -1 plays the entire file, and a value of 0 returns the first video frame. Any positive number plays the stream for the corresponding number of seconds. By default, the value is -1. This is an optional parameter.

reset A Boolean value, or number, that flushes the playing stream. If reset is false (0), the server maintains a playlist, and each call to Stream.play is appended to the end of the playlist so that the next play does not start until the previous play finishes. You can use this technique to create a dynamic playlist. If reset is true (1), any playing stream stops, and the playlist is reset. By default, the value is true.

You can also specify a number value of 2 or 3 for the reset parameter, which is useful when playing recorded stream files that contain message data. These values are analogous to false (0) and true (1), respectively: a value of 2 maintains a playlist, and a value of 3 resets the playlist. However, the difference is that specifying either 2 or 3 for reset returns all messages in the specified recorded stream at once, rather than at the intervals which the messages were originally recorded (the default behavior).

For more information on Flash Media Server logging see TechNote 16464 on the Macromedia Flash Media Server Support Center.

remoteConnection  A reference to a NetConnection object that is used to connect to a remote server. The requested stream plays from the remote server if this parameter is provided. This parameter is optional.

virtualKey A string indicating a key value. Starting with Flash Media Server 2, stream names are not always unique; you can create multiple streams with the same name, place them in different physical directories, and use the VirtualDirectory section and VirtualKeys section of the vhost.xml file to direct clients to the appropriate stream. Because the Stream.length() method is not associated with a client, but connects to a stream on the server, you may need to specify a virtual key to identify the correct stream. For more information about keys, see Client.virtualKey. This parameter is optional.

Returns

A Boolean value: true if the Stream.play call is accepted by the server and added to the playlist; false otherwise. The Stream.play method can fail if the server fails to find the stream or if an error occurs. To get information about the Stream.play call, you can define a Stream.onStatus handler to catch the play status or error.

If the streamName parameter is false, the stream stops playing. A Boolean value of true is returned if the stop succeeds; false otherwise.

Description

Method; controls the data source of a stream with an optional start time, duration, and reset flag to flush any previously playing stream. The Stream.play() method also has a parameter that lets you reference a NetConnection object to play a stream from another server. The Stream.play() method allows you to do the following:

You can combine multiple streams to create a playlist for clients. The server-side Stream.play() method behaves a bit differently than the NetStream.play method on the client side. A play call on the server is similar to a publish call on the client. It controls the source of the data that is coming into a stream. When you call Stream.play on the server, the server becomes the publisher. Because the server has a higher priority than the client, the client is forced to unpublish from the stream if the server calls a play method on the same stream.

In general, if any recorded streams are included in a server playlist, you cannot play the server stream as a live stream.

NOTE

 

A stream that plays from a remote server by means of the NetConnection object is a live stream.

If you require a value to begin a stream, you may need to change the Application.xml file's "Enhanced seeking" flag at the server. "Enhanced seeking" is a Boolean flag in the Application.xml file. By default, this flag is set to false. When a play occurs, the server seeks to the closest video keyframe possible and starts from that keyframe. For example, if you want to play at time 15, and there are keyframes only at time 11 and time 17, seeking will start from time 17 instead of time 15. This is an approximate seeking method that works well with compressed streams.

If the flag is set to true, some compression is invoked on the server. Using the previous example, if the flag is set to true, the server creates a keyframe--based on the preexisting keyframe at time 11--for each keyframe from 11 through 15. Even though a keyframe does not exist at the seek time, the server generates a keyframe, which involves some processing time on the server.

Example

The following example shows how streams can be chained between servers:

application.myRemoteConn = new NetConnection();
application.myRemoteConn.onStatus = function(info){
    trace("Connection to remote server status " + info.code + "\n");
    // Tell all the clients.
    for (var i = 0; i < application.clients.length; i++){
        application.clients[i].call("onServerStatus", null, 
        info.code, info.description);
    }
};
// Use the NetConnection object to connect to a remote server.
application.myRemoteConn.connect(rtmp://movie.com/movieApp);
// Setup the server stream.
application.myStream = Stream.get("foo");
if (application.myStream){
    application.myStream.play("Movie1", 0, -1, true, application.myRemoteConn);
}

The following example shows Stream.play is used as a hub to switch between live streams and recorded streams:

// Set up the server stream.
application.myStream = Stream.get("foo");
if (application.myStream){
    // This server stream plays "Live1", 
    // "Record1", and "Live2" for 5 seconds each.
    application.myStream.play("Live1", -1, 5);
    application.myStream.play("Record1", 0, 5, false);
    application.myStream.play("Live2", -1, 5, false); 
} 

The following example combines different streams into a recorded stream:

// Set up the server stream.
application.myStream = Stream.get("foo");
if (application.myStream){
    // Like the previous example, this server stream 
    // plays "Live1", "Record1", and "Live2" 
    // for 5 seconds each. But this time, 
    // all the data will be recorded to a recorded stream "foo".
    application.myStream.record();
    application.myStream.play("Live1", -1, 5);
    application.myStream.play("Record1", 0, 5, false);
    application.myStream.play("Live2", -1, 5, false);
}

The following example uses Stream.play to stop playing the stream foo:

application.myStream.play(false);

The following example creates a playlist of three MP3 files (beethoven.mp3, mozart.mp3, and chopin.mp3) and plays each file in turn over the live stream foo:

application.myStream = Stream.get("foo");
if(application.myStream) {
    application.myStream.play("mp3:beethoven", 0);
    application.myStream.play("mp3:mozart", 0, false);
    application.myStream.play("mp3:chopin.mp3", 0, false);
}

In the following example, data messages in the recorded stream file log.flv are returned at the intervals which they were originally recorded.

application.myStream = Stream.get("data");
if (application.myStream) {
    application.myStream.play("log", 0, -1);
}

In the following example, data messages in the recorded stream file log.flv are returned all at once, rather than at the intervals which they were originally recorded.

application.myStream = Stream.get("data");
if (application.myStream) {
    application.myStream.play("log", 0, -1, 2);
}

Comments


No screen name said on Feb 9, 2007 at 12:47 PM :
The section that talks about chaining servers for streams the line:

application.myStream.play("Movie1", 0, -1, true, application.myRemoteConn);

Does not work for live streams. It should either be:

application.myStream.play("Movie1", -1, -1, true, application.myRemoteConn);

or

application.myStream.play("Movie1", -2, -1, true, application.myRemoteConn);

The startTime parameter was set to 0 which will only look to play recorded streams.. not live ones.
3dward ma553y said on Feb 8, 2008 at 3:41 AM :
I would really like a full example of how to stream just one audio file from an FMS server?
No screen name said on Aug 7, 2008 at 12:11 AM :
Server-side Stream.play method plays the FLV files or live streams but the main problem is the Audio/Video Synchronization issue. If I subscribe to a recorded FLV file through Flash Client and will start play then it will work perfectly with audio/video sync perfectly, but when I do the Stream.play for the same file and then subscribe to that stream from the Flash client then Audio and Video will out of sync and normally audio comes with no stoping or delay while video is not like that and so they become out of sync.

Is there someone helping this issue?
Suzanne Smith said on Oct 1, 2008 at 4:32 PM :
Synchronization is always improving. Using the latest versions of Flash Player and Flash Media Server can also help.
No screen name said on Dec 12, 2008 at 7:37 AM :
Is there an update on http://kb.adobe.com/selfservice/viewContent.do?
externalId=19067547 ?

Are VP6 or other codecs officially supported now, and if so, which versions
of Flash Media Server support them?
jody_b said on Dec 12, 2008 at 12:56 PM :
Enhanced seek in On2 VP6 was fixed in Flash Media Server version 2.0.4 and Flash Player 9.
Flash Media Server 3 and Flash Player 9 Update 3 support enhanced seek in H.264 content.
jody_b said on Sep 8, 2009 at 1:14 PM :
I'm not sure I understand your issue -- you'll either have to change the time playlist to match the length of the videos or truncate the videos to match the time sequence.

I'd suggest asking this question in the forums:
http://forums.adobe.com/community/flash/flash_media_server

 

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/00000788.html