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({PlayerMode mode = PlayerMode.MEDIA_PLAYER, String? playerId})
Creates a new instance and assigns an unique id to it.

Properties

audioPlayerStateChangeHandler AudioPlayerStateChangeHandler?
Handler of changes on player state.
getter/setter pair
completionHandler VoidCallback?
Handler of player completions.
getter/setter pair
durationHandler TimeChangeHandler?
Handler of changes on audio duration.
getter/setter pair
errorHandler ErrorHandler?
Handler of player errors.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
mode PlayerMode
Current mode of the audio player. Can be updated at any time, but is going to take effect only at the next time you play the audio.
getter/setter pair
notificationState AudioPlayerState
no getter
onAudioPositionChanged Stream<Duration>
Stream of changes on audio position.
no setter
onDurationChanged Stream<Duration>
Stream of changes on audio duration.
no setter
onNotificationPlayerStateChanged Stream<AudioPlayerState>
Stream of changes on player state coming from notification area in iOS.
no setter
onPlayerCommand Stream<PlayerControlCommand>
Stream of remote player command send by native side
no setter
onPlayerCompletion Stream<void>
Stream of player completions.
no setter
onPlayerError Stream<String?>
Stream of player errors.
no setter
onPlayerStateChanged Stream<AudioPlayerState?>
Stream of changes on player state.
no setter
onSeekComplete Stream<void>
Stream of seek completions.
no setter
playerId String?
An unique ID generated for this instance of AudioPlayer.
getter/setter pair
playingRouteState PlayingRouteState
no getter
positionHandler TimeChangeHandler?
Handler of changes on player position.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
seekCompleteHandler SeekHandler?
Handler of seek completion.
getter/setter pair
state AudioPlayerState?
getter/setter pair

Methods

dispose() Future<void>
Closes all StreamControllers.
earpieceOrSpeakersToggle() Future<int>
getCurrentPosition() Future<int>
getDuration() Future<int>
Get audio duration after setting url. Use it in conjunction with setUrl.
isLocalUrl(String url) bool
monitorNotificationStateChanges(void callback(AudioPlayerState value)) Future<bool>
Start getting significant audio updates through callback.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pause() Future<int>
Pauses the audio that is currently playing.
play(String url, {bool? isLocal, double volume = 1.0, Duration? position, bool respectSilence = false, bool stayAwake = false, bool duckAudio = false, bool recordingActive = false}) Future<int>
Plays an audio.
playBytes(Uint8List bytes, {double volume = 1.0, Duration? position, bool respectSilence = false, bool? stayAwake = false, bool duckAudio = false, bool? recordingActive = false}) Future<int>
Plays audio in the form of a byte array.
release() Future<int>
Releases the resources associated with this media player.
resume() Future<int>
Resumes the audio that has been paused or stopped, just like calling play, but without changing the parameters.
seek(Duration position) Future<int>
Moves the cursor to the desired position.
setNotification({String? title, String? albumTitle, String? artist, String? imageUrl, Duration forwardSkipInterval = Duration.zero, Duration backwardSkipInterval = Duration.zero, Duration duration = Duration.zero, Duration elapsedTime = Duration.zero, bool hasPreviousTrack = false, bool hasNextTrack = false}) Future
Sets the notification bar for lock screen and notification area in iOS for now.
setPlaybackRate({double playbackRate = 1.0}) Future<int>
Sets the playback rate - call this after first calling play() or resume().
setReleaseMode(ReleaseMode releaseMode) Future<int>
Sets the release mode.
setUrl(String url, {bool isLocal = false, bool respectSilence = false}) Future<int>
Sets the URL.
setVolume(double volume) Future<int>
Sets the volume (amplitude).
startHeadlessService() → void
this should be called after initiating AudioPlayer only if you want to listen for notification changes in the background. Not implemented on macOS
stop() Future<int>
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

logEnabled bool
Enables more verbose logging.
getter/setter pair
players Map<String?, AudioPlayer>
Reference Map with all the players created by the application.
final

Static Methods

platformCallHandler(MethodCall call) Future<void>