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

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.
final
notificationService NotificationService
getter/setter pair
notificationState PlayerState
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<PlayerState>
Stream of changes on player state coming from notification area in iOS.
no setter
onPlayerCompletion Stream<void>
Stream of player completions.
no setter
onPlayerError Stream<String>
Stream of player errors.
no setter
onPlayerStateChanged Stream<PlayerState>
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.
final
playingRouteState PlayingRoute
no getter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state PlayerState
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
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.
setPlaybackRate(double playbackRate) 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, bool respectSilence = false, bool recordingActive = false}) Future<int>
Sets the URL.
setVolume(double volume) Future<int>
Sets the volume (amplitude).
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

players Map<String, AudioPlayer>
Reference Map with all the players created by the application.
final

Static Methods

invokeMethod(String method, Map<String, dynamic> args) Future<int>
platformCallHandler(MethodCall call) Future<void>