Enhance audio file handling with improved error logging and UI adjustments for audio player bar positioning

This commit is contained in:
Leon Bösche
2026-01-17 02:31:33 +01:00
parent 979091f975
commit d9a651b375
4 changed files with 54 additions and 37 deletions

View File

@@ -1178,20 +1178,30 @@ class _FileExplorerState extends State<FileExplorer>
}
}
} else if (audioExts.contains(ext)) {
if (file.id == null || file.id!.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Error: File ID is missing')),
try {
if (file.id == null || file.id!.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Error: File ID is missing')),
);
return;
}
final fileService = getIt<FileService>();
final url = await fileService.getFileUrl(
orgId: widget.orgId,
fileId: file.id!,
fileName: file.name,
);
return;
}
final fileService = getIt<FileService>();
final url = await fileService.getFileUrl(
orgId: widget.orgId,
fileId: file.id!,
fileName: file.name,
);
if (widget.onAudioFileSelected != null) {
widget.onAudioFileSelected!(file.name, url);
// ignore: avoid_print
print('[FileExplorer] Audio URL: $url');
if (widget.onAudioFileSelected != null) {
widget.onAudioFileSelected!(file.name, url);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error loading audio: $e')),
);
}
}
} else {
if (file.id == null || file.id!.isEmpty) {

View File

@@ -440,6 +440,24 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
},
),
),
// Audio player bar (positioned to the right of title)
if (_showAudioBar &&
_audioFileName != null &&
_audioFileUrl != null)
Positioned(
right: -200, // adjust to position next to title
child: SlideTransition(
position: _audioBarOffset,
child: AudioPlayerBar(
fileName: _audioFileName!,
fileUrl: _audioFileUrl!,
onClose: () {
_audioBarController.reverse();
setState(() => _showAudioBar = false);
},
),
),
),
// Right: nav buttons
Align(
alignment: Alignment.centerRight,
@@ -473,28 +491,6 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
),
),
),
// Audio player bar (absolute, below title)
if (_showAudioBar &&
_audioFileName != null &&
_audioFileUrl != null)
Positioned(
top: 56, // adjust as needed for spacing below top bar
left: 0,
right: 0,
child: SlideTransition(
position: _audioBarOffset,
child: Center(
child: AudioPlayerBar(
fileName: _audioFileName!,
fileUrl: _audioFileUrl!,
onClose: () {
_audioBarController.reverse();
setState(() => _showAudioBar = false);
},
),
),
),
),
Center(
child: BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {

View File

@@ -49,6 +49,9 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
String? _errorMsg;
Future<void> _initAudio() async {
// Log the file URL for debugging
// ignore: avoid_print
print('[AudioPlayerBar] Loading audio URL: ${widget.fileUrl}');
try {
await _audioPlayer.setUrl(widget.fileUrl);
// Wait until duration is available
@@ -65,13 +68,17 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
setState(() {
_errorMsg = 'Audio could not be played.';
});
// ignore: avoid_print
print('[AudioPlayerBar] ERROR: Audio could not be played.');
}
} catch (e) {
} catch (e, st) {
setState(() {
_errorMsg =
'Audio playback error: ' +
(e is Exception ? e.toString() : 'Unknown error');
});
// ignore: avoid_print
print('[AudioPlayerBar] Playback error: $e\n$st');
}
});
_audioPlayer.positionStream.listen((pos) {
@@ -84,13 +91,15 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
_isPlaying = state.playing;
});
});
} catch (e) {
} catch (e, st) {
setState(() {
_isLoading = false;
_errorMsg =
'Audio load error: ' +
(e is Exception ? e.toString() : 'Unknown error');
});
// ignore: avoid_print
print('[AudioPlayerBar] Load error: $e\n$st');
}
}

View File

@@ -1851,6 +1851,7 @@ func downloadOrgFileHandler(w http.ResponseWriter, r *http.Request, db *database
// which supports all common video/audio/image formats
contentType := getMimeType(fileName)
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", fileName))
w.Header().Set("Content-Type", contentType)
w.Header().Set("Accept-Ranges", "bytes")
@@ -1998,6 +1999,7 @@ func downloadUserFileHandler(w http.ResponseWriter, r *http.Request, db *databas
// which supports all common video/audio/image formats
contentType := getMimeType(fileName)
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", fileName))
w.Header().Set("Content-Type", contentType)
w.Header().Set("Accept-Ranges", "bytes")