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 the files to a temporary folder, and then plays them. 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.

Constructors

AudioCache({String prefix = 'assets/', AudioPlayer? fixedPlayer, bool respectSilence = false, bool duckAudio = false})

Properties

duckAudio bool
This flag should be set to true, if player is used for playing sound while there may be music
getter/setter pair
fixedPlayer AudioPlayer?
This is an instance of AudioPlayer that, if present, will always be used.
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.
getter/setter pair
prefix String
This is the path inside your assets folder where your files lie.
getter/setter pair
respectSilence bool
This flag should be set to true, if player is used for playing internal notifications
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear(Uri fileName) Future<void>
Clears the cache for the file fileName.
clearAll() Future<void>
Clears the whole cache.
fetchToMemory(String fileName) Future<Uri>
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.
loadAsFile(String fileName) Future<File>
Loads a single fileName to the cache but returns it as a File.
loop(String fileName, {double volume = 1.0, bool? isNotification, PlayerMode mode = PlayerMode.MEDIA_PLAYER, bool stayAwake = false}) Future<AudioPlayer>
Like play, but loops the audio (starts over once finished).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
play(String fileName, {double volume = 1.0, bool? isNotification, PlayerMode mode = PlayerMode.MEDIA_PLAYER, bool stayAwake = false, bool recordingActive = false, bool? duckAudio}) Future<AudioPlayer>
Plays the given fileName.
playBytes(Uint8List fileBytes, {double volume = 1.0, bool? isNotification, PlayerMode mode = PlayerMode.MEDIA_PLAYER, bool loop = false, bool stayAwake = false, bool recordingActive = false}) Future<AudioPlayer>
Plays the given fileBytes by a byte source.
toString() String
A string representation of this object.
inherited

Operators

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