FLV player, duration and time output

Hello all,

I have a fully working flv player using the netstream method.

I would like to display the total duration of the flv together with the amount that the video has currently played in a text field.

e.g. 1.21 / 4.23

How may i go about doing this?

I’m using Flash 8, Actionscript 2.0.

My code is:


 
[LEFT]var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
theVideo.attachVideo(ns);
ns.setBufferTime(10);
ns.onStatus = function(info) {
 trace(info.code);
 if(info.code == "NetStream.Buffer.Full") {
  bufferClip._visible = false;
 }
 if(info.code == "NetStream.Buffer.Empty") {
  bufferClip._visible = true;
 }
 if(info.code == "NetStream.Play.Stop") {
  ns.seek(0);
 }
}
ns.play("http://idl.newport.ac.uk/einclusion/flash/PEOPLEoverview_movie.flv");
playPause.onRollOver = function()
{
 if(this._currentframe == 1) 
  this.gotoAndStop('pauseOver');
 else this.gotoAndStop('playOver');
 }
 
playPause.onRollOut = function()
{
 if(this._currentframe == 10) this.gotoAndStop('pause');
 else this.gotoAndStop('play');
 }
playPause.onRelease = function() {
 if(this._currentframe == 10)
 {
  this.gotoAndStop('playOver');
  this._parent.ns.pause();
 }
 else
 {
  this.gotoAndStop('pauseOver');
  this._parent.ns.pause();
 }
}
 
rewindButton.onRelease = function() {
 ns.seek(0);
}
var videoInterval = setInterval(videoStatus,100);
var amountLoaded:Number;
var duration:Number;
ns["onMetaData"] = function(obj) {
 duration = obj.duration;
}
function videoStatus() {
 amountLoaded = ns.bytesLoaded / ns.bytesTotal;
 loader.loadbar._width = amountLoaded * 328.9;
 loader.scrub._x = ns.time / duration * 328.9;
}
var scrubInterval;
loader.scrub.onPress = function() {
 clearInterval(videoInterval);
 scrubInterval = setInterval(scrubit,10);
 this.startDrag(false,0,this._y,328,this._y);
}
loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
 clearInterval(scrubInterval);
 videoInterval = setInterval(videoStatus,100);
 this.stopDrag();
}
function scrubit() {
 ns.seek(Math.floor((loader.scrub._x/328)*duration));
}[/LEFT]
 

All help will be appreciated as I have been trying to find a solution for this for quite some time now!

Regards

EGR103

I think this coding may be useful for u.(flv player with time display)

event listener for changing the time display

function updateNP(event:Event):void {
// time code code…
var totalSeconds:Number = theplaya.playheadTime;
var totalSeconds2:Number = theplaya.totalTime;
var minutes:Number = Math.floor(totalSeconds /60);
var minutes2:Number = Math.floor(totalSeconds2 /60);
var seconds = Math.floor (totalSeconds) % 60;
var seconds2 = Math.floor (totalSeconds2) % 60;
if (seconds < 10){
seconds = “0” + seconds;
}
if (seconds2 < 10){
seconds2 = “0” + seconds2;
}
timeBox.text = minutes + “:” + seconds + " / " + minutes2 + “:” + seconds2;

}
this.addEventListener (Event.ENTER_FRAME, updateNP);

well for one duration is coded into the above script though you have to devide it by 60

also the above is correct in principle

fasilak is wrong meta data is not needed, unless your flv encriptiong mucks up how flash reads its duration and scrub time.