MtAudioPlayer class

Main public API for the mt_audio package.

Provides a simple, streams-based interface for audio playback with background support, notifications, and optional Android Auto integration.

Example:

final player = await MtAudioPlayer.init(
  config: MtAudioPlayerConfig(
    notificationChannelId: 'audio',
    notificationChannelName: 'Audio Playback',
  ),
);

// Set audio source
await player.setAudioItem(MtAudioItem(
  id: '1',
  uri: Uri.parse('https://example.com/audio.mp3'),
  title: 'My Audio',
));

// Listen to state
player.playbackStateStream.listen((state) {
  print('Playing: ${state.isPlaying}');
});

// Control playback
await player.play();

Properties

carPlay MtCarPlayHandler?
CarPlay handler for Apple CarPlay integration.
no setter
currentItem MtAudioItem?
Currently playing item (null if none).
no setter
currentItemStream Stream<MtAudioItem?>
Stream of current item changes.
no setter
currentPlaybackState MtPlaybackState
Current playback state.
no setter
currentPositionState MtPositionState
Current position state.
no setter
currentQueueState MtQueueState
Current queue state.
no setter
errorStream Stream<MtAudioError?>
Stream of errors.
no setter
hashCode int
The hash code for this object.
no setterinherited
icyMetadataStream Stream<IcyMetadata?>
Stream of ICY metadata changes (for live streams).
no setter
playbackStateStream Stream<MtPlaybackState>
Stream of playback state changes.
no setter
positionStateStream Stream<MtPositionState>
Stream of position state changes.
no setter
queueStateStream Stream<MtQueueState>
Stream of queue state changes.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addToQueue(MtAudioItem item) Future<void>
Adds an item to the end of the queue.
clearQueue() Future<void>
Clears the entire queue.
dispose() Future<void>
Disposes of the player and releases all resources.
insertInQueue(int index, MtAudioItem item) Future<void>
Inserts an item at the specified index in the queue.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pause() Future<void>
Pauses playback.
play() Future<void>
Starts or resumes playback.
removeFromQueue(int index) Future<void>
Removes an item from the queue at the specified index.
reorderQueue(int oldIndex, int newIndex) Future<void>
Reorders queue items.
seekBackward() Future<void>
Seeks backward by the configured interval.
seekForward() Future<void>
Seeks forward by the configured interval.
seekTo(Duration position) Future<void>
Seeks to the specified position.
setAudioItem(MtAudioItem item) Future<void>
Sets a single audio item as the source and replaces the current queue.
setPlaylist(List<MtAudioItem> items, {int initialIndex = 0}) Future<void>
Sets a playlist as the source and replaces the current queue.
setRepeatMode(MtRepeatMode mode) Future<void>
Sets the repeat mode.
setShuffleMode(bool enabled) Future<void>
Sets whether shuffle is enabled.
setSpeed(double speed) Future<void>
Sets the playback speed.
setVolume(double volume) Future<void>
Sets the player volume (0.0 to 1.0).
skipToIndex(int index) Future<void>
Skips to the item at the specified index.
skipToNext() Future<void>
Skips to the next item in the queue.
skipToPrevious() Future<void>
Skips to the previous item in the queue.
stop() Future<void>
Stops playback and releases resources.
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

init({required MtAudioPlayerConfig config}) Future<MtAudioPlayer>
Initializes the audio player.