5 Replies Latest reply on Oct 5, 2006 3:17 PM by Mark_A_Boyd

    WMV Volume Control

    PepperKev
      I need some help with code to controlling the volume of a WMV sprite in Director.

      I've already scoured the forum for this. I found one thread (But I can't find it now!) where Rob Dillon posted up a file called "Video Volume Control.dir" which I downloaded and discovered that it is meant for Quicktime.

      Nevertheless, I trucked on with it, and I'm wondering if I can actually get this to work or if there is a different approach to controlling the volume of a WMV.

      On my first attempt, the entire range of volume was cramped into the bottom 10% (or so) of the slider's range. Once you reached top volume, you could continue moving the slider, but it didn't affect anything.

      On my second attempt, and the slider moves but doesn't affect the volume at all.

      So here's the code I used; it's mostly from Rob Dillon's file but I tweaked it here and there to address the debug messages that came up.
      Video is sprite 7,
      The slider is called sliderUp and is sprite 11, down version is called sliderDown
      The constraining sprite is called horizontal and is on sprite 10.
        • 1. Re: WMV Volume Control
          Level 7
          Windows media files have a volume range of 0 through 7, while QT has a
          range of 0 through 255. To use the code that you have with WMV files
          just change the line:

          sprite(7).volume = integer((sprite(thisSprite).locH -
          leftEdge)/float(constraintWidth) * 255)

          to be:
          sprite(7).volume = integer((sprite(thisSprite).locH -
          leftEdge)/float(constraintWidth) * 7)

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/
          • 2. Re: WMV Volume Control
            PepperKev Level 1
            Thanks Rob!
            I made that change, I also adjusted the line "sprite(7).volume = 123" further up.

            It still isn't changing the volume of the sprite though.

            I think the error is in my property list. Any suggestions to fix that?

            The line you referred to was originally "sprite(thisVideoSprite).volume" But I changed it to refer directly to the sprite because I couldn't figure out the syntax for the item in the property list. I tried multiple configurations, but I'm a little weak on property lists, so I kinda gave up on it :-)

            Any chance you could tell me the correct syntax to make the thisVideoSprite property point to sprite 7?
            Here's the original without my various hack attempts to make it work:
            #thisVideoSprite:[#comment:"sprite channel of video sprite:",#format:#integer],\

            I appreciate your help!
            • 3. Re: WMV Volume Control
              Level 7
              Throw this behavior on to the volume slider button. A property window
              should open, then you can set the sprite numbers for the constrainer
              line and the video. Be sure that you are using sprite channel numbers
              and not cast member numbers.

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

              -- horizontal volume control

              -- attach this behavior to the slider sprite, and identify a second
              sprite to act as the constraining control for the distance
              -- use a toolbox sprite for this as the location point will be in the
              correct place, this constrainer can be a line with no width if you like,\
              or it can be hidden beneath another sprite, you can use any number
              of additional window dressing sprites to make the control\
              look good\
              if you use a bitmap as the constrainer, as in this example, set the
              constrainer sprite's member's reg point to the right end of the sprite\
              this behavior will position the the slider sprite at the zero point
              at the first use, so alignment isn't critical, the position of the
              slider will\
              be kept in a global variable and so the slider's location will be
              updated as it's used

              -- the math that does the work: the constrainer line represents the
              full variance of the volume: 0 to 7 for WMV files, the left end is 0
              --and the right end is 7. The scrolling button is constrained to this
              line. At any time you can get the horizontal location of this
              --button, the sprite's locH. the left end and the length of the line are
              known. Since the position of a sprite on the stage is
              --measured from the top edge and the left edge, we can use the distance
              from the left edge of the stage to the left end of the
              --constraining line as a constant.
              --
              --So if we take the locH of the scrolling button minus the locH of the
              constraining line, we have a number that gives us a distance
              --from the left edge of the stage. If we divide that number by the total
              distance, the length of the constraining line, then we end up
              --with a decimal number. This decimal number will be between 0 and 1.
              That's a ratio, the ratio of the location of the scrolling button
              --to the total length of the scrolling distance. Now multiply that
              number by the largest value that the result can have, in this case, 7,
              --and we have the value that we want to use.

              property thisSprite -- the volume slider
              property constrainersprite -- the line the slider moves on
              property customCursor -- a cursor to use for this button
              property thisVideoSprite -- the sound channel to control
              property animateMe
              property offSetH -- the distance from the center of the slider sprite to
              the mouse click location
              property leftEdge -- the left end of the constraining sprite
              property constraintWidth -- the width of the constraining sprite
              property upButton -- the member to show the normal condition of the
              scroll button
              property downButton -- the member to show the clicked condition of the
              scroll button


              on getPropertyDescriptionList
              myPropList = [\
              #constrainerSprite:[#comment:"enter the sprite number for the
              constraining line:",\
              #format:#integer,#default:5],\
              #customCursor:[#comment:"pick a
              cursor:",#format:#cursor,#default:280],\
              #thisVideoSprite:[#comment:"enter the sprite channel number for the
              QT sprite:",#format:#integer],\
              #downButton:[#comment:"select the down button
              image:",#format:#bitmap,\
              #default:""]\
              ]
              return myPropList
              end

              ---

              on beginSprite me
              thisSprite = me.spriteNum
              upButton = sprite(thisSprite).member.name
              constraintWidth = sprite(constrainerSprite).width
              sprite(thisSprite).cursor = customCursor
              animateMe = 0
              leftEdge = sprite(constrainerSprite).left
              sprite(thisSprite).locH = (constraintWidth/2 + leftEdge)
              sprite(thisVideoSprite).volume = 3
              -- this will set the initial volume for the video to half way.
              sprite(thisVideoSprite).movieRate = 1
              end


              on endsprite me
              sprite(thisSprite).cursor = 0
              end

              -------

              on mouseDown me
              animateMe = 1
              offSetH = (sprite(thisSprite).locH - the mouseH)
              sprite(thisSprite).member = downButton
              end


              on mouseUp me
              animateMe = 0
              volumePosition = sprite(thisSprite).locH
              sprite(thisSprite).member = upButton
              end

              on mouseUpOutside me
              animateMe = 0
              volumePosition = sprite(thisSprite).locH
              sprite(thisSprite).member = upButton
              end

              --------
              on prepareFrame me
              if animateMe = 1 then
              sprite(thisSprite).locH = constrainH(constrainerSprite, the mouseH +
              offSetH)
              sprite(thisVideoSprite).volume = integer((sprite(thisSprite).locH -
              leftEdge)/float(constraintWidth) * 7)
              end if
              end

              ----------

              --
              Rob
              _______
              Rob Dillon
              Adobe Community Expert
              http://www.ddg-designs.com
              412-243-9119

              http://www.macromedia.com/software/trial/
              • 4. Re: WMV Volume Control
                PepperKev Level 1
                Thank you!
                Okay I gave it a go.

                I got the properties box but no option to set the sprite number for the video, just the constraining line and the cursor. Of course I was still getting the error "Property not found" in reference to thisVideoSprite

                Anyway, i went out on a limb and added #default:7 to the thisVideoSprite line in the properties list, and lo and behold, it moved on to the next error, which is.... "operator expected" after the ] and before "return myPropList"

                What the heck am I doing wrong here??? aaah!
                • 5. Re: WMV Volume Control
                  Mark_A_Boyd
                  You're ignoring the word-wrap.

                  I'll log into the Web Forum and post Rob's script in that special way just for forum users.

                  This should look OK in newsreaders, too.