FORUMS: list search recent posts

AS3 - Video Stream - add Listener for .time and .duration

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Patrick Wilkes
AS3 - Video Stream - add Listener for .time and .duration
on Mar 23, 2011 at 6:09:55 pm

Hi There!

I am using AS3 to stream a couple videos into an .swf The video playback and everything else works fine. What I want to do is add an event listener to the stream so that it reports back two things: the total time of the stream and the current time. I have seen posts elsewhere talking about querying MetadataEvent.METADATA_RECEIVED, but not sure how to get this to work. Any help would be much appreciated! Thanks.

CODE:

import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;

var connection:NetConnection = new NetConnection();
var stream:NetStream;
var md_obj:Object = new Object();

var vidContainer:MovieClip = new MovieClip();
var vid:Video=new Video(320,240);

var cur_mov;
var cur_fr;
var swa_mov:String="../video/test01.flv";
var eng_mov:String="../video/test02.flv";

//video stream setup
connection.connect(null);
stream=new NetStream(connection);
vid.attachNetStream(stream);
stream.client=md_obj;
stream.pause();

function playMovie() {
disableButtons();
stream.play(cur_mov);
if (pause_clicked==true) {
stream.seek(stream.time - 1.5);
}

//this is where I'm stuck -------------------------

stream.addEventListener(MetadataEvent.METADATA_RECEIVED, total_time);
function total_time(event:MetadataEvent):void {
trace(MetadataEvent.info.duration);


//----------------------------------------------------


//if the movie reaches its end, restart the movie and pause it
md_obj={NetStatusEvent:stream_onPlayStatus};
stream.addEventListener(NetStatusEvent.NET_STATUS, stream_onPlayStatus);
function stream_onPlayStatus(event:NetStatusEvent):void {
trace(event.info.code);
if (event.info.code=="NetStream.Play.Stop") {
stream.seek(0);
button_pause.visible=false;
button_play.visible=true;
pauseMovie();
}
}
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]