PDA

View Full Version : FLV player, duration and time output



egr103
June 4th, 2008, 11:32 AM
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:





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));
}



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

Regards

EGR103

fasilak
June 4th, 2008, 12:24 PM
This cant be done directly.
You require the FLV file to be injected with meta data...
for more details visit:
http://www.buraks.com/flvmdi/ (http://www.buraks.com/flvmdi/)

The below code is the implementation part which should done after the meta data has been injected. Hope this helps..

If you find a better possible way please let me know.


nc = new NetConnection();
nc.connect(null);
nets = new NetStream(nc);
video.attachVideo(nets); //Video is an Embedded Video symbol
nets.play("sample.flv");
nets.onMetaData = function(metadata){
trace('onMetaData event at '+nets.time);
trace(' duration: '+metadata.duration+newline+
' lasttimestamp: '+metadata.lasttimestamp+newline+
' lastkeyframetimestamp: '+metadata.lastkeyframetimestamp+newline+
' width: '+metadata.width+newline+
' height: '+metadata.height+newline+
' videodatarate: '+metadata.videodatarate+newline+
' audiodatarate: '+metadata.audiodatarate+newline+
' framerate: '+metadata.framerate+newline+
' creationdate: '+metadata.creationdate+newline+
' filesize: '+metadata.filesize+newline+
' videosize: '+metadata.videosize+newline+
' audiosize: '+metadata.audiosize+newline+
' datasize: '+metadata.datasize+newline+
' metadatacreator: '+metadata.metadatacreator+newline+
' metadatadate: '+metadata.metadatadate );
}

pclaridge
June 5th, 2008, 03:05 AM
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);

randomagain
June 5th, 2008, 06:04 AM
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.