dougoftheabaci
dougoftheabaci

Reputation:

Get total time and time played from Flash Video component?

I've loaded a video into the FLVPlayback component and I'm looking for a way to get the total time and the time played so far and output them to two text fields so the end result would look something like "00:12/00:50".

Right now I'm defining the video by the components inspector but I'm eventually hoping to define this bit by actionscript as well. Any tips would be greatly appreciated.

Upvotes: 0

Views: 7270

Answers (3)

mika
mika

Reputation: 1451

To get the time:

flvPlayer.playheadTime;// gives you the current videp position 

As for formatting:

public static function formatTime(time:Number, detailLevel:uint = 2):String {
  var intTime:uint = Math.floor(time);
  var hours:uint = Math.floor(intTime/ 3600);
  var minutes:uint = (intTime - (hours*3600))/60;
  var seconds:uint = intTime -  (hours*3600) - (minutes * 60);
  var hourString:String = detailLevel == HOURS ? hours + ":":"";
  var minuteString:String = detailLevel >= MINUTES ? ((detailLevel == HOURS && minutes = MINUTES)) ? "0":"") + seconds;
  return hourString + minuteString + secondString;
}

Upvotes: 1

Jawdy
Jawdy

Reputation: 19

I know this is an old question - but I've been looking for some time and haven't found an answer.

If you're using the FLVPlayback component, then you can still use the MetadataEvent in order to get the metadata that is embedded within an FLV/F4V file. I created an FLVPlayback instance through AS3, listened for a MedataEvent.METADATA_RECEIVED event, then accessed the info property that the event returns. In code, it looks something like this:


package
{
import fl.video.FLVPlayback; // you will need to drag the component to the stage, then delete it.  This puts some stuff in the library and now you can access the class
import fl.video.MetadataEvent;
import flash.display.MovieClip;

public class flvTest extends MovieClip
{
private var inputURL:String = "./test.flv"; // change this to the location of your FLV/F4V
private var player:FLVPlayback;

public function flvTest():void
{
player = new FLVPlayback();
// set x,y,width,height values if you want
player.autoRewind = true; // I use this so when you press stop, it goes to the first frame
player.load( inputURL ); // you can use load() or source=
player.addEventListener( MetadataEvent.METADATA_RECEIVED, getMetaFromFLV );

addChild( player );
}

private var getMetaFromFLV( metadataEvent:MetadataEvent = null ):void
{
trace( "FLV Duration: " + metadataEvent.info.duration );
}

}
}

You obviously need some player controls etc, but the key to this reply is the MetadataEvent part. The info property that the event returns contains ALL the Metadata that is embedded within the FLV/F4V video file, so there are a lot of other values that you can get.

(Many other searches and posts only explain how to get the Metadata from NetStream and similar, which are used when connecting to a Flash Media Server - whereas here, we are accessing a local file and simply want the data that the file should have embedded within it).

I hope this helps someone!

Upvotes: -1

Related Questions