Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Direct Media Simple Control
Importing Photoshop layers
ZGTSB-Slider Button
Iconizer
Flash Sprite Cusor Changing Movie Script
Update QT3 movies
Colour Conversions Galore!
Open URL
3DVista Studio Director Xtra
Dryclean
 

 

 

Article Show Me the Movie

Added on 11/15/1999

 

Compatibilities:
D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: MediaMacros (website)

I have a video that I want to create a custom set of buttons for. Pause and play are easy enough, but how can I set up the slider, rewind, fast forward, etc.?

Get the source
You might want to start with the "show me" movies that ship with Director, but lets take a different approach.  If we know the exact location of each sprite we can always get and send data to each sprite allowing interaction.  What a slider bar mandates is that the 2 talk back and forth.  The slider gets the current time from the movie and moves accordingly, and the movie must be able to take input from the slider when the user moves it.  We can assign a sprite for the video to "live" in and another for the bar, but lets look at a more global approach.

Using the sendAllSprites command we can globally broadcast commands that will be picked up by the item that needs it. We'll use the "smart behavior" method to give the getPropertyDescriptionList handler just the items it needs. This is just an approach of stripping away any unneeded properties so that a single behavior can be used on all items.  By checking the type of the member we drop the behavior on we can skip asking the digital video which item it should be.  The same technique can be used in the other handlers so that the video runs its commands and all the buttons ignore it.

Lets start with the easy stuff.  Play, pause, stop, fast forward and rewind all use the movieRate property to decide the play speed. If we set it to 1 then the movie plays.  Set it to 0 and it stops.  A negative value reverses it, etc.  Now we can take a look at our friend the slider.  We will create a custom handler to calculate the position of the slider based upon the movie.  The basic idea is...

movieTime / movieDuration = percent done

We can then multiply the result by the length of the bar to place the slider.  Now we can go back and do this the other way.  When the user clicks on the slider we start a repeat loop that calculates the position of the slider and sends that to the movie to adjust the movie time to the same relative position.

So that is the theory behind it. The example code is below...

--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)

property spriteNum, whatItem, sliderList

on getPropertyDescriptionList me
  p_list = [:]
  if [#quickTimeMedia, #digitalVideo].getOne(sprite(the currentSpriteNum).member.type) = 0 then
    p_list.addProp(#whatItem, [#format : #symbol, #comment : "Which element:", #default : #play, #range : [#play, #stop, #rewind, #fast, #pause, #slider, #sliderBar, #counter]])
  end if
  return p_list
end

on beginSprite me
  if whatItem = #slider then
    barList = [:]
    sendAllSprites(#getSliderBar, barList)
    if barList.count < 2 then
      alert "Please place the slider bar and video sprite in a lower sprite channel than the slider!"
    else
      sliderList = barList
      calcLoc()
    end if
  end if
end

on getSliderBar me, barList
  if [#quickTimeMedia, #digitalVideo].getOne(sprite(spriteNum).member.type) <> 0 then
    barList[#video] = spriteNum
  else if whatItem = #sliderBar then
    barList[#sb] = spriteNum
  end if
end

on calcLoc me
  if whatItem = #slider then
    percentage = sprite(sliderList[#video]).movieTime / float(sprite(sliderList[#video]).member.duration)
    sprite(spriteNum).loc = point(sprite(sliderList[#sb]).left + (sprite(sliderList[#sb]).width * percentage),sprite(sliderList[#sb]).locV)
  end if
end

on exitFrame me
  if whatItem = #slider then
    calcLoc()
  end if
end

on mouseUp me
  case whatItem of
    #play ,#stop, #pause :
      sendAllSprites(#doVideo, whatItem)
  end case
end

on jumpVideo me, whatPercentage
  if [#quickTimeMedia, #digitalVideo].getOne(sprite(the currentSpriteNum).member.type) <> 0 then
    sprite(spriteNum).movieTime = whatPercentage * sprite(spriteNum).member.duration
  end if
end

on mouseDown me
  case whatItem of
    #rewind, #fast:
      sendAllSprites(#doVideo, whatItem)
    #slider :
      oldRate = sprite(spriteNum).movieRate
      sprite(spriteNum).movieRate = 0
      repeat while the stillDown
        newH = the mouseH
        if newH < sprite(sliderList[#sb]).left then
          newH = sprite(sliderList[#sb]).left
        else if newH > sprite(sliderList[#sb]).right then
          newH = sprite(sliderList[#sb]).right
        end if
        sprite(spriteNum).loc = point(newH, sprite(sliderList[#sb]).locv)
        percentage = (newH - sprite(sliderList[#sb]).left) / float(sprite(sliderList[#sb]).width)
        sendAllSprites(#jumpVideo, percentage)
        updateStage
      end repeat
      sprite(spriteNum).movieRate = oldRate
  end case
end

on doVideo me, doItem
  if [#quickTimeMedia, #digitalVideo].getOne(sprite(spriteNum).member.type) <> 0 then
    case doItem of
      #play :
        sprite(spriteNum).movieRate = 1
      #stop :
        sprite(spriteNum).movieRate = 0
        sprite(spriteNum).movieTime = 0
      #rewind :
        oldRate = sprite(spriteNum).movieRate
        sprite(spriteNum).movieRate = -2
        repeat while the stillDown
          sendAllSprites(#calcLoc)
          updateStage
        end repeat
        sprite(spriteNum).movieRate = oldRate
      #fast :
        oldRate = sprite(spriteNum).movieRate
        sprite(spriteNum).movieRate = 2
        repeat while the stillDown
          sendAllSprites(#calcLoc)
          updateStage
        end repeat
        sprite(spriteNum).movieRate = oldRate
      #pause :
        sprite(spriteNum).movieRate = 0
    end case
  end if
end

on getBehaviorDescription me
  describe = "Drop this on the video sprite and all the controller buttons and slider pieces."
  describe = describe & return & "Make sure the slider bar and movie are in a lower channel than the slider." & return & "Everything else is automatic."
  return describe
end  

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail