Hi,
I was wondering if anyone knows how to get the current time that the playhead is at to display it. like on a youtube player. I can get the total duration time of the flv but i am having trouble with the current time it is playing at. I am assuming this has to interact somehow with the scrub bar for when people jump around in the video. This player was created using the tutorial offered at gotoandlearn.com.
Below is my code i have so far. I commented the things I thought might be vague. Any help is appreciated.
//you need to change the path to the flv file and the path to the xml file for the dropdown
rewindBtn.onRelease = function(){
stream_ns.seek(0);
}
// pause button function
pauseBtn.onRelease = function(){
stream_ns.pause();
}
// stop button function
stopBtn.onRelease = function(){
//stream_ns.seek(0);
stream_ns.play.stop(0);
}
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
var stream_ns:NetStream = new NetStream(connection_nc);
video.attachVideo(stream_ns);
//video name i am pulling to test
stream_ns.play("jay.flv");
stream_ns.setBufferTime(20);
stream_ns.onStatus = function(info){
if(info.code == "NetStream.Buffer.Full"){
bufferClip._visible = false;
}
if(info.code == "NetStream.Buffer.Empty"){
bufferClip._visible = true;
}
if(info.code == "NetStream.Buffer.Stop"){
stream_ns.seek(0);
}
}
var videoInterval = setInterval(videoStatus, 100);
var amountLoaded:Number;
var duration:Number;
stream_ns["onMetaData"] = function(obj){
duration = obj.duration;
}
function videoStatus(){
amountLoaded = stream_ns.bytesLoaded / stream_ns.bytesTotal;
loader.loadBar._width = amountLoaded * 240;
loader.scrub._x = stream_ns.time / duration * 240;
}
var scrubInterval;
//loader is the MC that the scrubber and bar are located in
loader.scrub.onPress = function(){
clearInterval(videoInterval);
scrubInterval = setInterval(scrubIt, 10);
this.startDrag(false, .5, this._y, 232.5, this._y);
}
loader.scrub.onRelease = loader.scrub.onReleaseOutside = function(){
clearInterval(scrubInterval);
videoInterval = setInterval(videoStatus, 100);
this.stopDrag();
}
function scrubIt(){
stream_ns.seek(Math.floor((loader.scrub._x / 232.5)*duration));
}
var scrubEndInterval = setInterval(endPlay, 100);
function endPlay(){
if (loader.scrub._x == 239){
stream_ns.pause();
stream_ns.seek(0);
controlBtn.gotoAndStop(2);
return;
}
}
var showTalkInterval = setInterval(showTalk, 1000);
function showTalk(){
if (stream_ns.bytesLoaded == stream_ns.bytesTotal){
viewTalk._visible = true;
}
}
//this gets my duration
stream_ns.onMetaData = function(metadata) {
duration = metadata.duration;
var dur_seconds:Number = duration;
var minutes_dspl = Math.floor(dur_seconds/60);
var seconds_dspl = Math.floor(dur_seconds%60);
if (minutes_dspl<10) {
minutes_dspl = ("0"+minutes_dspl);
}
if (seconds_dspl<10) {
seconds_dspl = ("0"+seconds_dspl);
}
//textTime is the variable name for the text field
textTime.text = minutes_dspl+":"+seconds_dspl;
};
///form here down i found this online but it seems like there is more to it that i am missing or i
///just screwed it up somewhere
curTime = formattime(stream_ns.time)+" / "+formattime(duration);
//format the time of the video
function formattime(intime) {
//initialize it to null
output = "";
//calculate the current passed minutes
minutes = Math.floor(intime/60);
//if the minutes are under 10, add in a leading 0
if (minutes<10) {
output += "0";
}
//output the minutes
output += minutes+":";
//if the seconds are under 10, add in a leading 0
if (intime%60<10) {
output += "0";
}
//output the time
output += Math.floor(intime%60);
//return the time
return (output);
}