flutter_audio_player_plugin 1.0.0%2B2

SDKflutter
Platformandroidios

A new Flutter Audio Player Plugin.

Flutter Audio Player Plugin

A comprehensive Flutter plugin that provides customizable audio player components with support for both single audio playback and playlist management. Built with modern Flutter architecture and extensive customization options.

Features

  • 🎵 Full Audio Player - Complete audio player with progress slider, time display, and controls
  • 🎧 Mini Player - Compact audio player for minimal UI footprint
  • 📱 Playlist Support - Handle multiple audio tracks with next/previous navigation
  • 🎨 Highly Customizable - Customize icons, colors, styles, and themes
  • 🔄 Stream-based Architecture - Real-time position updates and status changes
  • 📊 Progress Tracking - Visual progress slider with seek functionality
  • 🎯 Event Callbacks - Comprehensive callback system for all player events
  • 🖼️ Audio Artwork - Display audio artwork with customizable dimensions
  • Performance Optimized - Efficient state management and memory usage

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_audio_player_plugin: ^1.0.0

Quick Start

Basic Usage

import 'package:flutter_audio_player_plugin/flutter_audio_player_plugin.dart';

// Initialize the audio player
final audioPlayer = MethodChannelFlutterAudioPlayerPlugin();

// Create audio info
final audioInfo = AudioInfo(
  title: 'Song Title',
  artist: 'Artist Name',
  audioUrl: 'https://example.com/audio.mp3',
  picture: 'https://example.com/artwork.jpg',
);

// Use the player widget
Player(
  audioPlayer: audioPlayer,
  audioInfo: audioInfo,
)

Core Components

1. AudioInfo Model

The data model for audio metadata:

class AudioInfo {
  final String? audioUrl;    // Audio file URL
  final String? title;       // Song title
  final String? artist;      // Artist name
  final String? picture;     // Artwork URL
}

2. Player Widget

A full-featured audio player with progress slider and complete controls.

Props

PropTypeRequiredDescription
audioPlayerMethodChannelFlutterAudioPlayerPluginAudio player instance
audioInfoAudioInfo?Single audio information
audiosListList<AudioInfo>?List of audio tracks for playlist
iconStyleMap<String, dynamic>Icon styling properties
customizedIconsMap<PlayerIcons, IconData>Custom icons for controls
sliderStylesSliderThemeData?Progress slider styling
imageWidthdouble?Artwork width (default: 100.0)
imageHeightdouble?Artwork height (default: 100.0)
onPlayFunction()?Play event callback
onPauseFunction()?Pause event callback
onResumeFunction()?Resume event callback
onStopFunction()?Stop event callback
onPlayNextFunction()?Next track event callback
onPlayPreviousFunction()?Previous track event callback
onPositionChangedFunction(int)?Position change callback
onCompletionFunction()?Audio completion callback

Usage Examples

Single Audio Player:

Player(
  audioPlayer: audioPlayer,
  audioInfo: AudioInfo(
    title: 'My Song',
    artist: 'Artist Name',
    audioUrl: 'https://example.com/song.mp3',
    picture: 'https://example.com/artwork.jpg',
  ),
  onPlay: () => print('Audio started playing'),
  onPause: () => print('Audio paused'),
  onCompletion: () => print('Audio finished'),
)

Playlist Player:

Player(
  audioPlayer: audioPlayer,
  audiosList: [
    AudioInfo(title: 'Song 1', artist: 'Artist 1', audioUrl: 'url1'),
    AudioInfo(title: 'Song 2', artist: 'Artist 2', audioUrl: 'url2'),
    AudioInfo(title: 'Song 3', artist: 'Artist 3', audioUrl: 'url3'),
  ],
  onPlayNext: () => print('Next track'),
  onPlayPrevious: () => print('Previous track'),
)

3. MiniPlayer Widget

A compact audio player for minimal UI footprint.

Props

PropTypeRequiredDescription
audioPlayerMethodChannelFlutterAudioPlayerPluginAudio player instance
audioInfoAudioInfo?Single audio information
audiosListList<AudioInfo>?List of audio tracks
iconStyleMap<String, dynamic>Icon styling properties
customizedIconsMap<PlayerIcons, IconData>Custom icons
backgroundColorColorBackground color (default: Colors.black12)
onPlayFunction()?Play event callback
onPauseFunction()?Pause event callback
onResumeFunction()?Resume event callback
onStopFunction()?Stop event callback
onPlayNextFunction()?Next track callback
onPlayPreviousFunction()?Previous track callback
onPositionChangedFunction(int)?Position change callback
onCompletionFunction()?Completion callback

