AudioCache class

This class represents a cache for Local Assets to be played.

On desktop/mobile, Flutter can only play audios on device folders, so first this class copies asset files to a temporary folder, and then holds a reference to the file.

On web, it just stores a reference to the URL of the audio, but it gets preloaded by making a simple GET request (the browser then takes care of caching).

You can pre-cache your audio, or clear the cache, as desired. For most normal uses, the static instance is used. But if you want to control multiple caches, you can create your own instances.

Constructors

AudioCache({String prefix = 'assets/', String? cacheId})

Properties

cacheId String?
An unique ID generated for this instance of AudioCache.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
loadedFiles Map<String, Uri>
A reference to the loaded files absolute URLs.
final
prefix String
This is the path inside your assets folder where your files lie.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear(String fileName) Future<void>
Clears the cache for the file fileName.
clearAll() Future<void>
Clears the whole cache.
fetchToMemory(String fileName) Future<Uri>
getTempDir() Future<String>
load(String fileName) Future<Uri>
Loads a single fileName to the cache.
loadAll(List<String> fileNames) Future<List<Uri>>
Loads all the fileNames provided to the cache.
loadAsBytes(String fileName) Future<Uint8List>
Loads a single fileName to the cache but returns it as a list of bytes.
loadAsFile(String fileName) Future<File>
Loads a single fileName to the cache but returns it as a File.
loadAsset(String path) Future<ByteData>
loadPath(String fileName) Future<String>
Loads a single fileName to the cache.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

fileSystem ↔ FileSystem
getter/setter pair
instance AudioCache
A globally accessible instance used by default by all players.
getter/setter pair