我如何扭转我的音量数学对我的音量滑块? [英] How do I reverse my sound volume math for my volume slider?

查看:154
本文介绍了我如何扭转我的音量数学对我的音量滑块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个视频播放器和我还挺停留在音量滑块部分。这是一个YouTube式的垂直滑块,这意味着如果滑块是在顶部位置量应该是100%,如果将滑块拖动到下方位置的声音应该是0。目前,它在做什么,我想要的正好相反:(

I'm building a video player and am kinda stuck at the volume slider part. It's a YouTube style vertical slider, meaning if the slider is in the top position volume should be 100% and if the slider is dragged to the bottom position sound should be 0. Currently it's doing the opposite of what I want :(

拖动滑块降低将会使声音变得更大,而向上拖动会降低它。

Dragging the slider down will make the sound louder, while dragging up lowers it.

下面是低于处理音量滑块我的code。

Here is my code below dealing with the volume slider.

// Sound Controller Settings ······························
   soundController = new SoundController();
   soundContrColor = soundController.colorChip;
   soundContrGray  = soundController.grayCover;
   soundContrGray.visible     = false;
   soundController.visible    = true;
   soundController.buttonMode = true;
   soundController.soundSlider.addEventListener(MouseEvent.MOUSE_DOWN, sliderDown);

// SoundController Button Mouse Events ························
   public function sliderDown(event:MouseEvent):void
   {
       soundController.soundSlider.startDrag(false, dragBounds);
       soundController.soundSlider.addEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
       soundController.soundSlider.addEventListener(MouseEvent.MOUSE_UP, sliderUp);
       soundContrGray.visible = true;
   }

   public function sliderMove(event:MouseEvent):void
       {
       soundContrGray.height = soundController.soundSlider.y;
       userVolume = Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);
       //userVolume = soundContrGray.height;
       setVolume(userVolume);

       trace("soundController.mouseY = "+soundController.soundSlider.y);
       trace("soundContrColor.height = "+Math.round(soundContrGray.height));
       trace("userVolume             = "+userVolume+"\r");

       event.updateAfterEvent();
       }

    public function sliderUp(event:MouseEvent):void
    {
        lastVolPoint = soundContrGray.height;
        setVolume(userVolume);
        event.updateAfterEvent();

        soundController.soundSlider.stopDrag();
        soundController.soundSlider.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
        soundController.soundSlider.removeEventListener(MouseEvent.MOUSE_UP, sliderUp);
    }

[微量]当我一路拖到顶部:

[TRACES] when I drag all the way to the top:

soundController.mouseY = 6
soundContrGray.height  = 6
userVolume             = 0

[微量]当我拖累一路走低:

[TRACES] when I drag all the way down:

soundController.mouseY = 56
soundContrGray.height  = 56
userVolume             = 30

我相信这是问题所在:

I believe this is where the problem lies:

userVolume = Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);

( - 4)。是一个偏移值,所以当你拖动它都将其关闭的方式,它的0,而不是4
我需要以某种方式扭转这一点,所以在上面的痕迹会掉...下去会使userVolume = 4和上升将使其30。

The (-4) is an offset value so when you drag it all the way to turn it off, it's 0 and not 4.
I need to reverse this somehow, so the traces above will swap... going down will make userVolume = 4 and going up will make it 30.

在此先感谢任何人,需要看看这个! :)

Thanks in advance for anyone that takes a look at this one! :)

推荐答案

我一定是失去了一些东西,因为它不能被这个简单的,可以吗?

I must be missing something because it can't be this simple, can it?

userVolume = 30-Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);

这篇关于我如何扭转我的音量数学对我的音量滑块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