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.

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

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 non-existent 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