Getting the current time of a loaded flv file

  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

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);
}
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23454
  • Loc: Woodbridge VA

Post 3+ Months Ago

Check number 32 in this tutorial. I think it's basically what you are after.

http://www.actionscript4designers.com/w ... ents3.html

Quote:
Display the current playback time in a Dynamic Text field

1. Select the my_playback MediaPlayback instance
2. With the my_playback instance selected, add this ActionScript in the Actions panel:

on(change) {
// trace(this.playheadTime); // display FLV's current time
_parent.video_length_txt.text = this.playheadTime;
}

This sends the value of the MediaPlayback.playheadTime property to the Dynamic Text field whose instance name is video_length_txt. We prefix the name with the addressing information _parent, because components are like movie clips: if you need to target something outside of the component/clip, you first must leave the component/clip's timeline. To send a string of information (the numerical value is automatically converted to a string in ActionScript 1.0) to a Dynamic Text field, we send it to the Dynamic Text field's text property.
3. Comment out the trace() statement by putting two forward slashes in front of it
4. Save and test movie

As the FLV is playing, the elapsed time (current playback time) is sent to the Dynamic Text field (instance name: video_length_txt). This means we can find out the video length outside of the Flash authoring system (the only place the Output window is available).


You might also find additional ideas with searches for these terms

display playheadTime
or
display.playheadTime
  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

Thank you ATNO/TW. I will try applying your ideas tomorrow. I will let you know if i was successful. Again thank you.
  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

That code seems to be only for the drag and drop media player. The one i have is all custom. I foun out how to do it and also convert the seconds to minutes when it reaches 60. Let me know if you want this code , I will give it to you. Thanks for the help.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23454
  • Loc: Woodbridge VA

Post 3+ Months Ago

Glad you figured out something. It would be nice to have the code, but if you're up for it, you may have noticed Bigwebmaster has started adding tutorial sections to OZZU. This Flash forum is one that doesn't have any tutorials yet. If you feel up to writing a tutorial on what you did, I think it would be awesome.

You can find the format and instructions for posting tutorials in the announcements board
announcements-rules/tutorial-making-tutorials-for-ozzu-howto-t85736.html

Then just PM Bigwebmaster and let him know you'd like to add one here. Up to you of course but would love to see you take the challenge.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.