Usage Example

MiniPlayer(
  audioPlayer: audioPlayer,
  audioInfo: audioInfo,
  backgroundColor: Colors.grey[200],
  onPlay: () => print('Mini player started'),
)

4. PlayerControls Widget

Reusable audio control buttons component.

Props

PropTypeRequiredDescription
handlePlayPauseAudioFunction()Play/pause handler
handleStopAudioFunction()Stop handler
handleSeekBackwardFunction()Seek backward handler
handleSeekForwardFunction()Seek forward handler
handlePlayNextAudioFunction()Next track handler
handlePlayPreviousAudioFunction()Previous track handler
isPlayingboolCurrent playing state
iconStyleMap<String, dynamic>Icon styling
customizedIconsMap<PlayerIcons, IconData>Custom icons
isMinPlayerboolMini player mode (default: false)

5. AudioImage Widget

Displays audio artwork with customizable properties.

Props

PropTypeRequiredDescription
audioPictureStringImage URL
widthdoubleImage width (default: 700)
heightdoubleImage height (default: 200)
alignmentAlignmentImage alignment (default: center)
fitBoxFitImage fit (default: contain)

6. AppText Widget

Customizable text widget with default styling.

Props

PropTypeRequiredDescription
textStringText content
styleTextStyleText styling (default: 18px bold)

Customization

Icon Customization

Map<PlayerIcons, IconData> customIcons = {
  PlayerIcons.playIcon: Icons.play_arrow_outlined,
  PlayerIcons.pauseIcon: Icons.pause_outlined,
  PlayerIcons.skipPreviousIcon: Icons.skip_previous_outlined,
  PlayerIcons.skipNextIcon: Icons.skip_next_outlined,
  PlayerIcons.replay10Icon: Icons.replay_10_outlined,
  PlayerIcons.forward10: Icons.forward_10_outlined,
};

Player(
  audioPlayer: audioPlayer,
  audioInfo: audioInfo,
  customizedIcons: customIcons,
)

Icon Style Customization

Map<String, dynamic> iconStyle = {
  'color': Colors.blue,
  'iconSize': 45,
};

Player(
  audioPlayer: audioPlayer,
  audioInfo: audioInfo,
  iconStyle: iconStyle,
)

Slider Customization

SliderThemeData sliderTheme = SliderThemeData(
  trackHeight: 10.0,
  thumbShape: RoundSliderThumbShape(enabledThumbRadius: 8.0),
  overlayShape: RoundSliderOverlayShape(overlayRadius: 16.0),
  activeTrackColor: Colors.tealAccent,
  inactiveTrackColor: Colors.greenAccent,
  thumbColor: Colors.limeAccent,
);

Player(
  audioPlayer: audioPlayer,
  audioInfo: audioInfo,
  sliderStyles: sliderTheme,
)

Player Status

The plugin provides various player statuses through the PlayerStatus enum:

  • loading - Audio is loading
  • playing - Audio is currently playing
  • paused - Audio is paused
  • stopped - Audio is stopped
  • error - An error occurred
  • completed - Audio playback completed
  • idle - Player is idle
  • ready - Player is ready to play

Event Callbacks

All player components support comprehensive event callbacks:

Player(
  audioPlayer: audioPlayer,
  audioInfo: audioInfo,
  onPlay: () => print('Audio started'),
  onPause: () => print('Audio paused'),
  onResume: () => print('Audio resumed'),
  onStop: () => print('Audio stopped'),
  onPlayNext: () => print('Next track'),
  onPlayPrevious: () => print('Previous track'),
  onPositionChanged: (position) => print('Position: $position'),
  onCompletion: () => print('Audio completed'),
)

Example App

The example/ folder contains a complete demonstration app showcasing:

  • Basic player usage
  • Playlist functionality
  • Custom icon implementation
  • Style customization
  • Mini player usage
  • Event handling

To run the example:

cd example
flutter pub get
flutter run

Platform Support

  • ✅ Android
  • ✅ iOS
  • ✅ Web (with limitations)

Dependencies

  • Flutter SDK: >=3.3.0
  • Dart SDK: ^3.5.4
  • plugin_platform_interface: ^2.0.2

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please:

  1. Check the example app for usage patterns
  2. Review the documentation above
  3. Open an issue on GitHub with detailed information about your problem

Note: This plugin requires proper audio permissions on Android and iOS. Make sure to add the necessary permissions to your app's manifest files.