๐พ Download
Installation:
npm install @pixi/sound@6.1.0Development Build:
- https://cdn.jsdelivr.net/npm/@pixi/sound@6.1.0/dist/pixi-sound.js
- https://cdn.jsdelivr.net/npm/@pixi/sound@6.1.0/dist/pixi-sound.mjs
Documentation:
Changed
๐จ Behavior Change
- Fix: Don't throw for an unknown alias or sprite by @zbdd in #378
- An unknown alias or sprite no longer throws.
play()returnsnull,volume(),speed()andduration()returnNaN, andstop(),pause()andresume()returnundefined.
- An unknown alias or sprite no longer throws.
- Fix: Fade out before the window-blur pause by @zbdd in #393
- A window blur now fades the output out over about a tenth of a second before it pauses, and the focus fades it back in.
pausedreadstrueas soon as the blur arrives.
- A window blur now fades the output out over about a tenth of a second before it pauses, and the focus fades it back in.
- Fix: Hold HTML audio played during pauseAll by @zbdd in #396
- With HTML audio, a sound played during
pauseAll()now waits forresumeAll(), as it already did with WebAudio.
- With HTML audio, a sound played during
- Fix: Pause and resume HTML audio when context.paused is set by @zbdd in #397
- With HTML audio, setting
sound.context.pausednow pauses and resumes the sounds that are playing.
- With HTML audio, setting
- Fix: Keep isPlaying false while a sound is paused by @zbdd in #409
isPlayingis nowfalsewhile a sound is paused.
- Fix: Hold a play into a paused sound by @zbdd in #410
- A sound played while it is paused (
pause()orpaused = true) now starts paused and plays onresume(), as a sound in a paused channel does. Before, it was heard.
- A sound played while it is paused (
- Fix: Silence sounds outside the library on close by @zbdd in #411
close()now also pauses sounds that aren't in the library, such as ones made withSound.fromand never added, so nothing keeps playing after it.
- Fix: Keep the sine tone within full scale by @zbdd in #416
utils.sineTone()now writes a sine from -1 to 1 instead of -2 to 2, so the tone is no longer clipped and is a little quieter. Usevolumeto change its level.
- Fix: Keep an app's pause made while the window is blurred by @zbdd in #420
pauseAll(),resumeAll()orcontext.pausedcalled while the window is blurred, for example in your own blur listener, is now kept when the window gets focus again.
๐ Added
- Feature: Add sound channels by @zbdd in #403
- A channel is a named group of sounds, such as music or effects, with its own volume, mute and pause. A sound joins a channel with the
channeloption, also in Assetsdata, andsound.channel(name)returns the channel, creating it the first time the name is used. The channel's volume multiplies with the sound's and the global volume, andvolumeAll,muteAllandpauseAlldon't change a channel's settings. A sound played into a paused channel starts paused.
import { sound, filters } from '@pixi/sound'; sound.add('theme', { url: 'theme.mp3', channel: 'music' }); const music = sound.channel('music'); music.volume = 0.5; music.muted = true; music.paused = true; music.filters = [new filters.TelephoneFilter()]; // WebAudio only music.stop(); // stops every sound in the channel music.isPlaying; // true while any sound in the channel is playing
- A channel is a named group of sounds, such as music or effects, with its own volume, mute and pause. A sound joins a channel with the
- Feature: Add filters to sound channels by @zbdd in #404
channel.filtersruns a channel's sounds through its filters, then throughfiltersAll. WebAudio only: with HTML audio, setting it warns and does nothing.
- Feature: Add stop and isPlaying to sound channels by @zbdd in #406
channel.stop()stops every sound in the channel, paused ones too.channel.isPlayingistruewhile any sound in the channel is playing, also while the channel is paused.
- Feature: Add a streaming option for long sounds by @zbdd in #418
streaming: truestarts a long sound, such as music, while it downloads, instead of after the whole file is downloaded and decoded. Volume, mute, speed, loop, pause, channels and the sound's and channel's filters still apply. A streaming sound plays one instance at a time (play()restarts it), ignoresendand playfilters, so a sprite plays from its start to the end of the file, and limits speed to 0.0625โ16.startneeds a server that supports range requests, and a file on another origin needs CORS headers.
import { sound } from '@pixi/sound'; import { Assets } from 'pixi.js'; sound.add('music', { url: 'music.mp3', streaming: true, loop: true }); sound.play('music'); // or with Assets Assets.add({ alias: 'music', src: 'music.mp3', data: { streaming: true } });
๐ Fixed
- Chore: Allow null in the options that take it by @zbdd in #384
- The options that already default to
null(url,source,complete,loaded,end,sprite) now acceptnullin their types.
- The options that already default to
- Fix: Keep an HTML sprite's end when it resumes by @zbdd in #390
- Fix: Don't play the old volume after resumeAll by @zbdd in #395
- Fix: Keep the HTML start when paused right after play() by @zbdd in #398
- Fix: Don't seek a reused HTML instance to the old start by @zbdd in #399
- Fix: End a sprite resumed after its end instead of throwing by @zbdd in #400
- Fix: Let a start listener stop the instance by @zbdd in #401
- Fix: Let a progress listener stop an HTML instance by @zbdd in #402
- Fix: Disconnect cleared filters from their chain by @zbdd in #407
- Fix: Allow a stop listener to stop its sound again by @zbdd in #412
- Fix: Keep instance filters set while paused by @zbdd in #413
- Fix: Stop playOnce asserting on a removed sound by @zbdd in #414
- Fix: Stop disableAutoPause throwing without WebAudio by @zbdd in #417
- Fix: Undo a blur pause on focus after autoPause is turned off by @zbdd in #419
๐งน Chores
- Chore: Run the tests with Vitest in Chromium by @zbdd in #364
- Chore: Bump shell-quote from 1.8.1 to 1.12.0 by @dependabot[bot] in #365
- Chore: Update vulnerable dev dependencies by @zbdd in #373
- Chore: Run the tests in Firefox too by @zbdd in #374
- Chore: Run the tests in WebKit too by @zbdd in #375
- Chore: Make a Firefox unlock test less flaky by @zbdd in #376
- Chore: Update extension-scripts to 5.0.0 by @zbdd in #377
- Chore: Mark v4 and v5 as no longer maintained by @zbdd in #379
- Chore: Play the resume-loop tests faster by @zbdd in #380
- Chore: Use inline type imports by @zbdd in #381
- Chore: Use xs 5's strict tsconfig apart from strictNullChecks by @zbdd in #382
- Chore: Fix strictNullChecks errors in filters and utils by @zbdd in #383
- Chore: Wait for events in the instance-lifecycle tests by @zbdd in #385
- Chore: Allow for the audio clock moving in the play test by @zbdd in #386
- Chore: Fix strictNullChecks errors in htmlaudio by @zbdd in #387
- Chore: Fix strictNullChecks errors in webaudio by @zbdd in #388
- Chore: Fix strictNullChecks errors in Sound and SoundLibrary by @zbdd in #389
- Chore: Fix strictNullChecks errors in the tests by @zbdd in #391
- Chore: Turn on strictNullChecks by @zbdd in #392
- Chore: Fix the README's PixiJS link and filter list by @zbdd in #394
- Chore: Say that only the exported sound library is supported by @zbdd in #405
- Chore: Update the example pages by @zbdd in #408
- Fix: Make the blur-fade focus-during-fade test deterministic by @zbdd in #415