~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

iOS: a video whose HLS fails goes on from the blob proxy

Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:ios/video-fallback
docs/internals.md+1−1
@@ -67,7 +67,7 @@ The service's DID document gives the endpoint of the service that its fragment n
Blob refs in an answer get URLs where HUD knows the repository holding them. That's the case for a record beside the `uri` naming it. Images go through the image CDN when HUD asks as no one or asks the AppView. Otherwise they go through the proxy alone.
Every video the answer shows (`app.bsky.embed.video#view`) gets a `url` of its blob from the proxy, in the repository of the post around it. Its own playlist, HLS on Bluesky's video service (`video.bsky.app`, its segments on `video.cdn.bsky.app`), is adaptive and served from a CDN, so the resolved tree gives it too (`hls`). Where the platform plays HLS natively (iOS, Safari, Chrome), the video plays from there. Elsewhere (Firefox) it plays the blob from the proxy, and the view never loads hls.js.
Every video the answer shows (`app.bsky.embed.video#view`) gets a `url` of its blob from the proxy, in the repository of the post around it. Its own playlist, HLS on Bluesky's video service (`video.bsky.app`, its segments on `video.cdn.bsky.app`), is adaptive and served from a CDN, so the resolved tree gives it too (`hls`). Where the platform plays HLS natively (iOS, Safari, Chrome), the video plays from there. Elsewhere (Firefox) it plays the blob from the proxy, and the view never loads hls.js. Where the HLS fails, the web falls back to the proxy as a second source, and iOS goes on from the proxy where the HLS stopped.
HUD makes calls as no one. When signed in, it makes them through the account's PDS, which proxies them to the service (`atproto-proxy`), for the services its sign-in asks to call ([sign-in](sign-in.md#what-hud-asks-for)).
ios/HUDKit/Sources/HUDKit/Embed/EmbedVideo.swift+20−3
@@ -1,12 +1,13 @@
import AVKit
import Combine
import SwiftUI
// A post's video, as a resolved tree's Embed gives it, shaped by its aspect
// ratio before it loads: the system's player, loading nothing until it is
// played, its poster drawn first, over Bluesky's HLS (`hls`), adaptive and
// from its CDN, else the server's blob proxy (`src`). With neither (a
// server that cannot reach it), the poster and a link to watch it on
// Bluesky.
// from its CDN, else the server's blob proxy (`src`); where the HLS fails,
// the proxy goes on from where it was. With neither (a server that cannot
// reach it), the poster and a link to watch it on Bluesky.
struct EmbedVideo: View {
/// What a video shows: where it plays from, its poster, shape and alt
@@ -39,6 +40,7 @@ struct EmbedVideo: View {
if let player {
VideoPlayer(player: player)
.accessibilityLabel(alt)
.task(id: ObjectIdentifier(player)) { await fallBack(player) }
} else {
Picture(source: poster, alt: alt, fit: .fit, placeholder: "Video")
Button {
@@ -76,4 +78,19 @@ struct EmbedVideo: View {
}
.onDisappear { player?.pause() }
}
/// Where `player` plays the HLS and it fails, play the proxy's stream
/// in its place, from where it was.
private func fallBack(_ player: AVPlayer) async {
guard shown.hls != nil, let src = shown.src, let item = player.currentItem else { return }
// `first(where:)` takes every status as it comes: a KVO publisher drops
// what changes while nothing asks for it.
let failed = item.publisher(for: \.status).first(where: { $0 == .failed }).values
for await _ in failed {
let at = item.currentTime()
player.replaceCurrentItem(with: AVPlayerItem(url: src))
await player.seek(to: at)
player.play()
}
}
}