Fix download button centering and width, fix audio/video loading by using blob URLs for web
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import '../theme/app_theme.dart';
|
||||
import '../services/api_client.dart';
|
||||
import '../injection.dart';
|
||||
@@ -97,7 +98,24 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
||||
Future<void> _initializeVideoPlayer() async {
|
||||
final url = _fileData?['viewUrl'] ?? _fileData?['downloadUrl'];
|
||||
if (url != null) {
|
||||
_videoController = VideoPlayerController.networkUrl(Uri.parse(url));
|
||||
String videoUrl = url;
|
||||
if (kIsWeb) {
|
||||
// For web, fetch bytes and create blob URL to avoid CORS issues
|
||||
try {
|
||||
final apiClient = getIt<ApiClient>();
|
||||
final uri = Uri.parse(url);
|
||||
final path = uri.path + (uri.query.isNotEmpty ? '?${uri.query}' : '');
|
||||
final bytes = await apiClient.getBytes(path);
|
||||
final mimeType =
|
||||
_fileData?['capabilities']?['mimeType'] ?? 'video/mp4';
|
||||
final blob = web.Blob([bytes], mimeType);
|
||||
videoUrl = web.URL.createObjectURL(blob);
|
||||
} catch (e) {
|
||||
// Fallback to direct URL
|
||||
videoUrl = url;
|
||||
}
|
||||
}
|
||||
_videoController = VideoPlayerController.networkUrl(Uri.parse(videoUrl));
|
||||
await _videoController!.initialize();
|
||||
setState(() {});
|
||||
}
|
||||
@@ -192,6 +210,7 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
||||
child: AudioPlayerBar(
|
||||
fileName: _fileData!['fileName'] ?? 'Audio',
|
||||
fileUrl: viewUrl,
|
||||
mimeType: _fileData?['capabilities']?['mimeType'],
|
||||
),
|
||||
);
|
||||
} else if (_isDocumentFile()) {
|
||||
@@ -266,10 +285,13 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
||||
elevation: 0,
|
||||
leading: _fileData != null
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(left: 16, top: 4),
|
||||
child: ModernGlassButton(
|
||||
onPressed: _downloadFile,
|
||||
child: const Icon(Icons.download, size: 18),
|
||||
padding: const EdgeInsets.only(left: 16),
|
||||
child: SizedBox(
|
||||
width: 56,
|
||||
child: ModernGlassButton(
|
||||
onPressed: _downloadFile,
|
||||
child: const Icon(Icons.download, size: 18),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
|
||||
Reference in New Issue
Block a user