15 Replies Latest reply on Jul 19, 2006 2:33 PM by Opera Rat

    slider bar to control frames in movie

    Opera Rat Level 1
      How do I create a slider bar that will allow the user to move between 20 consecutive frames in the movie. (Each frame contains a different sprite)?
        • 1. Re: slider bar to control frames in movie
          donaldhines
          Attach This Code to your slider Button. This asumes Your SliderBar is 800 pixels long. I didn't use markerr, only frames 1 to 20 with an idle script on each frame. If you want I made a quick little example, i'd be happy to send it to ya.
          • 2. Re: slider bar to control frames in movie
            Opera Rat Level 1
            I started to write a lengthy reply with all the roadblocks I keep running into and while I was writing I think I solved them. I THINK, I HOPE. I will try this code in my program. Wish me luck. It's one of those days where NOTHING is working (atleast not until I mess with it for 3 hours!)

            Thanks.
            • 3. Re: slider bar to control frames in movie
              Opera Rat Level 1
              I tried your code but everytime I click on the slider bar I get thrown to the first frame of my movie. I tried setting myscore to = 60 where my 21 frames begin but no luck. I changed the variable names to see if that was the problem - nope! What's going on.
              • 4. Re: slider bar to control frames in movie
                donaldhines Level 1
                go to http://donaldhines.netfirms.com/Scroll.htm, right click the link, select 'Save Target As' and download the example. It's avery rough example but you should get the idea.
                • 5. Re: slider bar to control frames in movie
                  a¿ex Level 1
                  here's a behavior which acts similar to the playback head in the score window:


                  property pSprite, pThumb, pRect, pDragging, pStartFrame, pLength, pCurrentFrame

                  on beginsprite me
                  pSprite = sprite(me.spritenum)
                  pThumb = sprite(me.spritenum + 1)
                  pRect = pSprite.rect
                  pDragging = 0
                  pStartFrame = pSprite.startframe
                  pLength = float(pSprite.endframe - pStartFrame)
                  end

                  on enterframe me
                  if pDragging = 1 then pDragging = the mousedown

                  if pDragging = 1 then
                  mh = the mouseH
                  curr = (mh - pRect.left) / float(pRect.width)
                  curr = min(1, max(0, curr))
                  curr = integer(pLength * curr) + pStartFrame
                  if curr <> pCurrentFrame then -- only do something if necessary
                  pCurrentFrame = the frame
                  pThumb.locH = pRect.left + pRect.width * ((pCurrentFrame-pStartFrame)/pLength)
                  go curr
                  end if
                  else
                  if the frame <> pCurrentFrame then -- only do something if necessary
                  pCurrentFrame = the frame
                  pThumb.locH = pRect.left + pRect.width * ((pCurrentFrame-pStartFrame)/pLength)
                  end if
                  end if

                  end

                  on mouseDown me
                  pDragging = 1
                  end


                  -------------------------------------------

                  make a behavior with the above scripttext and attach the behavior to a sprite which acts as "sliderbar".
                  have another sprite with a graphic for the slider thumb in a spritechannel above the one of the slider bar.

                  HTH
                  • 6. Re: slider bar to control frames in movie
                    Opera Rat Level 1
                    Thank you. Your slider script works nice. I had to look at it for a while because the slider thumb didn't work. It needs to be in the sprite below, not above the slider bar.

                    I can't get the thumb to slide when I click and drag on it all the time. (I can't scub my "timeline"). NOW. hmmm. There is music playing. You see what is happening is this. Music changes pages according where the sound (also music) is. So measure 5 the graphic will change. I had to do this part with animation because the performer is not playing according to fixed time at all. Slows up and speeds down to extremes! So this cursor has to not only scrub the timeline but also scrub the music. How do I now get it to scrub the sound track?
                    • 7. Re: slider bar to control frames in movie
                      a¿ex Level 1
                      quote:

                      Originally posted by: Opera Rat
                      Thank you. Your slider script works nice. I had to look at it for a while because the slider thumb didn't work. It needs to be in the sprite below, not above the slider bar.


                      Yes, it depends on the perspective. in the score window 12 is below 11, but numerical 12 is above 11 and visually sprite 12 is also above sprite 11.
                      but that one was easy enough to figure out, wasn't it ? :-)

                      quote:


                      So this cursor has to not only scrub the timeline but also scrub the music. How do I now get it to scrub the sound track?



                      Ok, this is a completely different story, as everything should be controlled by the current time of the music and thus it depends on how you play the music. there are several different ways to play sound in director. which format is the sound in and which lingo do you use to control it?

                      • 8. Re: slider bar to control frames in movie
                        Opera Rat Level 1
                        Let me explain what's going on.

                        On the top of the screen is music. This music changes pages when necessary according to the sound file. Then there is a cursor on top of the music (not the sliderbar cursor). This cursor moves like a karaoke bar so that you can see just where the music is. Now all this MUST animated. The musician playing the music plays with the tempo drastically. The cursor cannot just move accros the screen in a fixed amount of time (no scripting here). It must be animated so that it can follow the sound exactly - Sometimes it nearly stops and then speeds up quickly. That would be a nightmare to put into any script.

                        Underneath this visual is an analysis of the piece of music from beginning to end. On top of this analysis is the "invisible" (transparent) sliderbar. Cursor #2 slides across the bar allowing the user to move from beginning to end of piece easily - and this causes the visuals to change with it (cursor #1 moves and the music changes pages).

                        So the user can slide the slider to the middle of the piece and see the middle of the piece and hear it start from wherever he drags it. (Just like a slider in any slider in a media program (real audio, quicktime, etc.)

                        Rightnow I have the music in the timeline so I could get the animations to work correctly but will have it play with something like sound (1).play (member:) when the uses clicks on cursor #2 - our slider cursor. The music is an mp3 file (no cuepoints, unfortunately). It has to stay and mp3 file. So somehow I need to gather information about the length of the sound file and have the slider move along the sound file just like the visuals.
                        • 9. Re: slider bar to control frames in movie
                          a¿ex Level 1
                          so in your case the sound controls, where the slider and the current position in the score should be.
                          first of all, you can't "scrub" the music. you should stop it as soon as the user clicks the slider thumb and starts dragging until the user releases the slider thumb. then you just start the sound at the current position.
                          to do this use the commands play() and stop() with a sound object (e.g. sound(1).stop() to stop the sound in channel 1)
                          and use the properties currenttime (or elapsedtime, should be the same) and the duration property of the member. these values are in milliseconds.

                          so you could change my abover behavior to something like the following and attch it to your slider bar:

                          [code]
                          property pSprite, pThumb, pRect, pDragging, pStartFrame, pLength, pCurrentFrame
                          property pSoundChannel, pSoundMember, pDuration, pAutoStart

                          on beginsprite me
                          pSprite = sprite(me.spritenum)
                          pThumb = sprite(me.spritenum + 1)
                          pRect = pSprite.rect
                          pDragging = 0
                          pStartFrame = pSprite.startframe
                          pLength = float(pSprite.endframe - pStartFrame)
                          if pAutoStart then mStartMusic me
                          end

                          on getpropertyDescriptionList
                          retlist = [:]
                          retlist[#pSoundMember] = [#default:member(1), #format:#sound, #comment:"Sound member"]
                          retlist[#pSoundChannel] = [#default:3, #format:#integer, #range:[1,2,3,4,5,6,7,8], #comment:"Sound channel"]
                          retlist[#pAutoStart] = [#default:1, #format:#boolean, #comment:"Automatically start playing ?"]
                          return retlist
                          end

                          on exitframe me
                          if pDragging = 1 then

                          pDragging = the mousedown

                          if pDragging = 0 then -- dragging stopped, now retart the sound at the current position
                          perc = (pCurrentFrame - pStartFrame) / float(pLength)
                          pDuration = pSoundMember.duration
                          thestartTime = min(pDuration, max(0, pDuration*perc))
                          sound(pSoundChannel).play([#member:pSoundMember, #starttime:thestartTime])
                          end if
                          end if

                          setframe = 0
                          if pDragging = 1 then
                          mh = the mouseH
                          curr = (mh - pRect.left) / float(pRect.width)
                          curr = min(1.0, max(0.0, curr))
                          curr = integer(pLength * curr) + pStartFrame
                          if curr <> pCurrentFrame then -- only do something if necessary
                          pCurrentFrame = the frame
                          pThumb.locH = pRect.left + pRect.width * ((pCurrentFrame-pStartFrame)/pLength)
                          setframe = 1
                          go curr
                          end if
                          else
                          if sound(pSoundChannel).isbusy() then -- only move if the sound is playing
                          perc = sound(pSoundChannel).currenttime / float(pDuration)
                          pCurrentFrame = pStartFrame + integer(pLength*perc)
                          pThumb.locH = pRect.left + pRect.width * ((pCurrentFrame-pStartFrame)/pLength)
                          setframe = 1
                          go pCurrentFrame
                          end if
                          end if

                          if setframe = 0 then go the frame
                          end

                          on mouseDown me
                          pDragging = 1
                          sound(pSoundChannel).stop()
                          end

                          on mStartMusic me, whichSoundMember, whichSoundChannel, whichStartTime

                          if ilk(whichSoundMember) = #member then
                          if whichSoundMember.type = #sound then pSoundMember = whichSoundMember
                          end if

                          pDuration = pSoundMember.duration

                          if ilk(whichSoundChannel) = #integer then
                          pSoundChannel = min(8, max(1, whichSoundChannel))
                          end if

                          if ilk(whichStartTime) = #integer then
                          whichStartTime = min(pDuration, max(0, whichStartTime))
                          else
                          whichStartTime = 0
                          end if

                          sound(pSoundChannel).play([#member:pSoundMember, #starttime:whichStartTime])

                          end
                          [/code]


                          in fact you don't need any other script now. this behavior will set the frame according to the sprite span of the "sliderbar" and according to the current time of the music.

                          • 10. Re: slider bar to control frames in movie
                            a¿ex Level 1
                            Ok I'll try this funny code window stuff, where you actually don't see the code you post in your message.
                            it's kind of WYSINWYG

                            • 11. Re: slider bar to control frames in movie
                              Opera Rat Level 1
                              Your code wants to work. If I choose not to use auto start it says it can't divide by zero. If I choose autostart then it begins to play on its own and moves correctly, but in either case I can't drag the slider. But I think we're almost there!
                              • 12. Re: slider bar to control frames in movie
                                Opera Rat Level 1
                                I find that the slider does work. I just have to be exactly on the registration point - kinda strange. So now I just have to be able to have it not auto start. Can you see where this is problem is in the code? I get can't divide by zero when I set auto play to no.
                                • 13. Re: slider bar to control frames in movie
                                  a¿ex Level 1
                                  so you have set it to autostart false and the sound channel in question is playing nonetheless ?

                                  add the following:

                                  in the first line of the handler "on beginsprite":
                                  pDuration = 0


                                  in the first line of the handler "on exitframe":
                                  if pDuration = 0 then exit



                                  I don't understand what you are talking about with the registration point.
                                  you will have to try to explain better, than just "it doesn't work"

                                  be aware of the fact, that there must not be a script on the slider thumb, so the slider thumb allows all mouseclicks to be registered by the slider bar. the sliderbar is what gets the mouseclicks and I for one can click on any part of the sliderbar so that it works.
                                  • 14. Re: slider bar to control frames in movie
                                    Opera Rat Level 1
                                    When it struck me that the script was on the slider bar, I realized that my cursor had to be on the bar. I was just using a thin line. I turned it into a fat rectangle the height of my slider thumb and now it works like it's supposed to.

                                    I added those lines and it now the music plays and my animation takes off but the slider thumb is just sitting there. If I click on the slider thumb the music stops. As this is at the beginning of the movie I don't want anything to happen until the user clicks on the slider. Clicking on the slider thumb is the play pause button. You've helped me so much. I can't thank you enough. Once this piece of the puzzle is in place. I can move on to the last piece that I've been avoiding. That is in my post about cuepoints. But I don't want to think about that until I get this solved.

                                    Thanks a google!
                                    • 15. Re: slider bar to control frames in movie
                                      Opera Rat Level 1
                                      I've added a play/pause button that works so I don' need any clicking on the thumb of the slider. I also put a loop in the frame before the music starts. So my first play button actually just moves you to the beginning of the music which starts playing automatically. This button becomes a pause button when the music starts and switches with a real play or resume button.

                                      Thank you all for all of your help.