AudioPlayer class

This represents a single AudioPlayer, which can play one audio at a time. To play several audios at the same time, you must create several instances of this class.

It holds methods to play, loop, pause, stop, seek the audio, and some useful hooks for handlers and callbacks.

Constructors

AudioPlayer({String? playerId})
Creates a new instance and assigns an unique id to it.

Properties

audioCache AudioCache
This is the AudioCache instance used by this player. Unless you want to control multiple caches separately, you don't need to change anything as the global instance will be used by default.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
mode PlayerMode
no setter
onDurationChanged Stream<Duration>
Stream of changes on audio duration.
no setter
onPlayerComplete Stream<void>
Stream of player completions.
no setter
onPlayerStateChanged Stream<PlayerState>
Stream of changes on player state.
no setter
onPositionChanged Stream<Duration>
Stream of changes on audio position.
no setter
onSeekComplete Stream<void>
Stream of seek completions.
no setter
playerId String
An unique ID generated for this instance of AudioPlayer.
final
releaseMode ReleaseMode
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
source Source?
no setter
state PlayerState
getter/setter pair

Methods

dispose() Future<void>
Closes all StreamControllers.
getCurrentPosition() Future<Duration?>
getDuration() Future<Duration?>
Get audio duration after setting url. Use it in conjunction with setUrl.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pause() Future<void>
Pauses the audio that is currently playing.
play(Source source, {double? volume, double? balance, AudioContext? ctx, Duration? position, PlayerMode? mode}) Future<void>
release() Future<void>
Releases the resources associated with this media player.
resume() Future<void>
Resumes the audio that has been paused or stopped.
seek(Duration position) Future<void>
Moves the cursor to the desired position.
setAudioContext(AudioContext ctx) Future<void>
setBalance(double balance) Future<void>
Sets the stereo balance.
setPlaybackRate(double playbackRate) Future<void>
Sets the playback rate - call this after first calling play() or resume().
setPlayerMode(PlayerMode mode) Future<void>
setReleaseMode(ReleaseMode releaseMode) Future<void>
Sets the release mode.
setSource(Source source) Future<void>
Sets the audio source for this player.
setSourceAsset(String path) Future<void>
Sets the URL to an asset in your Flutter application. The global instance of AudioCache will be used by default.
setSourceBytes(Uint8List bytes) Future<void>
setSourceDeviceFile(String path) Future<void>
Sets the URL to a file in the users device.
setSourceUrl(String url) Future<void>
Sets the URL to a remote link.
setVolume(double volume) Future<void>
Sets the volume (amplitude).
stop() Future<void>
Stops the audio that is currently playing.
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

global GlobalPlatformInterface
final