Giter Site home page Giter Site logo

pixijs / sound Goto Github PK

View Code? Open in Web Editor NEW
376.0 15.0 66.0 5.02 MB

WebAudio API playback library, with filters. Modern audio playback for modern browsers.

Home Page: https://pixijs.io/sound/examples/

License: MIT License

TypeScript 100.00%
webaudio-api webaudio pixijs javascript-library pixi webaudio-api-playback

sound's Introduction

PixiJS Sound

WebAudio API playback library, with filters. Modern audio playback for modern browsers.

Node.js CI npm version

Features

  • Pausing and resuming
  • Independent volume control
  • Support blocking or layered sounds (multiple instances)
  • Support for PIXI.Assets system
  • Dynamic filters:
    • ReverbFilter
    • DistortionFilter
    • EqualizerFilter
    • StereoFilter
    • TelephoneFilter

Known Compatibility

  • Chrome 58+
  • Firefox 52+
  • Safari 11+
  • iOS 11+

Usage

Installation is available by NPM:

npm i @pixi/sound --save

To import into your project, for instance, when using Webpack, Parcel, Rollup, or another bundler:

import { sound } from '@pixi/sound';

sound.add('my-sound', 'path/to/file.mp3');
sound.play('my-sound');

Browser Usage

If you're using a <script> element to import @pixi/sound into your project, then the SoundLibrary object is PIXI.sound global.

<!-- PixiJS must be imported before @pixi/sound -->
<script src="https://unpkg.com/pixi.js/dist/browser/pixi.min.js"></script>

<!-- found here, if not using CDN "./node_modules/@pixi/sound/dist/pixi-sound.js" -->
<script src="https://unpkg.com/@pixi/sound/dist/pixi-sound.js"></script>

<script>
    PIXI.sound.add('my-sound', 'path/to/file.mp3');
    PIXI.sound.play('my-sound');
</script>

Versions Compatibility

PixiJS PixiJS Sound
v5.x - v6.x v4.x
v7.x v5.x
v8.x v6.x

Resources

License

MIT License.

sound's People

Contributors

andrewstart avatar bigtimebuddy avatar connorjclark avatar cursedcoder avatar dependabot[bot] avatar ericente avatar gorisanson avatar hendrysadrak avatar korilakkuma avatar miltoncandelero avatar patrick-hammond avatar qtiki avatar telime avatar windyrain avatar yueyuzhao avatar yuzeyang avatar zoadt avatar zprodev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sound's Issues

fs dependency no longer available on npm

I was importing pixi-sound and got the error message:

ERROR in ./~/pixi-sound/lib/Sound.js
Module not found: Error: Can't resolve 'fs' in '/Users/daniel/Sites/osweb/node_modules/pixi-sound/lib'
 @ ./~/pixi-sound/lib/Sound.js 333:17-30
 @ ./~/pixi-sound/lib/deprecations.js
 @ ./~/pixi-sound/lib/index.js

Apparently, the Sound module tries to use the fs (filesystem?) module to read a file from disk, but the fs module is no longer available on npm, according to the readme file of fs:

# Security holding package

This package name is not currently in use, but was formerly occupied
by another package. To avoid malicious use, npm is hanging on to the
package name, but loosely, and we'll probably give it to you if you
want it.

You may adopt this package by contacting [email protected] and
requesting the name.

Additionally, the fs module is not listed as a dependency on pixi-sound's npm page.

What's the best approach here? Replace fs with a module with similar functionality?

Now, need to use setTargetAtTime/setValueAtTime

see https://www.chromestatus.com/features/5287995770929152

We can't set 'value' directly any more.
e.g

current

gainNode.gain.value = 0.6

change to

gainNode.gain.setValueAtTime(0.6, context.currentTime);

But some old browsers (e.g. some android webviews) don't support setTargetAtTime/setValueAtTime.

So , we need to check it .

In my own sound lib , I use this :

    Sound.setAudioParamValue = function(nodeParam, value, context) {
        if (nodeParam.setValueAtTime) {
            nodeParam.setValueAtTime(value, context.currentTime);
        } else {
            nodeParam.value = value;
        }
    };

[feature] Sequence playing

Allow the playing of audio files in series to string together a bunch of audio files together.

PIXI.sound.playSeries(['foo', 'bar'], () => {
    console.log('complete!');
});

