简体   繁体   English

使用SoundJs更改全局音量

[英]Change global volumen with SoundJs

I'm creating an application in HTML5 using CreateJS. 我正在使用CreateJS在HTML5中创建一个应用程序。 By starting with the part of sounds, using SoundJS, I have seen that has many limitations. 通过使用SoundJS从声音的一部分开始,我已经看到了很多限制。 The createjs.Sound object has the method of play() and stop() . createjs.Sound对象具有play()stop() But play() executes only a specific sound and stop() for all the sounds of the stage. 但是play()仅执行特定的声音,而stop()对于舞台上的所有声音。

I wanted to know is if there is any way to define a global volume for all sounds and be able to go up or down at any time, although it sounds one or ten at a time. 我想知道是否有任何方法可以定义所有声音的全局音量,并且可以随时上调或下调,尽管一次听起来只有一声或十声。

I had initially thought the option to create a global variable and use it as a parameter of volume when playing a sound. 最初,我曾想过可以创建一个全局变量,然后在播放声音时将其用作音量参数的选项。 My problem is that I use several classes in different files, and they all have independent sounds. 我的问题是我在不同的文件中使用了几个类,并且它们都有独立的声音。 They would need that variable out comprehensive beyond the classes and methods. 他们将需要超出类和方法之外的全面变量。 I'm programming with typescript. 我正在用打字稿编程。

I can't use the master volumen for my problem. 我无法使用master volumen解决我的问题。 In the documentation, I can find: createjs.Sound.volume = 0.5; 在文档中,我可以找到: createjs.Sound.volume = 0.5;

But it changes all the global volume. 但这改变了所有的全球销量。 I need to separe the music and the sound effects in two different volume options. 我需要将音乐和声音效果分成两个不同的音量选项。

There is no way to do audio "groups" for volume, playback, or panning at this time. 目前无法对音量,播放或声像进行音频“分组”。 You would have to store off instances you want to control into arrays/groups, and then iterate those groups to set those values on each instance. 您必须将要控制的实例存储到阵列/组中,然后迭代这些组以在每个实例上设置这些值。

This could be a handy feature, so feel free to log an issue on GitHub . 这可能是一个方便的功能,请随时在GitHub上记录问题

I make my own solution. 我自己解决。 I created two global boolean variables. 我创建了两个全局布尔变量。 One for the music and the other for the sounds. 一种用于音乐,另一种用于声音。 When I want to reproduce a new sound, check if this variable is set to True. 当我想重现新的声音时,请检查此变量是否设置为True。

It works fine for me. 这对我来说可以。

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

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