
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
web-audio-player
Advanced tools
A simplified cross-browser WebAudio wrapper with a narrow API. This repo also attempts to report and solve some "WebAudio Gotchas" for getting WebAudio working on mobile. It targets new browsers and devices, and does not attempt to provide a non-WebAudio fallback.
The main use case for this is to support WebAudio features (such as reverb and frequency analysis) across desktop and mobile browsers.
Currently (as of Nov 2015), on recent versions of Safari and Android Chrome, you can only take advantage of these features by buffering and decoding the entire audio file (rather than streaming it).[1][2]
This module provides a consistent API whether you are using a media element (Chrome/FF) or buffer (other browsers) as the audio source.
http://jam3.github.io/web-audio-player/
The demo uses web-audio-analyser and analyser-frequency-average.
The audio streams and auto-plays on desktop. On mobile, the file is buffered, then decoded, then we wait for user to initiate playback.
You can use detect-media-element-source to approximately feature detect whether createMediaElementSource
will work or not, but you may be better off just using user agent strings or defaulting to a specific behaviour for all mobile browsers.
Tested with the following browsers/devices.
Meant to be used with Browserify or Webpack.
npm install web-audio-player --save
A simple example for Chrome/FF, which does not attempt to solve some of the mobile challenges.
var createPlayer = require('web-audio-player')
var audio = createPlayer('assets/audio.mp3')
audio.on('load', () => {
console.log('Audio loaded...')
// start playing audio file
audio.play()
// and connect your node somewhere, such as
// the AudioContext output so the user can hear it!
audio.node.connect(audio.context.destination)
})
audio.on('ended', () => {
console.log('Audio ended...')
})
For a complete mobile/desktop demo, see demo/index.js. See Gotchas for more details.
player = webAudioPlayer(src, [opt])
Creates a generic audio player interface from the given src
file path or array of sources. The src
elements can be any of the following:
'audio/foo.mp3'
, where the mime-type is guessed from the extension{ src, type }
which allows you to specify an exact mime-type and codec<source>
DOM elementIf opt.buffer
is true, the audio node is created from a buffer source (not streamed). Otherwise, it is created from a media element source (streamed). The two have different implications.
Full list of options:
volume
(Number) volume to play atbuffer
(Boolean) whether to use a Buffer source, default falseloop
(Boolean) whether to loop the playback, default falseloopStart
(Number) point to restart loop in seconds, default 0loopEnd
(Number) point to end loop and restart in seconds, defaults to end of the audio buffercrossOrigin
(String) for media element sources; optional cross origin flagcontext
(AudioContext) an audio context to use, defaults to a new context. You should re-use contexts, and also consider ios-safe-audio-contextelement
(Audio|HTMLAudioElement) an optional element to use, defaults to creating a new one. Only applicable when buffer
is false.autoResume
(Boolean) whether to resume the AudioContext during a call to play()
if it's state is suspended; default true. This exists to fix a bug with Safari 9+ where the context defaults to being suspended.When a MediaElement is used as the source, other options will be passed to simple-media-element.
:warning: For accurate
loopStart
andloopEnd
results, you should use a buffer source. MediaElement sources fall back to using a requestAnimationFrame timer, which is less robust, especially when the tab is out of view.
player.play()
Plays the audio, resuming it from a paused state.
player.pause()
Pauses the audio.
player.stop()
Stops the audio, settings its current time back to zero and triggering an 'end'
event.
The next time play()
is called, the track will start from the beginning.
player.context
(read-only)The AudioContext
being used for this player. You should re-use audio contexts where possible.
player.node
(read-only)The AudioNode
for this WebAudio player.
This will be a GainNode
that wraps the MediaElementAudioSourceNode or currently playing AudioBufferSourceNode.
player.element
(read-only)If buffer
is false (the source is a media element), this will be the HTMLAudioElement
or Audio
object that is driving the audio.
If the source is a buffer, this will be undefined.
player.buffer
(read-only)If we are using a buffer source, this will hold the decoded AudioBuffer instance from the audio file. This will be undefined until the 'loaded'
event is triggered.
If the source is a media element, this will be undefined.
player.duration
(read-only)The duration of the audio track in seconds. This will most likely only return a meaningful value after the 'load'
event.
player.playing
(read-only)A read-only boolean to determine whether the audio node is currently playing.
player.volume
A getter/setter for the player.node.gain
value, which allows you to adjust the volume during playback.
player.on('load', fn)
Called when the player has loaded, and the audio can be played. With a media element, this is after 'canplay'
. With a buffer source, this is after the audio has been decoded.
player.on('end', fn)
If the audio is not looping, this is called when the audio playback ends.
This is also triggered when the stop()
method is called.
player.on('error', fn)
Called with (err)
parameters when there was an error loading, buffering or decoding the audio.
player.on('progress', fn)
If buffer: true
, this will be called on the progress events of the XMLHttpRequest for the audio file (if the browser supports it). The parameters will be (percentage, totalBytes)
.
This is not called with a media element source.
player.on('decoding', fn)
If buffer: true
, this will be called after the XMLHttpRequest, and before decodeAudioData
starts. This alows you to provide an update to your user as the audio loads.
This is not called with a media element source.
Some new features may be added to this module, such as:
currentTime
propertyplay(N)
featurePlease open an issue or PR if you wish to discuss a new feature.
There are currently a lot of challenges with cross-platform WebAudio playback. This is likely to change soon as vendors continue fixing bugs.
buffer
source that doesn't loop, the audio file will only be playable once! You will need to create another buffer source to re-play it. This module handles this for you.createMediaElementSource
will need to download and decode the entire audio file before it can be played.
decodeAudioData
(this is in discussion)sampleRate
causing playback to be distorted sometimes
sampleRate
buffer
and "Add to Home Screen", you can auto-play music without the need for user gesture. This is not the case with iOS "Add to Home Screen."<audio>
tag's load()
method needs to be called; however, this just causes a second (superfluous) request for the file in most other browsers.audioElement.load()
is called immediately after audioElement.play()
, no sound will occur until the next play()
is called.'touchend'
that isn't part of a drag action. One solution is to attempt audio playback only when the distance and time since 'touchstart'
is less than a certain threshold; see tap-event.crossOrigin: 'Anonymous'
createMediaElementSource()
works as expectedsampleRate
distortion bug in iOS6+<audio>
abstraction1.1.0
play()
and pause()
now works the same in both modesstop()
added to both modesvolume
control addedplaying
getter added1.0.6
MIT, see LICENSE.md for details.
FAQs
a cross-browser WebAudio player
The npm package web-audio-player receives a total of 72 weekly downloads. As such, web-audio-player popularity was classified as not popular.
We found that web-audio-player demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.