Unhandled promise rejection in decodeAudioData call

Hello.

AudioContext.decodeAudioData support newer promise-based syntax. But the library is used old callbacks syntax.

As a result, in situations when data cannot be decoded, an unhandled promise rejection error occurs.
Maybe need to add catch block to decodeAudioData call? Or completely switch to the new syntax.
What do you think?

https://github.com/pixijs/pixi-sound/blob/7d80d7e8916a41b790ac360cb3fbea137bb2b6de/src/webaudio/WebAudioContext.ts#L337

Error with library fs

Hello, I'm getting this error and I can't start my application,

ERROR in ./node_modules/pixi-sound/lib/Sound.js Module not found: Error: Can't resolve 'fs' in '/Users/davidh/Documents/Jobs/XXXX/node_modules/pixi-sound/lib' resolve 'fs' in '/Users/davidh/Documents/Jobs/XXXX/node_modules/pixi-sound/lib' Parsed request is a module using description file: /Users/davidh/Documents/Jobs/XXXX/node_modules/pixi-sound/package.json (relative path: ./lib) Field 'browser' doesn't contain a valid alias configuration

I tried installing fs and doesn't work, I added this configuration to the webpack and continue without working

target: 'node' node: { fs: 'empty' }

Questions about filters and fading

I would like to ask about 2 things:

  1. Is there a way to play the same sound with different filters at the same time?
    e.g. Panning effect left-to-right for 5 sounds played 100 ms after each other.

  2. From what I understand, the library supported fadeIn/fadeOut features. Were they removed?

Thank you.

Doesn't work on ios safari

In devtools: [Error] SyntaxError: Cannot declare a parameter named 'panning' as it shadows the name of a strict mode function.

Issue creating sound from HTMLAudioElement

I have an audio source that I'm having to embed in the html page, as a data url. I'm then getting the element, by its ID. And getting a HTMLAudioElement back. I'm then trying to create the pixi sound using the source option, but getting an error on creation.

` var sound = document.getElementById("assets/sounds/bgMusic.mp3");

if (sound instanceof HTMLAudioElement)
    console.log ("ok");

this.gameLoop = PIXI.sound.Sound.from({
    source: sound,
    autoPlay: true,
    loop: true
});`

'
Uncaught (in promise) TypeError: Failed to execute 'decodeAudioData' on 'BaseAudioContext': parameter 1 is not of type 'ArrayBuffer'.
at n.decode (pixi-sound.js:9)
at e._decode (pixi-sound.js:9)
at e.load (pixi-sound.js:9)
at e._preload (pixi-sound.js:9)
at new e (pixi-sound.js:9)
at Function.e.from (pixi-sound.js:9)
at GameData.loadSounds (GameData.js:158)
at GameData.loadParticles (GameData.js:36)
at startGame (app.js:80)
at AssetLoader.onAssetsLoaded [as callback] (app.js:64)

