[Red5] How can I get the duration of a stream

laysz liezhaoxie at yahoo.ca
Tue Feb 12 11:26:03 PST 2008


Hi,

  There is a tutorial that has code to something very similar to what you
want. 
http://www.actionscript.org/resources/articles/617/1/Streaming-and-database-connection-with-red5-media-server/Page1.html
His code disconnects users who have been playing a stream for more than 20
seconds.  He assigns a time stamp to the client id:

IClient client = conn.getClient( );        // setting client timestamp to 0,
because it doesn't started any stream
client.setAttribute( "stamp" , new Long( 0 ) );

He also overrides streamSubscriberStart so that he records the time when the
user starts watching the stream:
client = conn.getClient( );
Long stamp = (Long)client.getAttribute( "stamp" );        
if ( stamp == 0 ) client.setAttribute( "stamp" , System.currentTimeMillis( )
);

What you would do is override the disconnect(...) so that you first get the
current time.  Retreive the stamp attribute and take the difference.
client = conn.getClient( );
Long stamp = (Long)client.getAttribute( "stamp" );
Long result = System.currentTimeMillis( )  - stamp

That is how long your client was watching the stream for in milliseconds.

Hope that helps.





Yuanzong Qiu wrote:
> 
> Hi all
> 
> I am using Red5 as my media server, I have a question: I want to keep 
> tracking how long the user has played a music before closing. I mean the 
> length of the music instead of the real clock time. I am thinking of 
> adding a method in Appleave function, but failed. Any help would be 
> greatly appreciate.
> 
> Thanks
> 
> Qiu Yuanzong
> 
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-duration-of-a-stream-tp15439592p15440872.html
Sent from the Red5 - English mailing list archive at Nabble.com.




More information about the Red5 mailing list