audio_service
0.18.19, released 5 months ago by ryanheise.com
Flutter plugin for background audio playback with media controls.
What it does
Provides a way to run audio code in the background while the screen is off. It exposes a standard AudioHandler API that forwards media actions to your own player implementation and updates system notifications, lock screen, headset buttons and Android Auto/Apple CarPlay.
AI-written summary of version 0.18.19, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need background audio that continues when the app is minimized or the screen is locked
- You want system media controls, notifications, lock‑screen or Android Auto integration
- You need a unified API that works on Android, iOS, web and macOS
Skip it when
- Your app only plays short foreground sounds and doesn’t need background playback
- You prefer a zero‑native‑code solution for simple audio
- You already use a full‑featured media player that handles its own background service
Strengths
- Full platform support (Android, iOS, web, macOS, Linux via MPRIS)
- Works with any audio engine (just_audio, flutter_tts, etc.)
- Rich feature set: queue, shuffle, repeat, custom actions, lock‑screen UI
Weaknesses
- Requires native configuration (Android manifest, iOS background modes)
- Adds complexity compared to plain audio players
- May be overkill for simple use‑cases
Setup
- Kind
- Plugin (native code)
- Effort
- Medium
- Code generation
- No
- Direct dependencies
- 7
Add Android permissions and notification channel in AndroidManifest.xml, enable Background Modes (Audio) in Xcode, configure AudioServiceConfig with channel IDs, and ensure a compatible audio player (e.g., just_audio) is used inside the AudioHandler.
import 'package:audio_service/audio_service.dart';
import 'package:just_audio/just_audio.dart';
class MyAudioHandler extends BaseAudioHandler with QueueHandler, SeekHandler {
final _player = AudioPlayer();
@override Future<void> play() => _player.play();
@override Future<void> pause() => _player.pause();
@override Future<void> stop() => _player.stop();
@override Future<void> seek(Duration position) => _player.seek(position);
}
Future<void> main() async {
final audioHandler = await AudioService.init(
builder: () => MyAudioHandler(),
config: AudioServiceConfig(
androidNotificationChannelId: 'com.example.channel.audio',
androidNotificationChannelName: 'Audio Playback',
),
);
runApp(MyApp());
}Alternatives
Packages that do the same job and could replace audio_service.
- audioplayers
Simple API for playing short sounds without native background setup
87Compare
Works with
Packages commonly used together with audio_service: ones it builds on, ones built on it, and its own family.
- clockaudio_service depends on itA fakeable wrapper for dart:core clock APIs.
- rxdartaudio_service depends on itImplementation of the ReactiveX API for asynchronous programming leveraging native Dart Streams.
- flutter_cache_manageraudio_service depends on itGeneric cache manager for saving web files and cache info on device storage.
- audio_sessionaudio_service depends on itManages iOS audio session categories, Android audio attributes, and audio focus/ducking.
- audio_service_platform_interfaceaudio_service depends on itPlatform interface for the audio_service plugin
- just_audioSame familyFeature‑rich audio player for Flutter supporting gapless playlists and multiple sources
- just_audio_backgroundBuilt on audio_serviceAdds background playback and media controls to a just_audio player
- quran_libraryBuilt on audio_serviceAn integrated package for displaying the Holy Qur’an identical to the Medina Quran with the narration of Hafs on the authority of Asim.