Comments (8)
@goldfire "The play method already returns an ID"
How is that retrieved?
I am creating a looping sound, whose volume fades on scroll (based on a percentage of scrollTop and the distance from the "target"). However, it seems that each time I set the volume, it creates a new instance of the sound. I need to target just the existing instance and adjust only that.
from howler.js.
Well this gets a little tricky since the intended use is that you can play multiple instances of the same sound at the same time. However, this is tracked internally in sound._audioNode[x].paused
. So, if you track the soundId of a specific playback, I could create a method that checks if that specific sound is playing or not. I could also make it so that if you don't pass a soundId, it'll loop through all audio nodes for that Howl object and return true if any of them are currently playing. Any thoughts on that?
from howler.js.
OK, I thought that might be the case. At the moment my design is an
entity system, and any entity that emits sound has a Sound component
with various properties (presence for a sound that plays at the entity's
position, various collision sounds, random creature sounds, etc.) I was
creating a separate Howl for each of these, and assigning that to the
entity so it could control its own audio.
This begs a more fundamental documentation/design question: should each
Howl allocate itself from a singleton pool keyed on URL? Then, if I
create various unique Howls with the same urls property, their creation
would simply be no-op and return the existing instance? play() could
then return the ID which I could then pass to isPlaying() to determine
if that instance is playing, or isPlaying() with no arguments could
check if any instance of the given Howl is playing?
This fleshes the subject matter of the issue out a bit, but it wasn't
obvious to me that one Howl was meant to be shared among many sound
instances. A reasonable compromise might be to make play() return an
instance ID if it doesn't already, then offer a method to determine if
the specified ID is playing.
from howler.js.
The play method already returns an ID, and you can use that ID to control pretty much everything about the sound. The reason that each Howl is designed to be able to play multiple instances of the same sound is becuase you wouldn't want to create many new Howl objects if you were for example shooting a gun in a game rapid-fire.
The play method accepts a callback as the 2nd parameter, and returns the ID in the callback (it has to be in a callback because the play method has to asynchronously wait for a sound to be ready to play before actually beginning playback).
from howler.js.
Hmmm... I wonder if using these instance IDs would offer a way to work around the IE9 problems I was running into? It doesn't look like you can use the instance ID to play that same instance more than once, but if that worked... then for IE9, in my code I could store the IDs and rotate through say 3 instances for a given sound. (That would be enough for my use case to keep clipping to a tolerable level.)
Background: the issues in IE9 seem to be related to the creation and destruction of too many audio instances, which IE9 can't handle without eventually dropping audio clips. So maybe the instance IDs could make it possible to only create a finite number of instances and then re-use them by rotating through them. (This is how I'm having to support IE9 outside of howler, and is the way I was doing it before I started using howler.)
But then if the instances were destroyed by howler, then they wouldn't be playable any more... (Is the pool of audio nodes/instances one big pool that all howls/sounds share together, or are there separate pools specific to each howl/sound?) So maybe there would need to be a way to set the size of the pool so that it would be big enough to hold the required (finite) number of instances so that none of them would get destroyed? If that makes sense?
Just thinking out loud here, this might be a can of worms you wouldn't want to open.
from howler.js.
Got it. Is there a function to determine if a sound with a given ID is
playing? I didn't see one but may have missed it.
Thanks.
from howler.js.
Sorry, somehow I never noticed there was a new comment here. You can get the ID like this:
sound.play(function(soundId){
// do what you want with soundId
});
from howler.js.
Hi gavinbeck , 5 years later, did you manage to solve this? how did you prevent the creation of a new instance? I am facing the same problem. Many thanks
I am creating a looping sound, whose volume fades on scroll (based on a percentage of scrollTop and the distance from the "target"). However, it seems that each time I set the volume, it creates a new instance of the sound. I need to target just the existing instance and adjust only that.
from howler.js.
Related Issues (20)
- Max stack reached when setting volume every frame and context not running yet
- What is the most optimized way to dynamically loop between two timestamps of an audio track ?
- Does Howler supports IOS or Android??
- Problem with seek when streaming large audio
- iOS: HTML5 Audio pool exhausted, returning potentially locked audio object. HOT 1
- Writing our own code to track elapsed time is complicated. Especially when dealing with pause/play controls HOT 1
- Mp3 files don't play on latest Opera (version 100) HOT 6
- After going to sleep by pressing the ipad top button, there is no sound when waking up HOT 2
- Playback of static audio files waits until whole file loaded, ignores ranges on Firefox 115 with html5 HOT 2
- Tone is not stopping if I put a beep tone (duration less then 1 sec) HOT 1
- Howler.mute(false) doesn't work sometimes after the document lost focus or if the screen is locked and then unlocked IOS Chrome/Safari
- Audio Context cannot be created before user gesture
- Cuts out when playing sound over itself multiple times in Chrome
- Howler doesnt start on iOS if the interaction is a slide
- Support for accessing the HTMLAudioElement when using html5 player HOT 1
- I need to use howler to play dsd audio
- Howler sounds dont play if browser tab is minimized in howl - 'loading' state
- support for MPD streams
- Bug with playing short sounds since v2.2.2
- Audio visualizer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from howler.js.