This commit is contained in:
Leon Bösche
2026-01-17 02:20:10 +01:00
parent 712abbb34f
commit 979091f975

View File

@@ -47,6 +47,7 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
super.dispose();
}
String? _errorMsg;
Future<void> _initAudio() async {
try {
await _audioPlayer.setUrl(widget.fileUrl);
@@ -56,9 +57,22 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
_duration = d ?? Duration.zero;
_isLoading = false;
});
await _audioPlayer.play(); // Start playback automatically
// Animate play icon
if (mounted) _iconController.forward();
try {
await _audioPlayer.play(); // Start playback automatically
if (_audioPlayer.playerState.playing) {
if (mounted) _iconController.forward();
} else {
setState(() {
_errorMsg = 'Audio could not be played.';
});
}
} catch (e) {
setState(() {
_errorMsg =
'Audio playback error: ' +
(e is Exception ? e.toString() : 'Unknown error');
});
}
});
_audioPlayer.positionStream.listen((pos) {
setState(() {
@@ -73,6 +87,9 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
} catch (e) {
setState(() {
_isLoading = false;
_errorMsg =
'Audio load error: ' +
(e is Exception ? e.toString() : 'Unknown error');
});
}
}
@@ -98,7 +115,7 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
height: 48,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: AppTheme.glassDecoration.copyWith(
borderRadius: BorderRadius.circular(24),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: AppTheme.accentColor.withValues(alpha: 0.15),
@@ -114,7 +131,6 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
// Play/Pause button (AnimatedIcon)
ModernGlassButton(
onPressed: _isLoading ? () {} : _handlePlayPause,
child: AnimatedIcon(
icon: AnimatedIcons.play_pause,
progress: _iconController,
@@ -172,6 +188,18 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
),
),
),
if (_errorMsg != null)
Padding(
padding: const EdgeInsets.only(top: 2.0),
child: Text(
_errorMsg!,
style: const TextStyle(
color: Colors.red,
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
@@ -191,7 +219,6 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
padding: const EdgeInsets.only(left: 8.0),
child: ModernGlassButton(
onPressed: widget.onClose!,
child: const Icon(
Icons.close,
color: AppTheme.primaryText,