'
audio id="assets/sounds/bgMusic.mp3" src="data:image/mp3;base64,SUQzAwAAAAAAeFRYWFgAAAAmAAAAU29mdHdhcmUAQWRvYmUgQXVkaXRpb24gQ1M2IChXaW5kb3dzKVRZRVIAAAAaAAAAMjAxMy0wMy0xNVQyMToxODoxMyswMTowMFREUkMAAAAaAAAAMjAxMy0wMy0xNVQyMToxODoxMyswMTowMP/7kMQAAAAAAAAAAAAAAAAAAAAAAEluZm8AAAAPAAAABAAACCgAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAgICAgICAgICAgICAgICAgICAgICAgICAgMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD/////////////////////////////////AAAAOUxBTUUzLjk5cgHNAAAAAAAAAAAUgCQFzEIAAIAAAAgoeW149gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/7kMQAABIt6RUsGHPCy8Gi4raAAAACAqr6wh68FiMQpb+EollP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qqqqqqqqqqqqqqqqqqqqqqqqqg==" / >
`

The sound plays properly if I add controls to the audio tag.

Add AMD support

It is more requirement rather than a feature request.

Lets take a look at pixi-plugin-example. As you can see, at this lines plugin have to be attached to global PIXI variable as well as to be exported as a standalone module with its dependencies. At some point, this repo\plugin brokes one of the main approaches of how pixi.js is functioning.

Currently, there are a lot of module loaders that are built on top of AMD. I'm one of that users. Solution for me could be:

  • Remove module loading (definition, dependency management, etc.) from the whole project - totally not what I'll do.
  • Replace pixi-sound with some other sound library that is not part of pixi-* package.
  • Add AMD support to this plugin ASAP.

PIXI's Loader is not loading sounds as ArrayBuffer, unable to decode

As reported by @FunkyPaul on pixi.js Slack...

This works fine.

let soundsMap = {
    "game_start": "assets/sounds/game_start.ogg",
    "spin_ready": "assets/sounds/spin_ready.ogg",
    "spin_loop": "assets/sounds/spin_loop.ogg",
    "spin_stop": "assets/sounds/spin_stop.ogg",
    "win_loop": "assets/sounds/win_loop.ogg",
    "game_end": "assets/sounds/game_end.ogg",
    "spin_start": "assets/sounds/spin_start.ogg",
    "spin_tick": "assets/sounds/spin_tick.ogg"
};
sound.add(soundsMap, {
    preload: true
});

This throws the error below:

let loader = new PIXI.loaders.Loader();
loader
    .add("game_start", "assets/sounds/game_start.ogg")
    .add("spin_ready", "assets/sounds/spin_ready.ogg")
    .add("spin_loop", "assets/sounds/spin_loop.ogg")
    .add("spin_stop", "assets/sounds/spin_stop.ogg")
    .add("win_loop", "assets/sounds/win_loop.ogg")
    .add("game_end", "assets/sounds/game_end.ogg")
    .add("spin_start", "assets/sounds/spin_start.ogg")
    .add("spin_tick", "assets/sounds/spin_tick.ogg")
    .add("font_dark", "assets/fonts/font_dark.fnt")
    .add("font_light", "assets/fonts/font_light.fnt")
    .load(function (loader, resources) {
        this.loadAnimateScene();
    }.bind(this));
Uncaught (in promise) TypeError: Failed to execute 'decodeAudioData' on 'BaseAudioContext': parameter 1 is not of type 'ArrayBuffer'.
    at SoundContext.decode (SoundContext.js:156)
    at Sound._decode (Sound.js:355)
    at Sound._beginPreload (Sound.js:295)
    at new Sound (Sound.js:54)
    at SoundLibrary.add (SoundLibrary.js:65)
    at Loader.middleware (LoaderMiddleware.js:7)
    at Loader.js:590
    at next (async.js:32)
    at Loader.bitmapFontParser (bitmapFontParser.js:10)
    at Loader.js:590

Environment

multi play a not preloaded resource cause crash

PIXI.sound.add('...', {url})
PIXI.sound.play('...')
PIXI.sound.play('...')
pixi-sound.es.js:1242 Uncaught DOMException: Failed to set the 'buffer' property on 'AudioBufferSourceNode': Cannot set buffer to non-null after it has been already been set to a non-null buffer
    at e.set [as buffer] (webpack:///./node_modules/pixi-sound/dist/pixi-sound.es.js?:1242:31)
    at eval (webpack:///./node_modules/pixi-sound/dist/pixi-sound.es.js?:1279:49)
    at OfflineAudioContext.eval (webpack:///./node_modules/pixi-sound/dist/pixi-sound.es.js?:1555:13)

`addPixiMiddleware` doesn't work for other PixiJS plugins

As reported by @cursedcoder on Slack:

(PIXI.loaders as any).Loader = SoundLoader;
was it supposed to be:
(PIXI.loaders as any).SoundLoader = SoundLoader;
because code drops addPixiMiddleware method
leads to conflict with pixi-spine /cc @ivan
change above resolves the problem, still I’m not sure if it’s correct

Chrome 66 - The AudioContext was not allowed to start

Hi!
First of all - thanks for this great sound library! :)

Since last Chrome update there's a new policy:
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio

Needless to say, I don't like this new policy.

image

My game audio context gets paused :(
Since the game has no mouse intereaction, it never gets resumed.

However if I do press on the canvas with a pointer device, it resumes the audio context.
PIXI.sound.resumeAll() does not help either.

Is there no way to work around this?

I really like this library and I've been using it for my game;
It's still in active development and pixi-sound is an important part of it.

Add support for different audio format

Suggest using a glob-like API which allows you to set type for loading different audio files.

PIXI.sound.add('music', 'sounds/music.{mp3,ogg}');

In this case, mp3 would be loaded highest-priority with fallback to ogg.

Google Chrome Crashes When Loading Audio

I have an issue where Google Chrome crashes when loading audio with Pixi Sound.
(Firefox loads up fine 99% of the time)
scrnshot
I've tried everything I can but still can't seem to get it to be stable. It will load up correctly once in a while depending on how I save the audio file, e.g. really low quality with absolutely the lowest bitrate will sometimes work.

The mp3 file is 30 minutes long.
I am loading several other shorter mp3s as well.

Any ideas?
Help would greatly be appreciated.

Stopping sound when page is hidden on macOs

Hi, I have a problem stopping a pixi sound when you suscribe to "visibilitychange" event on html document using macOS. In windows/chrome works fine.

if user left our tab, we need to stop audio reproduction inmediately.

document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'hidden') {
stopAllPixiAudios(); //<---- this fire a PIXI.sound.stopAll()
}
});

when you do this, audio doesn't stop.

Is there any way to fix this ? I mean, the PIXI.sound.stopAll() is fired ok, and sound object has isPlaying attribute = false. But, audio still playing in background.

I'm using Chrome Versión 66.0.3359.117
OS: MacOs High Sierra 10.13.4

Any help ?

Thanks

Doesn't run

image

AnalyserNode doesn't have init method.

image

pixi-sound 2.0.0
pixi.js 4.6.1

Problems with sound in latest Chrome on Android in iframe

Sorry for vague description of the problem, but I am unable to make reproducible example of the problem and post issue here just in hope you're give me any clue how to debug this problem. I have private part of site where over iframe inserted application with PIXI.sound. I have limited access to this part of the site. It was found that on tablets, with latest version of Chrome sound in this application not working. I've tested this with my own hands, I'd log in and heard sound, then I updated Chrome, again logged in, and heard no sound at all (not even when I click and it supposed to play, see this phaserjs/phaser#2913). And there is no errors in console, I debug remotely and see that PIXI.sound.play is working, but hear no sound. I've failed to do reproducible example, because when I placed application in iframe alone I've heard sound. So may be you give me any hint how to debug this issue, I'll really appreciate it. Thanks in advance!

Cannot set property 'loop' of null

Uncaught TypeError: Cannot set property 'loop' of null

Error in instance.refresh() function when change parameters like volume or loop on paused instances, because this._source is currently null.

Workaround - do not trigger setters, direct change instance._loop, instance._volume etc.

Not a real problem, i just writing a function to help me manipulate multiple instances of sound at the same time and get this in process. Sorry for my bad english.

Unable to use this lib in browser

Hello! Project seems excellent, but when I tried to use it in my code, I've got error

./~/pixi-sound/lib/Sound.js Module not found: Error: Can't resolve 'fs' in '/home/user/Desktop/projects/balls/monster_cash/node_modules/pixi-sound/lib'

and as I see in Sound.js on 334 line there is var fs = require("fs"); And as far as I know it is node.js native module. How can I use it in browser? Or may be I have wrong import (I use ES6 modules with webpack). Didn't find any example how to import module in your docs, but it isn't working without it

import Sound from 'pixi-sound';

Does it right?

suggestion: convert audio for demo-loop to ogg to have seamless looping

Just found out pixi now also has an audio department too. Nice!
ooking at the demo here: http://pixijs.io/pixi-sound/examples/demo.html I see the file for the looping sounds are mp3 as well.
Unfortunately mp3 is not capable of having seamless loops, because of limitations of the format itself. There will always be some space in front of the file wich causes the file to always have some silence between loops making it impossible to loop seamlessly. Ogg files don't have this problem and are capable of seamless looping (but unfortunately the format isn't supported in IE though).

Maybe you guys already knew this, but just wanted to let you guys know as a suggestion. Maybe to change the loop files of the example to ogg (with fallback to mp3 for ie) or some extra attention in the help if not already there or something. Maybe it helps. Keep up the great work!

Publish pre-releases on npm

I would like to use the 2.0.0 alpha in my project, but don't want to build the files myself every time. Could you publish the pre-releases to npm? According to this post, this is preferrably done using a custom tag:

npm publish --tag alpha

otherwise, npm seems to install pre-releases by default when installing without a version number (e.g. npm install pixi-sound).

console.assert

pixi-sound use console.assert function which not exist in MRAID sdk environments (mobile advertisement). At least MoPub SDK. I propose to replace this function on something simpler like console.log to have more compatibility with mobile MRAID advertisement.

some sugest filter

hi , this look awsome, I have not yet arrived at the musical features of my project, but your plugin seems super and nice for me.

i just add some low priority filter sugest here.

BPM detection and stretching time control (for mix audio track in game || project)
http://joesul.li/van/beat-detection-using-web-audio/
https://github.com/cjcliffe/beatdetektor/blob/master/js/beatdetektor.js
https://github.com/danbovey/wam

low PASS filter
http://webaudioapi.com/samples/filter/

room effect
http://webaudioapi.com/samples/room-effects/

occilator
http://webaudioapi.com/samples/value-curve/

thanks
have a nice day!

How to use it with webpack

Hi, it may be just me, but I've been having trouble when I'm integrating this library with PIXI...

I concluded that one way was...

import * as PIXILib from 'pixi.js';
import * as PIXISoundLib from 'pixi-sound';

PIXI = {...PIXILib, ...PIXISoundLib}

...which does not seem really nice tbh 😅

chrome ended event not working

my code like this

PIXI.sound.Sound.from({
    url: 'xxxxxxx',
    preload: true,
    loaded: function (err, sound) {
        const instance = sound.play();
        instance.on('progress', function (progress) {
            console.log('Amount played: ', Math.round(progress * 100) + '%');
        });
        instance.on('end', function () {
            console.log('Sound finished playing');
        });
    }
});

result , Increased by 86% repeat , and not trigger end event
A few days ago began to have this problem
image

Old package on NPM

Hi!

Can you update this lib released under npm? It still says it's 1.4.2

Loading videos as audio files

Hello,

I've started working on a kind of a wrapper around PIXI.js recently. My idea is to add some mechanisms I like using and to make the entire framework fit to my needs better. I've finished adding the core pixi module and I wanted pixi-sound.js to be the first extension I add to it. Let me describe you the problem I encountered.

So basically I need my wrapper to be an all round solution. For that purpose I need to be able to play videos as well as sounds. the problem I get is that when I add pixi-sound.js it changes PIXI.loaders.Resource._xhrTypeMap/PIXI.loaders.Resource._loadTypeMap, so mp4 video files are trying to be loaded and decoded as audio files because mp4 is in PIXI.sound.utils.extensions.

The first thing that popped in my mind was PIXI.sound.useLegacy = true; before adding resources and loading them, but even then I was still getting videos which had audio as data property of resource. After looking at https://github.com/pixijs/pixi-sound/blob/master/src/loader/LoaderMiddleware.ts I noticed that in non-legacy mode mp4 files were still loaded as audio files just in legacy mode. (Kind of obvious but you gotta try to see it fail...)

In the end I patched it for my purpose (as I always want to use mp4 files as videos) with the following code to revert it to default pixi setup
PIXI.sound.utils.extensions.splice(PIXI.sound.utils.extensions.indexOf('mp4'), 1);
PIXI.loaders.Resource.setExtensionXhrType('mp4', undefined);
PIXI.loaders.Resource.setExtensionLoadType('mp4', PIXI.loaders.Resource.LOAD_TYPE.VIDEO);

I guess this is maybe not an issue, but I wanted to report it just in case someone else comes across it. Also, if there is some explanation or reason why pixi-sound looks at mp4 files as just audio files, I'd like you to tell me so I understand it and see if my "revert" solution maybe has some problems I am not aware of at this moment.

Thanks in advance

Global speed setting

Add a global speed setting (similar to global volume), which is multiplied with playbackRate for sound instances.

[feature] Support HTML5 Fallback

Need basic support for HTML5 fallback to support IE. Will probably add a new class (e.g. LegacySound) which wraps the HTML5 <audio> element but provides a common interface (e.g. ISound) for the existing Sound class which allows for basic support like play, pause, mute, volume and sprites. Loader middleware installing would need to check to see if WebAudio is support or else don't do anything so the Loader will return <audio> elements instead.

Add decoupling to pixi.js

Maybe the module can decouple from PIXI.js (in global namespace) for ppl that do not use PIXI for rendering but pixi-sound for audio?

I think we could expose an interface in index.ts that allow passing an arbitary PIXI object (even empty), for example:

var customPIXI = {};
import PixiSound from 'pixi-sound';
PixiSound.init (customPIXI);

and in SoundLibrary.init (), just change:

public static init (customPIXI) {
    const PixiJS = customPIXI || PIXI as any;
}

Possible?

Filters API :)

I had a dream where to apply filters to sound it was a simple as this:

var mySound = Sound.from('happy-days.mp3')
var filter = new PitchShiftFilter();

mySound.filters = [filter];

Gradually filter effect

Hi, can I fade in-out effect of a filter?

I try to explain it better, if I want to go from a filterless track to a filter but gradually (such as reverb) is it possible with pixi-sound filter?

Unfortunately I noticed that the reverb value in seconds is at least 1, if it was possible to gradually move from 0 to 1 or (x).. I would have the desired effect?

Many thanks
W

Errors in IE/Edge and Firefox

Hello!

I'm using pixi.js for my project, and sounds play a significant part in it. Among desired browsers where my project is supposed to work are IE11/Edge and newest FF.

I get these errors trying either pixi-sound demo or starting my project with pixi-sound:

  1. IE11/Edge
    SCRIPT438: Object doesn't support property or method 'canPlayType'
    SCRIPT16385: Not implemented // several times

And no reaction for click.

  1. Firefox
    An unknown error occurred while processing decodeAudioData // several times

And after 'play' click:
TypeError: instance.on is not a function
An unknown error occurred while processing decodeAudioData.
Error: Unable to decode file

Everything is ok in Chrome and Safari.
I tried both v1.4.2 and v2.0.0-alpha.

Tell, please, if you are able to handle that or you can advice any options for me?

Cannot build: missing rollup config

Hi there, trying to build the bundled distribution for this project -
I'm assuming npm run build is the proper command.

I'm getting an error stating that the rollup.config.js is missing - I don't see it as part of the source code.

Here's the full terminal dump if it helps:

> [email protected] prebuild /Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound
> npm run clean && npm run lint


> [email protected] clean /Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound
> rimraf dist/**


> [email protected] lint /Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound
> tslint examples/**.js test/*.js src/**.ts rollup.config.js --format=stylish --fix



> [email protected] build /Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound
> npm run build:umd && npm run build:es


> [email protected] build:umd /Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound
> rollup -c -f umd -o dist/pixi-sound.js

Error: ENOENT: no such file or directory, lstat '/Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound/rollup.config.js'
    at Object.realpathSync (fs.js:1657:15)
    at runRollup (/Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound/node_modules/rollup/bin/rollup:653:16)
    at Object.<anonymous> (/Users/sean/projects/PaperGorillas/src/js/ext/pixi-sound/node_modules/rollup/bin/rollup:907:2)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)

Thanks!

[feature] Implement fadeIn and faceOut methods

Add methods for fading in and out of the volume levels when playing or stopping audio. For instance:

const sound = PIXI.sound.Sound.from('foo.mp3');
const instance = sound.fadeIn(500); // same as play()
instance.fadeOut(200); // fade out a single instance
sound.fadeOut(200); // fade out all instances

And global library commands:

PIXI.sound.add('foo', 'foo.mp3');
const instance = PIXI.sound.fadeIn('foo', 500);
instance.fadeOut(200); 
PIXI.sound.fadeOut('foo', 200); // fade out all instances
PIXI.sound.fadeOut(); // fade out all sounds, all instances

RFC: Option for sound context [auto|re]initialization

Status

At the moment sound context is always automatically created within SoundLibrary

Why it is not good

When context is created it is bound with sound hardware, so it always consumes resources.

There may be situations when hardware is blocked at the moment SoundLibrary being created.

My personal real cases:

  • On iOS cordova background plugin will rebind audio sources when used, this will always halt existing audio contexts.
  • Opening page with just pixi-sound included produces "soft noise" – when empty sound is streamed to audio output.

Proposal

  1. Add option autoInitialize – self-explanatory.
  2. Add interface SoundLibrary.rebuildContext() – or similar, this will provide users ability to recover from any hardware interruptions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.