如何正确导入pixi-sound (PIXI JS)

How to correctly import pixi-sound (PIXI JS)

这可能是个愚蠢的问题,但是如何正确导入 pixi-sound?

我的问题是:

import * as PIXI from "pixi.js";
import PIXI_SOUND from "pixi-sound";

const EFFECT_SOUNDS = [...list of music]

for (let name in EFFECT_SOUNDS) {
   PIXI.Loader.shared.add(name, EFFECT_SOUNDS[name]);
}

... more logic

PIXI.Loader.shared.load(function(loader, resources) {
  if (resources[sound]) {

    // this is where the issue is
    resources[sound].sound.play();
    resources[sound].sound.speed= 0.5;
  }
});

上面的代码 resources[sound].sound.playexistspeedstop 等其他属性不存在。

我尝试将代码更改为:

import * as PIXI_SOUND from "pixi-sound";

但这行不通。

我也试过 PIXI_SOUND.Loader 但这会引发错误。

这对我有用

import * as PIXI from 'pixi.js';
window.PIXI = PIXI; // this seems optional
import 'pixi-sound';

如果您正在使用 @inlet/react-pixi,您可以像这样导入

import { Container, withPixiApp } from '@inlet/react-pixi';
import { default as PIXI_SOUND } from 'pixi-sound';


PIXI_SOUND.add(key, {
    url: url,
    preload: true,
    loaded: (err, sound) => {
        if (err) {
            console.warn(`load sound ${key} - ${url} error: ${err}`)
        } else {
            console.log(`loaded sound ${key} - ${url}: ${sound.duration} seconds`)
        }
    }
})