3 Replies Latest reply on Aug 31, 2010 12:35 PM by gallion311

    Display current time for Windows Media (wmv) video?

    gallion311

      Hey whats up guys, creating some fairly simple Interactive CD's where we'll be showing alot of example videos.

       

      I'd like to annotate these videos with the elapsed time, just like how any other video player would...

       

      I searched quite a bit and found a topic on another site, but never really got a full answer, or at least one I could make work.

       

      Here's the code from the old topic:

       

        myDuration = member("myvideo").duration
        mref = member("Duration", "internal")
        mref.text = string(_movie.framesToHMS (myDuration, 60, 0, 0))

       

       

       

      Now this solution only displayed the duration of the clip, as a static number; so how do we make it count up progressivelly?

       

      To count down, simply calculate the remaining time every frame and display it. Assuming the code in your post gives you the duration and current time, this would be:

      (paste this code into a behavior script and attach it to the video sprite. I assume there is a text member called "duration"):

      property pSprite
      property pMember
      property pDuration

      on beginSprite me
        pSprite = sprite(the currentSpriteNum)
        pMember = pSprite.member -- assumes this is a digital video member
        pDuration = pMember.duration
      end

      on enterFrame me
        elapsed = pSprite.currentTime
        remaining = pDuration - elapsed
        --
        textMem = member("Duration", "Internal")
        textMem.text = me.milliToHMS(elapsed) && "|" && me.milliToHMS(remaining)
      end

      on milliToHMS me, in_milliseconds
        -- use your own code here to convert milliseconds to hours/minutes/seconds
        -- and return it as a string
      end

      This was the final solution but I couldn't get it working...

      Anyone have a complete solution using the above code, or even an alternate solution?

      Thanks!
      Ryan
        • 1. Re: Display current time for Windows Media (wmv) video?
          gallion311 Level 1

          Alright, I did a fair amount of readin yesterday and found a pretty good solution to my issue, and far more simple than the code posted above.

           

          So instead of using the duration function, and then subtracting to display the elapsed time, there's a function specifically for this type of usage.

           

          I used the currentTime, and that automatically updates as the video moves along.

           

          So here's the code to get this working:


          on exitFrame
            go to the frame
           
            member("mytextfield").text = string(framestoHMS(sprite("myvideo").currentTime, 30, 0, 0)) 
           
          end

           

          This returns the current time of the video, in minutes, seconds, milliseconds.

           

          The only remiaing question is how to parse and shorten that string into just minutes and seconds...

           

          So instead of 00:19:00.16, I'd want 00:19.

           

          I'd imagine the simplest method would be to grab the first 5 characters by using the char function, but couldn't get that to work.

           

          Any ideas?

          • 2. Re: Display current time for Windows Media (wmv) video?
            Mike Blaustein Level 4

            member("mytextfield").text = string(framestoHMS(sprite("myvideo").currentTime, 30, 0, 0)).char[1..5]

            1 person found this helpful
            • 3. Re: Display current time for Windows Media (wmv) video?
              gallion311 Level 1

              Thats it, thanks Mike I appreciate the assistance.

               

              Anyway, I do have another quick one:

               

              Now that I have everything displaying correctly I noticed the times are off; the timecode I'm displaynig seems to be way behind the video.

               

              After some trial and error I realized I could just use the .duration function to display the full time of the video and sure enough it's way off. I ended up having to change the tempo in FramestoHMS to 17. I could understand 15, but 17 is an unsual framerate...

               

              Any ideas on that one?

               

              It works, so I'm not complaining, but suspect I may be doing something wrong...