Overview
TheAudiobookPlayer screen is a full-screen audio player interface that provides comprehensive playback controls, sleep timer functionality, equalizer settings, track selection, and Chromecast support. It displays the currently playing audiobook with cover art, metadata, and interactive controls.
File Location: lib/screens/audiobook_player/audiobook_player.dart
Purpose and Functionality
The AudiobookPlayer screen provides:- Full-screen playback interface with modern glassmorphism design
- Real-time playback progress tracking and seeking
- Sleep timer with preset durations and end-of-track option
- Audio equalizer with customizable presets
- Track/chapter selection dialog
- Chromecast integration for remote playback
- Skip silence functionality
- Background playback support with notifications
- Adaptive UI for single-track vs multi-track audiobooks
Key Components
Services and Providers
State Management
Uses ValueNotifiers and StreamSubscriptions for reactive UI updates:Global Keys
Widget Structure
The screen uses aStreamBuilder<MediaItem?> to reactively rebuild when the current track changes:
-
App Bar (dark theme with artwork thumbnail)
- Mini cover art thumbnail
- Track title and artist/author
- Chromecast button
- Equalizer button
- Track list button
- Collapse button
-
Body (gradient background)
- Large cover art with hero animation (280x280)
- Title section with proper typography
- Album name (for multi-track audiobooks)
- Artist/author name
- Progress bar with seek functionality
- Controls container (glassmorphism card)
- Playback controls
- Speed control
- Sleep timer button
- Skip silence toggle
Sleep Timer Functionality
Timer Durations
Predefined timer options:Starting a Timer
End-of-Track Timer
Canceling Timer
Code Examples
Artwork Helpers (Local and Remote)
Track Selection Dialog
Equalizer Dialog
Timer Options Bottom Sheet
Adaptive Title Display
Controls with Nested ValueListenableBuilders
Lifecycle Management
Initialization
Dependency Injection
Disposal
Dependencies
audio_service- Background audio playbackprovider- Dependency injectionhive- Local storagewe_slide- Sliding panel containercached_network_image- Image caching and displayflutter_background- Background execution for timer
Custom Widgets Used
Controls- Main playback control widgetProgressBarWidget- Seekable progress barEqualizerIcon- Dynamic equalizer icon indicatorEqualizerDialog- Equalizer settings dialogTrackSelectionDialog- Chapter/track selection dialogChromeCastButton- Chromecast connectivity button
Audio Service Integration
The player integrates deeply withMyAudioHandler (custom AudioHandler implementation):
audioHandler.initSongs()- Initialize playlistaudioHandler.play()- Start playbackaudioHandler.pause()- Pause playbackaudioHandler.setSkipSilence()- Toggle silence skippingaudioHandler.getPositionStream()- Real-time position updatesaudioHandler.mediaItem- Current track metadata streamaudioHandler.chromeCastService- Chromecast integration
Background Execution
Usesflutter_background package to maintain timer functionality when app is backgrounded:
- Displays persistent notification while timer is active
- Pauses playback when timer expires (even in background)
- Properly cleans up background execution when timer completes or is canceled