Enhance audio file handling with improved error logging and UI adjustments for audio player bar positioning
This commit is contained in:
@@ -1178,6 +1178,7 @@ class _FileExplorerState extends State<FileExplorer>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (audioExts.contains(ext)) {
|
} else if (audioExts.contains(ext)) {
|
||||||
|
try {
|
||||||
if (file.id == null || file.id!.isEmpty) {
|
if (file.id == null || file.id!.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Error: File ID is missing')),
|
const SnackBar(content: Text('Error: File ID is missing')),
|
||||||
@@ -1190,9 +1191,18 @@ class _FileExplorerState extends State<FileExplorer>
|
|||||||
fileId: file.id!,
|
fileId: file.id!,
|
||||||
fileName: file.name,
|
fileName: file.name,
|
||||||
);
|
);
|
||||||
|
// ignore: avoid_print
|
||||||
|
print('[FileExplorer] Audio URL: $url');
|
||||||
if (widget.onAudioFileSelected != null) {
|
if (widget.onAudioFileSelected != null) {
|
||||||
widget.onAudioFileSelected!(file.name, url);
|
widget.onAudioFileSelected!(file.name, url);
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Error loading audio: $e')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (file.id == null || file.id!.isEmpty) {
|
if (file.id == null || file.id!.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
|||||||
@@ -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
|
// Right: nav buttons
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
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(
|
Center(
|
||||||
child: BlocBuilder<AuthBloc, AuthState>(
|
child: BlocBuilder<AuthBloc, AuthState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
|
|
||||||
String? _errorMsg;
|
String? _errorMsg;
|
||||||
Future<void> _initAudio() async {
|
Future<void> _initAudio() async {
|
||||||
|
// Log the file URL for debugging
|
||||||
|
// ignore: avoid_print
|
||||||
|
print('[AudioPlayerBar] Loading audio URL: ${widget.fileUrl}');
|
||||||
try {
|
try {
|
||||||
await _audioPlayer.setUrl(widget.fileUrl);
|
await _audioPlayer.setUrl(widget.fileUrl);
|
||||||
// Wait until duration is available
|
// Wait until duration is available
|
||||||
@@ -65,13 +68,17 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
setState(() {
|
setState(() {
|
||||||
_errorMsg = 'Audio could not be played.';
|
_errorMsg = 'Audio could not be played.';
|
||||||
});
|
});
|
||||||
|
// ignore: avoid_print
|
||||||
|
print('[AudioPlayerBar] ERROR: Audio could not be played.');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e, st) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_errorMsg =
|
_errorMsg =
|
||||||
'Audio playback error: ' +
|
'Audio playback error: ' +
|
||||||
(e is Exception ? e.toString() : 'Unknown error');
|
(e is Exception ? e.toString() : 'Unknown error');
|
||||||
});
|
});
|
||||||
|
// ignore: avoid_print
|
||||||
|
print('[AudioPlayerBar] Playback error: $e\n$st');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_audioPlayer.positionStream.listen((pos) {
|
_audioPlayer.positionStream.listen((pos) {
|
||||||
@@ -84,13 +91,15 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
|||||||
_isPlaying = state.playing;
|
_isPlaying = state.playing;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e, st) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
_errorMsg =
|
_errorMsg =
|
||||||
'Audio load error: ' +
|
'Audio load error: ' +
|
||||||
(e is Exception ? e.toString() : 'Unknown error');
|
(e is Exception ? e.toString() : 'Unknown error');
|
||||||
});
|
});
|
||||||
|
// ignore: avoid_print
|
||||||
|
print('[AudioPlayerBar] Load error: $e\n$st');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1851,6 +1851,7 @@ func downloadOrgFileHandler(w http.ResponseWriter, r *http.Request, db *database
|
|||||||
// which supports all common video/audio/image formats
|
// which supports all common video/audio/image formats
|
||||||
contentType := getMimeType(fileName)
|
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-Disposition", fmt.Sprintf("inline; filename=\"%s\"", fileName))
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
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
|
// which supports all common video/audio/image formats
|
||||||
contentType := getMimeType(fileName)
|
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-Disposition", fmt.Sprintf("inline; filename=\"%s\"", fileName))
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
w.Header().Set("Accept-Ranges", "bytes")
|
||||||
|
|||||||
Reference in New Issue
Block a user