diff --git a/app/lib/features/artifacts/domain/artifact_preview.dart b/app/lib/features/artifacts/domain/artifact_preview.dart index f60b39ae..728efe12 100644 --- a/app/lib/features/artifacts/domain/artifact_preview.dart +++ b/app/lib/features/artifacts/domain/artifact_preview.dart @@ -8,7 +8,11 @@ enum ArtifactPreviewKind { text, markdown, - /// A recorded file the viewer cannot draw (video, CSV, archives, ...). + /// A same-origin video, played in the viewer from its resolved url (never + /// fetched as bytes, never autoplayed), as the web viewer does. + video, + + /// A recorded file the viewer cannot draw (CSV, archives, ...). unsupported, /// No safe same-origin url to fetch: absent, unsafe or another origin. @@ -52,9 +56,9 @@ const String artifactPreviewExternalUrl = /// Classifies [artifact] against the configured server origin. /// -/// Images are drawn from the resolved bytes; `text/plain` is selectable text; a -/// `.md`/`.markdown` name or `text/markdown` is handed to the injected markdown -/// builder. Everything else is explicitly unsupported rather than faked. +/// Images are drawn from the resolved bytes; a video plays from the resolved +/// url; `text/plain` is selectable text; a `.md`/`.markdown` name or +/// `text/markdown` is handed to the injected markdown builder. Everything else is explicitly unsupported rather than faked. ArtifactPreviewPlan planArtifactPreview({ required ArtifactRecord artifact, required String configuredEndpoint, @@ -89,6 +93,13 @@ ArtifactPreviewPlan planArtifactPreview({ message: '', ); } + if (isVideoContentType(mime)) { + return ArtifactPreviewPlan( + kind: ArtifactPreviewKind.video, + resolved: resolved, + message: '', + ); + } if (mime == 'text/markdown' || _isMarkdownName(artifact.name)) { return ArtifactPreviewPlan( kind: ArtifactPreviewKind.markdown, diff --git a/app/lib/features/artifacts/ui/artifact_video_player.dart b/app/lib/features/artifacts/ui/artifact_video_player.dart new file mode 100644 index 00000000..f7617dfa --- /dev/null +++ b/app/lib/features/artifacts/ui/artifact_video_player.dart @@ -0,0 +1,145 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:video_player/video_player.dart'; + +import '../../../ui/adaptive/host.dart'; + +/// Creates the player for one video url; tests inject a fake controller. +typedef ArtifactVideoControllerFactory = + VideoPlayerController Function(Uri uri); + +VideoPlayerController defaultArtifactVideoController(Uri uri) => + VideoPlayerController.networkUrl(uri); + +const String artifactVideoPlayLabel = 'Play video'; +const String artifactVideoPauseLabel = 'Pause video'; +const String artifactVideoError = 'The video could not be played.'; + +/// Plays one recorded same-origin video in the viewer, as the web viewer's +/// `