diff --git a/b0esche_cloud/lib/widgets/audio_player_bar.dart b/b0esche_cloud/lib/widgets/audio_player_bar.dart index 5ce5703..0839ea1 100644 --- a/b0esche_cloud/lib/widgets/audio_player_bar.dart +++ b/b0esche_cloud/lib/widgets/audio_player_bar.dart @@ -47,6 +47,7 @@ class _AudioPlayerBarState extends State super.dispose(); } + String? _errorMsg; Future _initAudio() async { try { await _audioPlayer.setUrl(widget.fileUrl); @@ -56,9 +57,22 @@ class _AudioPlayerBarState extends State _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 } catch (e) { setState(() { _isLoading = false; + _errorMsg = + 'Audio load error: ' + + (e is Exception ? e.toString() : 'Unknown error'); }); } } @@ -98,7 +115,7 @@ class _AudioPlayerBarState extends State 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 // Play/Pause button (AnimatedIcon) ModernGlassButton( onPressed: _isLoading ? () {} : _handlePlayPause, - child: AnimatedIcon( icon: AnimatedIcons.play_pause, progress: _iconController, @@ -172,6 +188,18 @@ class _AudioPlayerBarState extends State ), ), ), + 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 padding: const EdgeInsets.only(left: 8.0), child: ModernGlassButton( onPressed: widget.onClose!, - child: const Icon( Icons.close, color: AppTheme.primaryText,