Audio

By
,

Post-0.5.2

Preparation

Starting with 0.5.2, the soundManager is no longer part of PML itself. Instead, it was moved to pmlapi, a separate mod. If you are planning to use soundManger, be sure to add the pmlapi dependency to your mod's version.json(for 0.6.0 onward) or manifest.json(for 0.5.2):

"dependencies": [
  {
    "id": "pmlapi",
    "version": "0.1.2"
  }
]

version 0.1.2 is the newest for 0.5.2.

Usage

Instead of pml.soundManager, you now call the pmlapi mod:

pml.getMod("pmlapi").soundManager

You can also make a variable for pmlapi:

this.pApi = pml.getMod("pmlapi");

this way you can use

this.pApi.soundManager

instead of having to use pml.getMod every time

Registering sounds

In order to play a sound, you have to register it first. This has to be done in postInit, not init.
To register a sound, use this.pApi.soundManager.registerSound like this:

this.pApi.soundManager.registerSound(name, [url]);

name is the name of the sound
url is the url to the audio file, please make sure to not use relative links, as some devices do not support these

Playing sounds

After havig registered the sound, it can be played from within your mod directly or in mixins using this.pApi.soundManager.playSound like this:

this.pApi.soundManager.playSound(name, volume);

name is the name given to the sound
volume is the volume that the sound should be played at

Sound overrides

You can override sounds:

this

Pre-0.5.2

Audio

You can add audio to be played using PolyTrack's sound manager using PolyModLoader

Registering Audio

In order to play a sound, you have to register it first. This has to be done in postInit, not init.
To register a sound, use pml.soundManager.registerSound like this:

pml.soundManager.registerSound(name, [url]);

name is the name of the sound
url is the url to the audio file, please make sure to not use relative links, as some devices do not support these

Playing Audio

After havig registered the Audio, it can be played from within your mod directly or in mixins using pml.soundManager.playSound like this:

pml.soundManager.playSound(name, volume);

name is the name given to the sound
volume is the volume that the sound should be played at