13 Replies Latest reply on Dec 1, 2008 10:33 AM by rtalton

    playheadTime issue

    rckehoe Level 1
      I am having a small issue with playheadTime. I have a datagrid that lists all the cuePoints for my video... I am trying to jump to certain cuePoints when you select an item from the grid. I have not been having much luck, for some reason it when I use this playheadTime function, it always jumps me 20 seconds for each cuePoint...

      For Example:
      Point 1: 20 Seconds
      Point 2: 40 Seconds
      Point 3: 60 Seconds (or 1 Minute)

      I have manually entered my info, but for some reason is not working...

      Here is my script, any help would be appreciated.
        • 1. Re: playheadTime issue
          rtalton Level 4
          Is this a progressive download? If it is, seeking to a cuepoint will take you to the first keyframe after a cuepoint, not the cuepoint itself. Place your cuepoint before the keyframe nearest the time you are seeking to, and it will jump to the correct position.
          • 2. Re: playheadTime issue
            John Hall Level 4
            So you're saying no matter what you click on, it jumps to the first cue point, right?
            • 3. Re: playheadTime issue
              rckehoe Level 1
              I am new to Flex, so I will try to answer these questions as best that I can...

              I did not encode the FLV videos that I am going to use, I am creating the cuePoint array in the VideoDisplay tag like the code below...

              And no, it doesn't jump to the first cue point. It always jumps 20 seconds for each cuepoint...

              For example:
              The first line in the data grid jumps to 20 seconds (rather than 11)
              The second line in the data grid jumps to 40 seconds (rather than 22)
              The third line in the data grid jums to 60 seconds (rather than 33)

              This goes on for all the lines in the datagrid, all of which are spaced 20 seconds apart.

              <mx:cuePoints>
              <mx:Array>
              <mx:Object name="01 - eTraining" time="11"/>
              <mx:Object name="02 - Attend and Retake" time="22"/>
              <mx:Object name="03 - Keyfactors" time="33"/>
              <mx:Object name="04 - Consistent Learning" time="56"/>
              <mx:Object name="05 - Certifications" time="69"/>
              <mx:Object name="06 - Global Access Training" time="88"/>
              <mx:Object name="07 - Save!" time="108"/>
              </mx:Array>
              </mx:cuePoints>

              • 4. Re: playheadTime issue
                rtalton Level 4
                The event handler should be looked into next.
                I wouldn't use "event.currentTarget.selectedItem" as the parameter.
                Simply pass the event object itself and it will contain the selected item that you want to get to...

                Edit your change event on the Data Grid like so:
                change="JumpQue(event)"

                Edit your handler like so:
                private function JumpQue(event:ListEvent):void{

                Put a break point in the handler. Now go into debug, click a row in the Data Grid, and look at the event.currentTarget in the handler.
                Look for the value of the Data Grid item you cliked on and that it contains the value you are expecting. Many times you will see that you need to use a different "path" to get to the selected item's property, and the correct time value you are looking for.

                If you can post complete code, this might help also.
                • 5. Re: playheadTime issue
                  rckehoe Level 1
                  I don't mean to sound like a complete Newb... But... I get an error... Here is the error, perhaps you can lead me in the right direction.

                  1046: Type was not found or was not a compile-time constant: ListEvents


                  • 6. Re: playheadTime issue
                    rckehoe Level 1
                    Actually, I think the syntax was incorrect... I tried the following, and there are no more errors...

                    private function JumpQue(ListEvent:Event):void {

                    Is this the same thing as what you said ?
                    • 7. Re: playheadTime issue
                      rtalton Level 4
                      Close! It should read:
                      private function JumpQue(event:ListEvent), not:
                      private function JumpQue(ListEvent:Event) -you have it backwards in the parenthesis from what I wrote.

                      Just to be clear, "event" is a made-up variable name/word, and "ListEvent" tells Flex what kind of event is coming into the function. You could substitute any suitable word instead of "event", like:
                      JumpQue(wowzah:ListEvent), or
                      JumpQue(evt:ListEvent), or
                      JumpQue(dirtyHarry:ListEvent)...
                      ...but you should tell Flex that this is a ListEvent dispatched by the List control.
                      Your syntax works because you are telling Flex to use a made-up word "ListEvent" of type "Event"-a generic Event object. Not real accurate, but it should work.
                      I think you have it now, since you are not getting an error. Read the help docs on the error object. Then when you are setting up an event handler (oops, er, "listener"), also look in the help docs for the control (DataGrid, List, Image... whatever you are using) and see the "Events" section for the control. There you pick the event that makes the most sense to you and "listen" for that event. This will tell you what event type to put into the parenthesis after your variable name. Remember, it's "(variablename:EventType)"

                      Good Luck!


                      • 8. Re: playheadTime issue
                        rckehoe Level 1
                        ok... I got the ListEvent deal working without error, but when I click on an item from the datagrid it still doesn't advance the video to the correct spot.

                        So... I add a response.text at the bottom of the function to see what the variable is. In the textbox I created, it shows the correct number...

                        My question is... Am I to put a whole number in seconds like... 33 seconds, 26 seconds... Or should it be a decimal or something... 0.3, or 0.26 ??

                        here is the NEW function that you had me change...

                        private function JumpQue(TimeEvnt:ListEvent):void {
                        var NewTime:int = TimeEvnt.currentTarget.selectedItem.time;
                        InstructorVideo.playheadTime=NewTime;
                        response.text = TimeEvnt.currentTarget.selectedItem.time;
                        }
                        • 9. Re: playheadTime issue
                          rtalton Level 4
                          I'm going to look at this and get back to you in a bit...
                          • 10. Re: playheadTime issue
                            rckehoe Level 1
                            I think I found the issue...

                            It wasn't the code, it was the FLV file itself. I think it was encoded wrong... So I used another FLV that I encoded myself and it seemed to work fine.

                            However, If I don't add any cuePoints or Keyframes when I encode the FLV, would that allow me to add them in my Flex app without issue?

                            • 11. Re: playheadTime issue
                              rtalton Level 4
                              I experimented with the playheadTime property and learned that you cannot set it to an exact time unless it coincides with a keyframe (see explanation below).
                              See an example here:
                              http://www.anaheimwib.com/_comps/video/ (I'll leave it up for a couple of days).

                              This will let you experiment with different times to see where the playhead moves to.
                              Essentially, what happens when you set playheadTime is that it will move to the first keyframe AFTER the cuepoint.
                              I used After Effects to create the FLV and set the cuepoints (see details below). By default, the Adobe Media Encoder set the keyframes at 2-second intervals. Note that in the application example I posted, you cannot move the playhead to any other value except 2 seconds, 4 seconds, 6 seconds etc. Any value you input in between these 2-second keyframe intervals will move the playhead to the next keyframe downstream in the file. (Note: this test is for progressive download, not streaming)

                              So, unless your cue points match up exactly with a keyframe, you will not be able to move the playhead exactly to that cuepoint.

                              Settings the keyframes manually might help you, but keep in mind that overriding the encoder keyframe placement can degrade video quality in some cases and you'd have to increase the bitrate to compensate, resulting in a larger file (this is a whole 'nother topic I won't get into here, but it involves how the encoder is compressing the frames).

                              Video details:
                              Used the Adobe Media Encoder in After Effects CS3.
                              frame rate: 24 fps (set to match Flex's default frame rate)
                              bitrate: 400 kbps
                              no audio
                              codec: On2 VP6
                              cue points were encoded at 0, 11, 22, 33, 56, 69, 82, 108 and 120 seconds, as rckehoe used in his example.

                              Let me know if this was helpful.
                              • 12. Re: playheadTime issue
                                rckehoe Level 1
                                I understand perfectly... Thank you for spending time on this!
                                • 13. Re: playheadTime issue
                                  rtalton Level 4
                                  No problem. I needed to test the VideoDisplay control anyway. Never use it, myself!