AudioCache class

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

Flutter can only play audios on device folders, so first this class copies the files to a temporary folder, and then plays them. 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, File>
A reference to the loaded files.
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(String fileName) → void
Clears the cache of the file fileName.
clearCache() → void
Clears the whole cache.
disableLog() → void
Disables AudioPlayer logs (enable only if debugging, otherwise they can be quite overwhelming).
fetchToMemory(String fileName) Future<File>
getAbsoluteUrl(String fileName) Future<String>
load(String fileName) Future<File?>
Loads a single fileName to the cache.
loadAll(List<String> fileNames) Future<List<File?>>
Loads all the fileNames provided to the cache.
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, bool? recordingActive}) Future<AudioPlayer>
Plays the given fileName by a byte source.
toString() String
A string representation of this object.
inherited

Operators

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