Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature
There is currently no way to play WebRTC audio in Howler. This PR lets you provide a MediaStream as a source, since you can create a MediaStream object from WebRTC audio tracks.
If someone wanted to play WebRTC audio in the current state of the library, they would have implement it separately from Howler, which means re-implementing most of Howler's features, such as spatial audio, etc..., hence the need for this in the core library.
Related Issues
Fixes #581 and fixes #1314
Solution
Instead of making a new class for streams, this PR lets you provide a MediaStream as a source for a
Howl
object. If aHowl
object is using a MediaStream as a source, then it will:If using Web audio:
bufferSource
with the result ofcreateMediaStreamSource
, instead of using an actual buffer sourceIf using HTML5 audio:
srcObject
I'm not 100% happy with this solution, as the API feels wrong, so I'm leaving this PR as a draft. Ideally there would be a new class for streams since they are more limited than sounds, and a buffered stream class which can be paused/seeked, but this PR is more of a starting point.
Testing
Howl
object with the MediaStream as thesrc
(or part of thesrc
array)play
it,pause
it, etc...Breaking Changes
No breaking changes as far as I know
Other stuff
The build script didn't work on my system (there were some errors with
sed
), so I replaced the build script with esbuild. I didn't include this in the PR, and you can find it in the master branch of our repository, but I think it would be better if #1518 got merged (please!)