14.13. Seeking Relative to the Total Stream Length
Problem
You want to seek a stream based on the total length of the stream.
Solution
Get the stream length from the
server and then use the
seek( ) method.
Discussion
A problem arises when you want to seek within a stream relative to
the total length of the stream. For example, if you want to create a
slider that a user can move to seek through a stream, you must
determine the total length of a stream. There is no client-side
property or method that returns that information. However, you can
write a server-side function to return a stream’s
length using the Stream.length( ) method. Here
are the steps to return a stream’s length from the
server:
In the server-side .asc file (either the main.asc file or another .asc file that is loaded by main.asc) create a method for client objects that takes the name of a stream and returns the length of that stream (see Recipe 14.4). Most often, you assign methods to a client in the
application.onConnect( )method.// The
application.onConnect( )method is invoked automatically whenever a new // client connects to the FlashCom application. The client object is created and // passed as a parameter to the method. application.onConnect = function (newClient) { // Create a customgetStreamLength( )method for each client. The method takes // the name of a stream as a parameter. newClient.getStreamLength = function (streamName) { // Return the length of the requested stream. return Stream.length(streamName); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access