jetzaber
This commit is contained in:
@@ -47,6 +47,7 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? _errorMsg;
|
||||||
Future<void> _initAudio() async {
|
Future<void> _initAudio() async {
|
||||||
try {
|
try {
|
||||||
await _audioPlayer.setUrl(widget.fileUrl);
|
await _audioPlayer.setUrl(widget.fileUrl);
|
||||||
@@ -56,9 +57,22 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
_duration = d ?? Duration.zero;
|
_duration = d ?? Duration.zero;
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
await _audioPlayer.play(); // Start playback automatically
|
try {
|
||||||
// Animate play icon
|
await _audioPlayer.play(); // Start playback automatically
|
||||||
if (mounted) _iconController.forward();
|
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) {
|
_audioPlayer.positionStream.listen((pos) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -73,6 +87,9 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
|
_errorMsg =
|
||||||
|
'Audio load error: ' +
|
||||||
|
(e is Exception ? e.toString() : 'Unknown error');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +115,7 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
height: 48,
|
height: 48,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||||
decoration: AppTheme.glassDecoration.copyWith(
|
decoration: AppTheme.glassDecoration.copyWith(
|
||||||
borderRadius: BorderRadius.circular(24),
|
borderRadius: BorderRadius.circular(16),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: AppTheme.accentColor.withValues(alpha: 0.15),
|
color: AppTheme.accentColor.withValues(alpha: 0.15),
|
||||||
@@ -114,7 +131,6 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
// Play/Pause button (AnimatedIcon)
|
// Play/Pause button (AnimatedIcon)
|
||||||
ModernGlassButton(
|
ModernGlassButton(
|
||||||
onPressed: _isLoading ? () {} : _handlePlayPause,
|
onPressed: _isLoading ? () {} : _handlePlayPause,
|
||||||
|
|
||||||
child: AnimatedIcon(
|
child: AnimatedIcon(
|
||||||
icon: AnimatedIcons.play_pause,
|
icon: AnimatedIcons.play_pause,
|
||||||
progress: _iconController,
|
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),
|
padding: const EdgeInsets.only(left: 8.0),
|
||||||
child: ModernGlassButton(
|
child: ModernGlassButton(
|
||||||
onPressed: widget.onClose!,
|
onPressed: widget.onClose!,
|
||||||
|
|
||||||
child: const Icon(
|
child: const Icon(
|
||||||
Icons.close,
|
Icons.close,
|
||||||
color: AppTheme.primaryText,
|
color: AppTheme.primaryText,
|
||||||
|
|||||||
Reference in New Issue
Block a user