5 Replies Latest reply on Jan 5, 2010 2:26 PM by schipmold

    current frame for Spark VideoPlayer


      Hi all,


      I've been playing with the Spark VideoPlayer but can't find a way to get the playhead's frame position.


      The playhead's time is fine, but that only works with seconds and I need to get the exact timecode.

      Since I know the framerate and duration from the metadata I figured I should be able to calculate the milliseconds if I know what frame the head is on...

      Or does anyone know another way to get the exact timecode?




        • 1. Re: current frame for Spark VideoPlayer
          rfrishbe Level 3

          The currentTime property should be more granular than seconds. Do you not see this?  In fact, it should be really granular, but we only dispatch currentTimeChange events every 250 milli-seconds by default. I did a quick test, and when polling this property on every frame, it gets updated correctly.


          In the VideoPlayer, in the UI, we round to the nearest second, though one could change that by modifying the skin or overriding formatTimeValue() in VideoPlayer.


          I don't think there's a way to get the frame number from the video.


          Here's the test I ran:


          <?xml version="1.0" encoding="utf-8"?>
              xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:d="http://ns.adobe.com/fxg/2008/dt" xmlns:th="http://ns.adobe.com/thermo/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
              width="900" height="100%" backgroundColor="#ffffff">
                      import mx.events.FlexEvent;


                      protected function videoplayer1_creationCompleteHandler(event:FlexEvent):void
                          addEventListener(Event.ENTER_FRAME, function(event:Event):void


              <s:VideoPlayer id="vp" source="Fuel.mp4" creationComplete="videoplayer1_creationCompleteHandler(event)" />


          I think that should be granular enough for you.  If it's not, please post your use-case and why you need the current frame of the video.




          • 2. Re: current frame for Spark VideoPlayer
            schipmold Level 1

            Hi Ryan,


            Thanks for the example, but what build are you using exactly?

            It looks like 'currentTime' is not a property of VideoPlayer by the language ref or the build I'm using ( so I get an error on that line.




            • 3. Re: current frame for Spark VideoPlayer
              schipmold Level 1

              Never mind Ryan, I got it to work with the playhead now as well. Thanks for the advise.


              Now I'm only running into a problem with the actual playheadtime.


              I've got a 6 seconds clip that's played in the videoplayer and stops at the last frame.

              The metatdata duration value is always 6 which is correct, but the playheadtime at the last frame varies between 5.9999 and 6.1.

              Most of the time it's correct and stops at 6, but it doesn't seem to be reliable.


              Do you know a workaround for that as well?






              <?xml version="1.0" encoding="utf-8"?>

              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"


                 xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">



              import mx.events.StateChangeEvent;


              import spark.events.VideoEvent;


              [Bindable] private var duration:Number = 0;

              [Bindable] private var currentTc:String = "";


              protected function videoPlayer_currentStateChangeHandler(event:StateChangeEvent):void






              protected function videoPlayer_enterFrameHandler(event:Event):void


              if (event.target.playing) {






              protected function videoPlayer_metadataReceivedHandler(event:VideoEvent):void


              duration = event.metadataInfo.duration;



              private function calcTC():void {

              trace("playheadTime :"+videoPlayer.playheadTime.toString());

              trace("metadata duration: "+duration);

              var m:Number = Math.round(videoPlayer.playheadTime/60);

              var s:Number = Math.floor(videoPlayer.playheadTime - (m*60));

              var ms:Number = Math.round(1000*(videoPlayer.playheadTime - Math.floor(videoPlayer.playheadTime)));


              var mss:String = "";


              if (ms<10) {

              mss = "00"+ms;

              } else if (ms<100) {

              mss = "0"+ms;

              } else {

              mss = ms.toString();



              var tc:String = '';

              tc += m<10? '0'+m : ''+m;

              tc += s<10? ':0'+s : ':'+s;

              tc += ':'+mss;


              currentTc = tc;




              protected function videoPlayer_playheadUpdateHandler(event:VideoEvent):void








              <s:VideoPlayer id="videoPlayer"








              <s:Label x="441" y="18" text="Duration (s):" width="79" height="14" textAlign="right"/>

              <s:Label x="533" y="18" id="durationLabel" text="{duration}" width="179" height="14"/>

              <s:Label x="441" y="40" text="Timecode:" width="79" height="14" textAlign="right"/>

              <s:Label x="533" y="40" id="tcLabel" text="{currentTc}" width="179" height="14"/>


              • 4. Re: current frame for Spark VideoPlayer
                rfrishbe Level 3

                Hmm, that seems weird, and it should be consistent.  I didn't run your sample, but it might be related to:




                Can you look at the workaround described in FM-225 (a related bug to FM-238) and see if that helps?



                • 5. Re: current frame for Spark VideoPlayer
                  schipmold Level 1

                  Ok, I've gone over FM-225 and FM-238 but can't really find the workaround you mentioned.


                  I did just download the water.flv example referred to in FM-225, but I do also see the same issue with that one so I'm not entirely sure if this is the same issue.

                  9 out of 10 times the playheadTime on the last frame is the same as the duration (7.347), but every now and then the playhead ends at 7.307 and the duration is still 7.347.


                  I've also created a new clip with FFMpeg which removes any metadata from the original clip so there should be no audio delays and it also happens with that (again 9 out of 10 times).