Repository navigation
fix(macos): replay an HLS clip from its end without a spurious end - #265
Open
comprido96 wants to merge 1 commit into
Open
comprido96 wants to merge 1 commit into
comprido96 wants to merge 1 commit into
Conversation
Seeked back from its end, AVPlayer plays an HLS VOD up to the first EXT-X-DISCONTINUITY and then jumps to the end and stops, when the first segment carries no audio sample. Frigate's fMP4 clips of a camera that records audio only sparsely (one AAC packet per 10 s file) are like that whenever a clip starts inside a recording file. It happens on every replay, including loop = true, which restarts with seekTo(0) from the end. On first play the same boundary goes through, and switching the audio track off does not help. seekTo now rebuilds the player on the same, already loaded asset when the HLS item has reached its end since the last rebuild. The replay costs about as much as the seek did, and the clip plays through. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS, replaying an HLS VOD from its end can stop after a few seconds and jump straight to the end. This is the restart cycle you get with
loop = true, and with a manualseekTo(0f)+play()afteronPlaybackEnded.It happens when the clip's first segment carries no audio sample:
EXT-X-DISCONTINUITYit jumps to the end and postsAVPlayerItemDidPlayToEndTime;loop = truethe library then seeks to 0 again, so it repeats forever.The same boundary plays fine on first play. Switching the item's audio track off (
AVPlayerItemTrack.isEnabled = false) does not help.Real-world source: Frigate (NVR) fMP4 clips of a camera that records audio only sparsely, one AAC packet per 10 s recording file. A clip that starts inside a recording file then has a first segment with no audio at all.
Fix
When the HLS item has reached its end since the last rebuild,
seekTorebuilds the player on the same, already loaded asset (setupVideoOutputAndPlayer), then seeks. A fresh item plays through the boundary. The rebuild reuses the loaded asset, so a replay costs about as much as the seek did.Testing
Tested on macOS 26 (Apple Silicon), against Frigate 0.17 HLS VOD clips (fMP4 segments,
EXT-X-DISCONTINUITYbetween segments, keyframes every 2 s) from two cameras: H.264 Baseline 1280×720 25 fps, and H.264 High 2560×1920 ~30 fps VFR with AAC.NativeVideoPlayer.swiftran 10 laps of "seek near the end → end → seekTo(0) + play → watch 12 s": 10/10 without a spurious end, about 1.4 s to restart. The same driver onmaster: 4/4 laps end at ~7.6 s.:mediaplayer:jvmJarpasses.Prepared with an AI coding assistant (Claude Code) while integrating the library into a macOS desktop app, and tested as described above. Happy to adjust, split or drop anything that does not fit the project.
🤖 Generated with Claude Code