AVQueuePlayer does not seek already played HLS streams properly, causing AVPlayerLooper to jump to wrong time

Originator:stan.chevallier
Number:rdar://46784549 Date Originated:17-Dec-2018 08:43 PM
Status:Open Resolved:
Product:tvOS + SDK Product Version:12.1.1
Classification:Other Bug Reproducible:Always
 
Summary:
We are currently developing an application that uses a short background video. As our target is iOS 11+ we decided to use AVPlayerLooper to gracefully handle looping our video stream.

This stream is a 15 seconds h264 video, doesn’t contain a sound track, and has been created using mediafilesegmenter and variantplaylistcreator with segments of 4 seconds. 

We reduced our player logic to the attached example project. 

Impacted devices:
- AppleTV 4, iOS 12.1.1
- Simulator gen. 4 + 4K, tvOS 11.4 + 12.1 

Fixes we tried:
- as some of the segments do not start with a key frame with also tried generating them using ffmpeg, by encoding each segment from the source, to obtain valid files. Alas the issue persists.
- recreating AVPlayerLooper with an AVQueuePlayer subclass, re-adding and item once it has ended. This fails in the same way. Calling seek(to:completion:) after re-adding an item does not work either
- change the segment length, while this does change something in the behaviour (instead of resuming from say 13s it might resume from 14s or 10s) it does not solve the issue
- AVQueuePlayer subclass that creates a new AVPlayerItem from the template once the currentItem has ended. This works, but network cache is not leveraged properly
- using a single .mp4 file instead of an HLS stream while keeping native AVPlayerLooper. This works

The attachement contains:
- a demo project that recreates the issue every time
- a source stream, script to generate the HLS segments, and script output files
- the log generated by the demo app
- a sysdiagnose

Steps to Reproduce:
0. Create the HLS files, upload to an accessible host
1. Create an AVPlayerItem with the stream index.m3u8 URL
2. Create an AVPlayerLayer, AVQueuePlayer and AVPlayerLooper
3. Start the player
4. Watch closely the video once it has played 3/4 times

Expected Results:
The video loop should be seamless, and each loop should start from the beginning and play until the current item end

Actual Results:
Once each items in the AVPlayerLooper queue has played once the player becomes jumpy. For instance, as we finish item #0 in the looper, it will advance to item #1 but at 13 or 14secs, instead of restarting from the beginning.

Version:
12.1.1

Notes:
We also noted the following issues, possibly related. We would not expect either as the next stream should already be cached when an item finishes.
1. intermittent black screen between the first loops
2. resolution jumps when multiple variants varying in dimension are available

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!