Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(mobile): add video playback with native iOS controls #8919

Mergedjuliusmarmingemerged 6 commits intomain fromrefs/pull/8919/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

What Changed

Mobile video attachments currently open as files. This adds playback from received messages and local drafts, including the compact composer and new-task sheet.

  • iOS opens AVKit's full-screen player from the attachment thumbnail, with native playback controls, zoom, Close, and swipe dismissal. Received videos stream directly from their signed URL; there is no full-file download or app loading overlay before presentation.
  • Video tiles show cached thumbnails. The asset endpoint supports single byte ranges so native readers can fetch metadata, frames, and playback data without downloading the entire file first.
  • Touch and hold an iOS video attachment to save or share the original through the system sheet. Android uses an Expo Video modal with a save/share action. Draft file leases remain active through playback and sharing.
  • Preserve picker filenames and recognize video extensions when MIME metadata is generic. Web and mobile share that detection helper. The native source-view registration can be reused for image zoom transitions.

Why

Videos should be playable before and after sending. AVKit supplies the expected iOS controls and dismissal behavior, while byte-range delivery lets opening, seeking, and thumbnail extraction avoid waiting for a complete download.

UI Changes

Current iPhone 17 Pro / iOS 27 recording: thumbnail → streaming playback → native controls → swipe back → reopen → Close.

https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/5f0c0378d96a0fe5/ios-streaming-video-player.mp4

The screenshots compare an earlier player iteration on this branch with the final native player, using the same sample clip.

Before native UI refinementFinal iOS player
Earlier player with custom header and save/share footerFinal AVKit player with native controls

Validation

  • iOS 27 simulator: received and local-draft playback, thumbnails, autoplay, play/pause, Close/reopen, swipe dismissal, native sharing, and invalid-video recovery. A separate audio player remained playing through video presentation and dismissal.
  • A stalled stream opened and remained dismissible before any video bytes arrived. Throttled playback progressed before the file finished transferring. Two normal previews made zero full-file download calls.
  • Focused download/share, draft-lease, thumbnail, MIME-detection, and HTTP byte-range tests passed. Mobile and server typechecks, targeted lint, SwiftLint, and formatting passed. The picker suite includes a provider-URI regression and passes all 31 tests.
  • A matching development build is installed on the phone and launched against Metro. Phone playback still needs manual verification. Android, relay/tunnel transport, and physical audio routing were not runtime-tested.
Other observations from simulator testing

Saving to Files under a new filename passed with identical file bytes. Replacing an existing filename stalled on iOS 27, including with the original Expo Sharing path.

Sending a video from the new-task sheet uploaded it and received a reply, but left the cleared sheet open. The navigation call is unchanged; a runtime comparison with main was not performed.

Checklist

  • Changes are focused on video attachment playback and its supporting delivery/lifecycle code
  • I explained what changed and why
  • I included before/after screenshots for UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk Touches asset HTTP semantics for videos, native AVKit/audio-session behavior, and attachment file lifecycle; regressions could affect non-video downloads, older servers without ranges, or draft cleanup timing.

Overview Adds end-to-end mobile video attachments: playable tiles in the thread feed and composer, with iOS AVKit full-screen playback zooming from a registered thumbnail and Android using an expo-video modal.

Native iOS (T3NativeControls) exposes presentVideo / dismissVideo, a PresentationSource view for transition/share anchoring, and shareFileFromSource for popover share sheets. Playback streams remote signed URLs without a full download first; drafts use retain/release leases so files are not deleted during preview or share.

Supporting client work includes cached expo-video thumbnails, expo-document-picker for file picks, refactored download/share preview files, and shared videoMimeType in @t3tools/shared/video.

Server: video asset GETs honor single Range requests (206/416) so iOS can stream and extract frames; normal downloads and unsupported ranges still return the full file.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b6f497d2641811cb26def188166e52bfd67ea9a7. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add native iOS video playback, thumbnail caching, and byte-range asset serving

  • Adds T3NativeControls expo module that presents AVPlayerViewController (inline-to-fullscreen zoom, auto-play, audio session management, cleanup on dismiss) and presentVideo/dismissVideo/shareFileFromSource JS-callable functions; PresentationSource view registers source anchors for share and zoom transitions.
  • Adds videoThumbnails.ts that lazily imports expo-video to extract a single frame (≤480x480) with abort signaling, 15s timeout, and LRU cache capped at 32 entries; VideoThumbnailImage.tsx renders these lazily and cancels on unmount.
  • Adds assetFileResponse in the server asset route that serves 206 partial content with Content-Range/Accept-Ranges for video MIME types and 416 for unsatisfiable ranges; non-video assets and unsupported Range syntax fall back to full 200.
  • Integrates video into the composer and feed: video attachments render as VideoAttachmentTile with thumbnails and a long-press share menu on iOS; VideoPreviewModal resolves local draft files via loadLocalVideoPreview or remote URLs and presents the native player.
  • Refactors attachment download/share lifecycle around AttachmentPreviewFile with explicit share/dispose, switches file picking to expo-document-picker, and adds retain/release leases (retainComposerAttachmentFile) so preview/playback prevents premature file deletion.
  • Risk: pickComposerFiles now uses expo-document-picker (getDocumentAsync, copyToCacheDirectory) and consumes result.assets/mimeType instead of expo-file-system pickFileAsync fields; presentVideo rejects when the URL is not playable or a presentation is already active; video asset routes now return 416 for unsatisfiable ranges.
Macroscope summarized b6f497d.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: f64f2a38-cc80-4a15-a218-87973bd34b11

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Warning

      Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


      Comment `@coderabbitai help` to get the list of available commands.
    3. github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change

    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.3 KiB13.3 KiB−3 B (−0.0%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB+1 B (+0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.4 KiB6.4 KiB−4 B (−0.1%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.6 KiB55.6 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages10100 (0.0%)21✅
      ClaudeTotal thread wire13.3 KiB13.5 KiB+222 B (+1.6%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB−4 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.4 KiB6.6 KiB+226 B (+3.5%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded56.4 KiB57.9 KiB+1.5 KiB (+2.7%)66.4 KiB✅
      ClaudeLive turn messages911+2 (+22.2%)21✅

      Baseline: bba79cc · PR result: b6f497d · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor Bugbot Autofix is [ON](https://www.cursor.com/dashboard/bugbot), but a cloud agent failed to start. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b6f497d2641811cb26def188166e52bfd67ea9a7. Configure [here](https://www.cursor.com/dashboard/bugbot).
      apps/mobile/src/lib/videoThumbnails.ts line 44Resolvedby juliusmarminge
    6. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This is a large end-to-end mobile video feature spanning native iOS playback, Android playback, sharing, file retention, thumbnail extraction, document picking, and server byte-range delivery, with meaningful runtime side effects across existing paths. An unresolved concrete concern about rejected native thumbnail work after cancellation further warrants human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    7. juliusmarminge merged this31c1c59

    8. juliusmarminge closed this

Sign in to join this conversation.