Fix local folder playback after app container UUID changes

After iOS reinstall/restore the app container UUID rotates, which left both
the persisted source.url and the security-scoped bookmark pointing at a
no-longer-current path. Files derived a stale absolute path that got appended
onto the resolved bookmark, producing doubled URLs that MPV could not load.

- Resolve the base URL by picking whichever of the bookmark or source.url
  actually exists on disk.
- Compute MediaFile relative paths against the resolved root so they survive
  later container changes.
- Hold the security-scoped resource access for the source's lifetime via a
  shared resolver, so MPV can open files long after the directory enumeration
  that resolved the bookmark has returned.
- Normalize legacy absolute paths embedded in old recents/history video IDs
  so they re-resolve under the current container.
This commit is contained in:
Arkadiusz Fal
2026-05-08 18:23:16 +02:00
parent 5d88ed9743
commit b7b7c5ac62
3 changed files with 161 additions and 24 deletions

View File

@@ -67,7 +67,14 @@ struct MediaFile: Identifiable, Hashable, Sendable {
/// Full URL to this file.
var url: URL {
source.url.appendingPathComponent(path)
// For local folders, the persisted `source.url` may point at a stale app
// container path after iOS reinstall/restore. Prefer the freshly resolved
// bookmark URL stored in `LocalFolderURLResolver` when available.
if source.type == .localFolder,
let resolved = LocalFolderURLResolver.resolvedURL(for: source.id) {
return resolved.appendingPathComponent(path)
}
return source.url.appendingPathComponent(path)
}
/// File extension (lowercase).