diff --git a/lib/controls/audio_video/media_kit_av_control.dart b/lib/controls/audio_video/media_kit_av_control.dart index ecaa3ab..347e969 100644 --- a/lib/controls/audio_video/media_kit_av_control.dart +++ b/lib/controls/audio_video/media_kit_av_control.dart @@ -57,13 +57,13 @@ class _MediaKitAvControlState extends State { super.deactivate(); } - void toggleVideoPlay() async { + Future toggleVideoPlay() async { _logger.fine('Toggling play on: ${widget.videoUrl}'); if (needToOpen) { await player.open(Media(widget.videoUrl), play: false); needToOpen = false; } - player.playOrPause(); + await player.playOrPause(); setState(() {}); } @@ -81,6 +81,7 @@ class _MediaKitAvControlState extends State { @override Widget build(BuildContext context) { print('Building MediaKit Control'); + final playing = player.state.playing; if (controller == null) { return Container( width: widget.width, @@ -111,7 +112,7 @@ class _MediaKitAvControlState extends State { Row( children: [ IconButton( - icon: player.state.playing + icon: playing ? const Icon(Icons.pause) : const Icon(Icons.play_arrow), onPressed: toggleVideoPlay, diff --git a/lib/screens/media_viewer_screen.dart b/lib/screens/media_viewer_screen.dart index aed0383..f5af423 100644 --- a/lib/screens/media_viewer_screen.dart +++ b/lib/screens/media_viewer_screen.dart @@ -9,6 +9,7 @@ import 'package:path_provider/path_provider.dart'; import '../controls/login_aware_cached_network_image.dart'; import '../friendica_client/friendica_client.dart'; import '../globals.dart'; +import '../models/attachment_media_type_enum.dart'; import '../models/media_attachment.dart'; import '../services/auth_service.dart'; import '../utils/clipboard_utils.dart'; @@ -98,12 +99,37 @@ class _MediaViewerScreenState extends State { final descriptionHeightPct = widget.attachments.isEmpty ? 0.0 : 0.1; final mediaHeight = height * (1 - descriptionHeightPct); final descriptionHeight = height * descriptionHeightPct; + + late final bool canSave; + late final Widget mediaViewer; + switch (currentAttachment.explicitType) { + case AttachmentMediaType.image: + canSave = true; + mediaViewer = SizedBox( + width: width, + height: mediaHeight, + child: InteractiveViewer( + maxScale: 10.0, + scaleFactor: 400, + child: LoginAwareCachedNetworkImage( + imageUrl: currentAttachment.uri.toString()), + )); + break; + case AttachmentMediaType.unknown: + case AttachmentMediaType.video: + canSave = false; + mediaViewer = Text( + 'No media viewer for ${currentAttachment.explicitType.name} type for link ${currentAttachment.fullFileUri}'); + break; + } + return Scaffold( appBar: AppBar( actions: [ - IconButton( - onPressed: () => saveImage(context, currentAttachment), - icon: const Icon(Icons.download)) + if (canSave) + IconButton( + onPressed: () => saveImage(context, currentAttachment), + icon: const Icon(Icons.download)) ], ), body: SafeArea( @@ -112,16 +138,7 @@ class _MediaViewerScreenState extends State { Column( mainAxisAlignment: MainAxisAlignment.start, children: [ - SizedBox( - width: width, - height: mediaHeight, - child: InteractiveViewer( - maxScale: 10.0, - scaleFactor: 400, - child: LoginAwareCachedNetworkImage( - imageUrl: currentAttachment.uri.toString()), - ), - ), + mediaViewer, if (currentAttachment.description.isNotEmpty) buildTextArea(currentAttachment, descriptionHeight), ],