I did a very simple update to Lee Brimelow's timecode class to make it work with Flash 8's FLVplayback component. Lee actually had his version as a nice, tidy AS Class; but for this I made a down-and-dirty function.
// GetTimeCode Function
// Adapted from Lee Brimelow's timecode class for netStream
function getTimecode(thisFLV,thisProp):String {
if (thisProp == "playheadTime") {
var t:Number = Math.round(thisFLV.playheadTime);
} else if (thisProp == "duration") {
var t:Number = Math.round(thisFLV.metadata.duration);
} else if (thisProp == "timeRemaining") {
var t:Number = Math.round(thisFLV.metadata.duration - thisFLV.playheadTime);
}
var min:Number = Math.floor(t/60);
var sec:Number = t%60;
var tc:String = new String("");
if(min < 10) {
tc += "0";
}
if(min >= 1) {
tc += min.toString();
}
else {
tc += "0";
}
tc += ":";
if(sec < 10) {
tc += "0";
tc += sec.toString();
}
else {
tc += sec.toString();
}
return tc;
}//getTimecode
Also, I added another parameter to the function call so you can retrieve more than just the current position in timecode format: you can get the current time as well as time remaining and total time.
To use the function simply call getTimecode() and include a reference to your FLVPlayback instance and the property you wish to retrieve such as "playheadTime", "duration" or "timeRemaining".
For example: tcDisplay.text = getTimecode(myFLV, "timeRemaining";
To have this function update regularly while your video is playing you can simply call it during a setInterval loop.
Do you have the actual code to use your Timecode Function for Flash FLVplayback with a setInterval loop?
thanks, that info would be much appreciated!
Is there anyway you can send me a fla with this code in it?
PLEASE
Just need a more detailed description for where to place the code
tcDisplay.text = getTimecode(myFLV, "timeRemaining"); and how I put it in a 'setInterval loop' when using it with dynamic text such as playheadTime 00:00 etc. Thanks.
To properly use the getTimecode() function in this blog post, you first need to have a dynamic text field on your stage with an instance name of 'tcDisplay' (without the quotes). This is the text field that will be updated on the interval you set.
Then, in the actionscript panel, insert the following code directly after the above code in the actionscript panel:
function updateText() {
timeValue = getTimecode(player, "timeRemaining");
tcDisplay.text = timeValue;
}
myInterval = setInterval(updateText, 1000);
This is great stuff, thank you. I'm not sure why, but I am unable to get "duration" and "timeRemaining" to work using 'thisFLV.metadata.duration'. Can you please send me a copy of your FLA file so I can see how you used it? It would be very helpful. Thank you!
Is it possible to e-mail me the .fla file or post it on the site?
I am not a programmer and I have followed the instructions but I am still getting the NaN:N error.
I have imported a .flv movie (Compressed with Sorenson Squeeze) with a contentPath to my website url and instance named it 'thisFLV' (without quotes)
I have created Dynamic Text on the stage and entered the value 00:00 with the instance named 'tcDisplay'. (Is entering 00:00 correct or does the text box have to be blank?)
I have copied the main code above which was adapted from Lee Brimelow's timecode class in to an action at frame 1. I then copied the code supplied by Theo and pasted it after the main code as instructed.
The movie plays, but I can't get the timecode to work.
Where am I going wrong?
I presume that my flv file has to include metadata? If this is the problem, what metadata should the file have and how do I check it is there?
I have had a look at the Metadata of my FLV using FLVMDV.
It seems that the duration data is there for this code to work.
Video Codec:On2 VP6
Audio Codec: MP3 44kHz 16bit Stereo
Frame rate: 25 fps
Duration: 5:19:764
onMetaData event data:
onMetaData
duration:319.79
width:420
height:236
videodatarate:1200
canSeekToEnd:false
videocodecid:4
audiodatarate:192
audiocodecid:2
framerate:25
Managed to work it out.
Anna, you will be please to know that it works with duration and timeRemaining.
With Theo's code it wasn't obvious what the instance name of the .flv had to be.
Ok.
Name the .flv instance as 'player' (no quotes)
The .flv is previously imported from a webserver/streaming service.
You can set the contentPath and other settings under Parameters.
Create 3 Dynamic Text boxes on the stage
(You can type 00:00 in the boxes, but it is not essential)
Enter 'tcDisplay', 'tcRemaining', 'tcDuration' as the instance names.
Paste the code below at the end of the main code adapted from Lee Brimelow's timecode class (as an action at frame 1)
// updateText Function
function updateText() {
timeValue = getTimecode(player,"playheadTime");
tcDisplay.text = timeValue;
timeValue = getTimecode(player,"duration");
tcDuration.text = timeValue;
timeValue = getTimecode(player,"timeRemaining");
tcRemaining.text = timeValue;
}
myInterval = setInterval(updateText,1000);
Andy, you have no idea of how much you helped me out with this! thank you!
WOW... this has saved my job...... thank you to everyone who contributed!!!
I got this to work when simply importing a FLV file into Flash 8, however I'm using an XML file to load multiple FLV files and I can't get it to work with this code (taken from a gotoandlearn.com tutorial):
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
theVideo.attachVideo(ns);
rewindButton.onRelease = function() {
ns.seek(0);
}
playButton.onRelease = function() {
ns.pause();
}
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 * 228;
loader.scrub._x = ns.time / duration * 228;
}
var scrubInterval;
loader.scrub.onPress = function() {
clearInterval(videoInterval);
scrubInterval = setInterval(scrubit,10);
this.startDrag(false,0,this._y,228,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 / 228) * duration));
}
var vlist:XML = new XML();
vlist.ignoreWhite = true;
vlist.onLoad = function() {
var videos:Array = this.firstChild.childNodes;
for(i=0;i
videoList.addItem(videos[i].attributes.desc,videos[i].attributes.url);
}
ns.play(videoList.getItemAt(0).data);
videoList.selectedIndex = 0;
}
var vidList:Object = new Object();
vidList.change = function() {
ns.play(videoList.getItemAt(videoList.selectedIndex).data);
}
videoList.addEventListener("change",vidList);
vlist.load("videos.xml");
Wow, this is awesome!!!!! I have been working on this for months and just now found this solution. Thanks to everyone!!!
Works Perfect. Thank You!!