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
- balance → double
-
no setter
-
creatingCompleter
→ Completer<
void> -
Completer to wait until the native player and its event stream are
created.
final
- desiredState ↔ PlayerState
-
Auxiliary variable to re-check the volatile player state during async
operations.
getter/setter pair
-
eventStream
→ Stream<
AudioEvent> -
no setter
- 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
-
onLog
→ Stream<
String> -
Stream of log events.
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
- playbackRate → double
-
no setter
- playerId → String
-
An unique ID generated for this instance of AudioPlayer.
final
- positionUpdater ← PositionUpdater?
-
Set the PositionUpdater to control how often the position stream will be
updated. You can use the FramePositionUpdater, the
TimerPositionUpdater or write your own implementation of the
PositionUpdater.
no getter
- releaseMode → ReleaseMode
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source → Source?
-
no setter
- state ↔ PlayerState
-
The current playback state.
It is only set, when the corresponding action succeeds.
getter/setter pair
- volume → double
-
no setter
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> -
Play an audio
source
. -
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, {String? mimeType}) → 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, {String? mimeType}) → Future< void> -
setSourceDeviceFile(
String path, {String? mimeType}) → Future< void> - Sets the URL to a file in the users device.
-
setSourceUrl(
String url, {String? mimeType}) → 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 → GlobalAudioScope
-
final