npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extensions.unity.audioloader

v1.0.4

Published

Asynchronous audio loading from remote or local destination. It has two layers of configurable cache system: RAM and Disk.

Downloads

7

Readme

Unity Audio Loader

npm openupm License Stand With Ukraine

Async audio loader with two caching layers for Unity.

Features

  • ✔️ Async loading from Web or Local AudioLoader.LoadAudioClip(audioURL);
  • ✔️ Memory and Disk caching - tries to load from memory first, then from disk
  • ✔️ Dedicated thread for disk operations
  • ✔️ Avoids loading same audio multiple times simultaneously, task waits for completion the first and just returns loaded audio if at least one cache layer activated
  • ✔️ Auto set to AudioSource AudioLoader.SetAudioSource(audioURL, audioSource);
  • ✔️ Debug level for logging AudioLoader.settings.debugLevel = DebugLevel.Error;

Usage

In main thread somewhere at start of the project need to call AudioLoader.Init(); once to initialize static properties in right thread. It is required to make in main thread. Then you can use AudioLoader from any thread and any time.

Sample - Loading audio file, set to AudioSource

using Extensions.Unity.AudioLoader;
using Cysharp.Threading.Tasks;

public class AudioLoaderSample : MonoBehaviour
{
    [SerializeField] string audioURL;
    [SerializeField] AudioSource audioSource;

    async void Start()
    {
        // Loading audio file from web, cached for quick load next time
        audioSource.clip = await AudioLoader.LoadAudioClip(audioURL);

        // Same loading with auto set to audio
        await AudioLoader.SetAudioSource(audioURL, audioSource);
    }
}

Sample - Loading audio into multiple Audio components

using Extensions.Unity.AudioLoader;
using Cysharp.Threading.Tasks;

public class AudioLoaderSample : MonoBehaviour
{
    [SerializeField] string audioURL;
    [SerializeField] AudioSource audioSource1;
    [SerializeField] AudioSource audioSource2;

    void Start()
    {
        // Loading with auto set to audio
        AudioLoader.SetAudioSource(audioURL, audioSource1, audioSource2).Forget();
    }
}

Cache

Cache system based on the two layers. First layer is memory cache, second is disk cache. Each layer could be enabled or disabled. Could be used without caching at all. By default both layers are enabled.

Setup Cache

  • AudioLoader.settings.useMemoryCache = true; default value is true
  • AudioLoader.settings.useDiskCache = true; default value is true

Change disk cache folder:

AudioLoader.settings.diskSaveLocation = Application.persistentDataPath + "/myCustomFolder";

Override Cache

// Override Memory cache for specific audio
AudioLoader.SaveToMemoryCache(url, audioClip);

// Take from Memory cache for specific audio file if exists
AudioLoader.LoadFromMemoryCache(url);

Does Cache contain audio

// Check if any cache contains specific audio file
AudioLoader.CacheContains(url);

// Check if Memory cache contains specific audio file
AudioLoader.MemoryCacheContains(url);

// Check if Memory cache contains specific audio file
AudioLoader.DiskCacheContains(url);

Clear Cache

// Clear memory Memory and Disk cache
AudioLoader.ClearCache();

// Clear only Memory cache for all audio files
AudioLoader.ClearMemoryCache();

// Clear only Memory cache for specific audio file
AudioLoader.ClearMemoryCache(url);

// Clear only Disk cache for all audio files
AudioLoader.ClearDiskCache();

// Clear only Disk cache for specific audio file
AudioLoader.ClearDiskCache(url);

Installation

openupm add extensions.unity.audioloader