A feature-rich, customizable audio player package for Flutter applications. This package provides a simple API for playing audio tracks and playlists with a beautiful, customizable UI.
- 🎵 Play single tracks or playlists
- 🎮 Full playback controls (play, pause, stop, seek, next, previous)
- 🎨 Customizable UI components
- 📱 Background playback with notification controls
- 🧩 BLoC state management
- 📦 Easy to integrate
Add this to your package's pubspec.yaml file:
dependencies:
audio_player_package: ^1.0.0Or use the following command:
flutter pub add audio_player_packagefinal player = await AdvancedAudioPlayer.initialize(
androidNotificationChannelId: 'com.example.audio_player',
androidNotificationChannelName: 'Audio Player',
androidNotificationOngoing: true,
);final track = AudioTrack(
id: '1',
title: 'Song Title',
artist: 'Artist Name',
album: 'Album Name',
url: 'https://example.com/song.mp3',
artUri: 'https://example.com/cover.jpg',
);
player.playTrack(track);final playlist = Playlist(
id: 'playlist1',
name: 'My Playlist',
tracks: [track1, track2, track3],
);
player.playPlaylist(playlist);// Toggle play/pause
player.playPause();
// Stop playback
player.stop();
// Skip to next track
player.next();
// Skip to previous track
player.previous();
// Seek to position
player.seek(Duration(seconds: 30));
// Set volume (0.0 to 1.0)
player.setVolume(0.7);
// Set repeat mode
player.setRepeatMode(AudioServiceRepeatMode.all);
// Set shuffle mode
player.setShuffleMode(AudioServiceShuffleMode.all);AdvancedAudioPlayer.createBlocProvider(
player: player,
child: Scaffold(
body: Center(
child: AdvancedAudioPlayer.createAudioPlayerWidget(
primaryColor: Colors.blue,
backgroundColor: Colors.grey[200],
height: 200,
showCoverArt: true,
showQueue: false,
),
),
),
);AdvancedAudioPlayer.createBlocProvider(
player: player,
child: Scaffold(
bottomNavigationBar: AdvancedAudioPlayer.createMiniPlayerWidget(
primaryColor: Colors.blue,
backgroundColor: Colors.white,
onTap: () {
// Navigate to full player screen
},
),
),
);The package provides highly customizable player widgets that allow you to change icons, colors, styles, and more:
AdvancedAudioPlayer.createCustomAudioPlayerWidget(
primaryColor: Colors.purple,
backgroundColor: Colors.grey[200],
height: 250,
playIcon: Icons.play_circle_filled,
pauseIcon: Icons.pause_circle_filled,
nextIcon: Icons.skip_next_rounded,
previousIcon: Icons.skip_previous_rounded,
stopIcon: Icons.stop_circle,
shuffleIcon: Icons.shuffle_on,
shuffleOffIcon: Icons.shuffle,
repeatIcon: Icons.repeat,
repeatOneIcon: Icons.repeat_one,
repeatOffIcon: Icons.repeat,
titleStyle: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.purple,
),
artistStyle: TextStyle(
fontSize: 14,
color: Colors.grey[700],
),
sliderActiveColor: Colors.purpleAccent,
sliderInactiveColor: Colors.grey[300],
sliderThumbColor: Colors.purple,
onTrackChanged: (track) {
// Handle track change
},
onPlayStateChanged: (isPlaying) {
// Handle play state change
},
);AdvancedAudioPlayer.createCustomMiniPlayerWidget(
primaryColor: Colors.teal,
backgroundColor: Colors.teal[50],
height: 80,
playIcon: Icons.play_arrow_rounded,
pauseIcon: Icons.pause_rounded,
titleStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.teal,
),
artistStyle: TextStyle(
fontSize: 12,
color: Colors.grey[700],
),
borderRadius: BorderRadius.circular(16),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
onTap: () {
// Show full player or navigate to player screen
},
);final bloc = player.bloc;
// Listen to state changes
bloc.stream.listen((state) {
if (state is AudioPlayerReady) {
// Handle ready state
}
});
// Dispatch events
bloc.add(PlayTrack(track));Check out the example app in the example directory for a complete implementation.
This project is licensed under the MIT License - see the LICENSE file for details.