The Preload command

Let clients download/buffer audio in advance, ensuring a smooth and timely playback

Media Preloading

Media preloading is a technique used to load audio files before they are needed.
The internet is a scary place, requests can fail, and not all internet connections are fast. Preloading can help to mitigate these issues by loading the audio files before they are needed.

OpenAudioMc uses a "pool" of preloaded audio files. Each time a media is requested to play, the web client will look in the pool to see if the media is already loaded. If it is, then the client will grab it out of the pool and play it immediately, without having to wait for the file to download. This can bring loading times down from a few seconds to a few milliseconds.

The command follows the following format; (read more about selectors and sources here)

/openaudiomc preload <selector> <source>

So, for example, running

/openaudiomc preload @a files:awesome-show.mp3

will preload the file awesome-show.mp3 for all players on the server, meaning that it will be ready to play immediately when requested. I recommend starting preloads ~5 seconds before the media is needed, as this is enough for even most of the slowest connections to load the media.

Pro tips

  • If you already know that the media will be used more than once, then you can preload it multiple times to keep a few instances in the pool
  • You shouldn't be preloading media too generously, as it can take up a lot of memory. If you're running out of memory, then you should consider reducing the amount of preloaded media.
  • Be sure to actually play the media that you're preloading, as preloading media that isn't used is a waste of resources.
  • Be respectful of your users' data plans. Don't spam preloads without a good reason.

Known edge cases

  • 3D Speakers will not use preloaded media if CORS is not set up correctly.

Automatic preloading

The plugin will also try to automatically preload media that is used frequently in certain areas.
This is achieved by making a heatmap of played media sources for areas of 150x150 blocks (roughly 9 square chunks).
If The player moves into another section, then it'll drop the cache pool from the previous section and start preloading the media for the new section. The plugin will only load 7 sources per section (which can be changed in the config), which covers

  • regions
  • speakers
  • play commands
  • ride audio
  • api audio

Cached entries will be removed if they haven't been played for a while, and the configured amount of preloaded media is sorted by the last time they were played and how often, to prioritize the most used media.
Max 70 sections are stored at any given time, and a section may not hold more than 15 sources. This is to prevent the plugin from using too much memory.

Permissions

openaudiomc.commands.preload

This permission is required to use the /oa preload command

Default access level: op

Javadoc related to this feature (currently based on the dev branch)