![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
audio-manager
Advanced tools
Play sounds using Web Audio, fallback on HTML5 Audio.
AudioManager
is specifically designed to works for games that have a big
quantity of audio assets. Loading and unloading is made easy and transparent.
// initialisation
var audioManager = new AudioManager(channelIds);
audioManager.init();
audioManager.setVolume(channelId, volume);
// play simple sound
audioManager.playSound(channelId, soundId, volume, panoramic, pitch);
// sound group
audioManager.createSoundGroups(soundGroupDefs, channelId);
audioManager.createSoundGroup(soundGroupId, soundGroupDef, muted);
audioManager.playSoundGroup(channelId, groupId, volume, panoramic, pitch);
// loop
audioManager.playLoopSound(channelId, soundId, volume);
audioManager.stopLoopSound(channelId);
audioManager.stopAllLoopSounds();
// release memory
audioManager.release();
Pass the list of channels to the constructor as an array of strings.
var channels = ['music', 'sfx', 'ui'];
var audioManager = new AudioManager(channels);
audioManager.settings.audioPath = 'assets/audio/';
To work correctly on iOS, this must be called on an user interaction e.g. user pressing a button. (C.f. this page to understand how this work.)
gameStartButton.on('tap', function () {
audioManager.init();
});
By default, channel volume is set to 0 and channel is muted. No sounds will play until channel volume is set.
var volume = 1.0; // volume is a float in range ]0..1]
audioManager.setVolume('ui', volume);
Create a sound and playing it in a channel. Sound is created and loaded automatically.
var fileName = 'laser1';
audioManager.playSound('sfx', fileName);
// volume and panoramic can be set optionally
var volume = 0.7; // volume is a float in range ]0..1]
var panoramic = 0.9; // panoramic is a float in range [-1..1], 0 is the center
audioManager.playSound('sfx', fileName, volume, panoramic);
Sounds creation and preloading can be forced.
audioManager.createSound(fileName).load();
Alternatively, sounds can be played outside channels.
var sound = audioManager.createSound(fileName);
sound.play(volume, panoramic, pitch); // all parameters are optional.
An onEnd
callback function can be set to be triggered everytime the playback ends.
Set it back to null
to remove it.
sound.onEnd = function () {
console.log('sound playback ended');
sound.onEnd = null;
};
This feature is only available with WebAudio.
var pitch = -7.0; // in semi-tone
sound.setPitch(pitch);
The pitch can be set at play.
audioManager.playSound('ui', fileName, volume, panoramic, pitch);
While a sound is playing, the pitch can be changed dynamically
var portamento = 3.0;
sound.setPitch(pitch, portamento);
A sound group is a collection of sounds that will play alternatively in a
round-robin pattern on each play
call.
var soundGroupDef = {
id: ['punch1', 'punch2'],
vol: [1.0, 0.8],
pitch: [0.0]
};
audioManager.createSoundGroups('punch', soundGroupDef);
var volume = 0.8; // volume is a float in range ]0..1]
var panoramic = 0.3; // panoramic is a float in range [-1..1], 0 is the center
var pitch = 3.0; // in semi-tone
audioManager.playSoundGroup('sfx', 'punch', volume, panoramic, pitch);
You can create several sound groups in one function call
var soundGroupDefs = {
groupId1: { id: ['sound1', 'sound2'], vol: [1.0, 0.8], pitch: [0.0] },
groupId2: { ... },
...
};
audioManager.createSoundGroups(soundGroupDefs, 'sfx');
Only one loop can play per channel. Playing a new looped sound in the same channel will stop current playing sound before starting new one.
var volume = 1.0; // volume is a float in range ]0..1]
var fileName = 'bgm1';
audioManager.playLoopSound('music', fileName, volume);
audioManager.stopLoopSound('music'); // stop looped sound in channel 'music'
audioManager.stopAllLoopSounds(); // stop all looped sounds in all channel
How looped sound fades and mixes can be set by modifying audioManager settings:
audioManager.settings.defaultFade = 3; // value in second
audioManager.settings.crossFade = true; // default is false
audioManager.release();
audioManager.settings.getFileUri
can be overriden if you want more control on how to
resolve files uri from sound id. The function have one on the following synchronous or
asynchronous profile:
function getFileUriSync(audioPath, id) {
var uri;
// ...
return uri;
}
function getFileUriAsync(audioPath, id, callback) {
var uri;
var error = null;
// ...
return callback(error, uri);
}
For instance, here's how you can add wizAssets to cache files on disc in a PhoneGap application:
if (window.wizAssets) {
audioManager.settings.getFileUri = function wizAssetsGetUri(audioPath, id, cb) {
window.wizAssets.downloadFile(audioPath + id + '.mp3', 'audio/' + id + '.mp3',
function onSuccess(uri) {
cb(null, uri)
},
cb // onFail callback
);
}
}
FAQs
Play sounds using Web Audio, fallback to HTML5 Audio
The npm package audio-manager receives a total of 7 weekly downloads. As such, audio-manager popularity was classified as not popular.
We found that audio-manager demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.