goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.36k stars 2.21k forks source link

Documentation on groups #982

Closed indexofrefraction closed 3 years ago

indexofrefraction commented 6 years ago

the documentation mentions groups but does not show how to define them it would be nice to get an example on groups added.

jmo84 commented 6 years ago

Apparently a group is an instance of HowlerGlobal but only one instance of it is created and there isn't any way to change the current instance to have multiple groups. Its local variable is called "Howler" but it's only assigned once and should not be confused with the module's exported property "Howler"

When a Howl is created, it uses the local Howler's _howls array. There is no apparent way to change any of this unless you modify the code yourself.

indexofrefraction commented 6 years ago

ahm.. that is a bit hard to understand...

i only understood, that i cant create some howls and assign them to a group id. to play pause fade etc. the group id instead of each individual sound...

the existing documentation sounds a bit like this would come out of the box

best, steve

On 29.06.2018, at 22:53, Jesse O notifications@github.com wrote:

Apparently a group is an instance of HowlerGlobal but only one instance of it is created and there isn't any way to change the current instance to have multiple groups. Its local variable is called "Howler" but it's only assigned once and should not be confused with the module's exported property "Howler"

When a Howl is created, it uses the local Howler's _howls array. There is no apparent way to change any of this unless you modify the code yourself.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/goldfire/howler.js/issues/982#issuecomment-401471136, or mute the thread https://github.com/notifications/unsubscribe-auth/AYq3mhZMV3ZRCgRfbVJ6dqeVLkjq0-UKks5uBpO8gaJpZM4U68Sg.

jmo84 commented 6 years ago

After searching the code, I can only guess that they're a feature that's in the works still. If you want to manipulate multiple sounds at once, you'll have to define your own arrays of Howls. Maybe the author @goldfire knows.

Boscox commented 4 years ago

For those who needs to figure out a way to achieve this, here's my simple way, you can do different sound groups by creating arrays with the variable names of the sounds like:

var sound1 = new Howl({ src: ['/folder/of/myaudio.mp3']});
var sound2 = ne..........

var ambientVolume = [ sound1, sound2, sound3, sound4 ]
var effectsVolume = [ sound5, sound6, sound7 ]
var musicVolume = [ sound8 ]

Then just simply use those array names to change the volume of each existing entities, like

for (var i = 0; i < ambientVolume.length; i++) { //For each sound in ambientVolume array
    ambientVolume[i].volume(0); //Change the volume to 0
}

Note that you don't need to specify the mainVolume, use howler.volume(number) to change every sound instead

_Also, i think that a "howler group" is really referencing the multiple instances of a very same sound (when you play the same sound multiple times, each one having a unique id to handle them)_

When you need to control that whole group then don't specify the id sound1.mute(true); otherwise being sound1.mute(true,id);

And you got it! :smile:

roschler commented 4 years ago

Shouldn't the main docs be updated to explain that groups don't work currently? The main page for the repo has 22 references to groups in the API description. A small note at the top of the main readme would save people a lot of head scratching. Fortunately I found this issue quickly when I searched for "howlerjs groups". Other people might not be so lucky.

HowlerJS is great either way.

LaurentAl commented 4 years ago

I've had exactly the same problem, because I thought I can use Howler to group different sound in groups, eg putting hello.mp3 and hi.mp3 to the group "greetings" and goodby.mp3 and bye.mp3 to the group farewell. But that's not the understanding of goups in Howler.

So I think @Boscox is right with the explanation of multiple instances!

shaftoe commented 4 years ago

I'm new to Howler and I'm also looking for a way to play/pause/stop tracks in sync, the docs explicitly mention "Control sounds individually, in groups or globally" as a feature so I'm looking for a native way to do so but as I understand from this open issue this is not possible. I'm confused 😅

lazarljubenovic commented 3 years ago

This is really confusing. Any word from maintainers on this?

goldfire commented 3 years ago

The docs have been updated at https://github.com/goldfire/howler.js#group-playback to explain what groups in howler means. Grouping separate Howls isn't a current feature, but that might be something that could be considered (but I would consider that separate from this particular issue).

lazarljubenovic commented 3 years ago

So a group is a spritesheet?

goldfire commented 3 years ago

@lazarljubenovic No:

Each new Howl() instance is also a group. You can play multiple sounds from the Howl and control them individually or as a group.

lazarljubenovic commented 3 years ago

So how do I rewirte the example from the docs having track01.mp3 and track02.mp3, instead of them being parta of a single spritesheet sound.mp3?

skymen commented 2 years ago

Any update on this? It is very unclear how to play different sounds from different audio files from a single Howl object

goldfire commented 2 years ago

Any update on this? It is very unclear how to play different sounds from different audio files from a single Howl object

I've tweaked the docs a bit more. Each Howl instance can only have one audio file, but that whole file or parts of that file as sprites can be played multiple times simultaneously and controlled as a group. You can't play different sounds from different files from a single Howl object.

skymen commented 2 years ago

Alright. I wrote a wrapper around Howler that manages Howl objects like real groups using group tags. https://github.com/skymen/howlerWrapper/tree/main

if anyone is interested in managing multiple Howl objects as a single group for muting, setting volume and playing audio, they are free to use my wrapper, make changes to it, suggest improvements, or fork it.