AudioPlayer class Null safety

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.


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


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.
read / write
hashCode int
The hash code for this object.
mode PlayerMode
onDurationChanged Stream<Duration>
Stream of changes on audio duration.
onPlayerComplete Stream<void>
Stream of player completions.
onPlayerStateChanged Stream<PlayerState>
Stream of changes on player state.
onPositionChanged Stream<Duration>
Stream of changes on audio position.
onSeekComplete Stream<void>
Stream of seek completions.
playerId String
An unique ID generated for this instance of AudioPlayer.
releaseMode ReleaseMode
runtimeType Type
A representation of the runtime type of the object.
source Source?
state PlayerState
read / write


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 non-existent method or property is accessed.
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.


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

Static Properties

global GlobalPlatformInterface