pixijs / sound

WebAudio API playback library, with filters. Modern audio playback for modern browsers.
https://pixijs.io/sound/examples/
MIT License
409 stars 67 forks source link

Parser for Pixi Assets does not register properly #252

Open adamarutyunov opened 1 year ago

adamarutyunov commented 1 year ago

Nuxt 2.15.3 + webpack 4.47.0

Pixi version: 7.2.4 @pixi/sound version: 5.2.1

I tried to use @pixi/sound with new Pixi.Assets loading system like this:

import * as PIXI from 'pixi.js'
import '@pixi/sound'

const url = item.data.src  // path to .mp3 file
const sound = await PIXI.Assets.load(url)

I successfully load images this way, but in this example I get this error:

[Assets] <path> could not be loaded as we don't know how to parse it, ensure the correct parser has been added

Seems like LoaderParser for sound files does not add to Pixi extension system. I tried to add the extensions manually:

import {soundAsset} from '@pixi/sound/lib/soundAsset.js'
PIXI.extensions.add(soundAsset)
PIXI.extensions.add(soundAsset.loader)

But I get this error that I cannot even explain:

Error: [Loader.load] Failed to load <src>.
TypeError: Cannot read properties of undefined (reading 'useLegacy')
    at _callee2$ (Loader.ts:200:1)
    at tryCatch (Loader.js:7:1062)
    at Generator.eval (Loader.js:7:3012)
    at Generator.eval [as throw] (Loader.js:7:1699)
    at asyncGeneratorStep (Loader.js:8:103)
    at _throw (Loader.js:9:291)

Finally I gave up and used old preloading system wrapper in promise, like this:

const sound = await new Promise((resolve, reject) => {
    Sound.from({
        url,
        preload: true,
        loaded: function(err, sound) {
            resolve(sound)
        }
    })
})

But eventually I'd like to revert it back to new Assets system. Where do I do something wrong?

Also I've tried to revert to old versions of pixi.js and @pixi/sound but I kept getting same errors.

bigtimebuddy commented 1 year ago

Can you create a minimum reproduction so that we can debug more easily? Functionally this works, as you can see the example here.

Make sure you don't have multiple copies of @pixi/core in your lock file (this can happen if you've upgraded) and could cause this behavior where the parser is getting installed in the wrong place.

hotyes commented 11 months ago

I had encountered same issue but solved it by adding following code manually

import { extensions } from 'pixi.js'
import { soundAsset } from '@pixi/sound'
extensions.add(soundAsset)