简体   繁体   English

改变简单声道的音量

[英]Changing the volume of a simple soundchannel

I would like to change the volume of a soundchannel, instead of turning it off/ starting it from the beginning. 我想改变音频通道的音量,而不是从一开始就将其关闭/启动。

Here is a bit of my code dealing with the soundchannel, musicIcon toggles the sound. 这里有一些处理声道的代码, musicIcon切换声音。

    function musicToggle(e:TouchEvent){
    if(musicIcon.alpha != 1){
        Chn_musicLoop = musicLoop.play(0,int.MAX_VALUE);
//Instead of restarting the music, I would like to set the volume to it's max (1)
        musicIcon.alpha *= 2;
    }
    else{
        musicIcon.alpha *= .5;
        Chn_musicLoop.stop();
//Instead of stopping the music, I would like to set the volume to 0.
    }}

What code would I need to do this? 我需要用什么代码才能做到这一点?

I believe you are looking for SoundTransform class. 我相信你正在寻找SoundTransform课程。

Basically: 基本上:

var st:SoundTransform = new SoundTransform(0.5, 0);

Chn_musicLoop.soundTransform = st;

The SoundTransform parameter of 0.5 would put your "volume" at halfway. SoundTransform参数为0.5会使您的“音量”处于中途。 The parameter is a range from 0 to 1. 参数范围为0到1。

Here's a reference in AS3 from adobe: 以下是来自adobe的AS3中的参考:

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d1f.html http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d1f.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM