Post

Replies

Boosts

Views

Activity

Reply to How to cache an HLS video while playing it
Got it, thank you! To clarify, are you suggesting that I just keep my AVPlayers in memory? That's actually what I'm currently doing, but this seems problematic in terms of memory - a user might quickly scroll through 50 videos. I was actually told last year at an in-person WWDC lab that it was a bad idea to keep 50 AVPlayers in memory. I added some cleanup logic to remove AVPlayers as the user scrolls away, but this means that videos need to be re-downloaded as if the user scrolls back. How would I cache more than ~8 of my 10-second videos, if memory is too limited but disk is contributes to NAND wear?
Jun ’20
Reply to How can I detect when the mute switch has been toggled?
Thanks for getting back to me. I totally understand that it's cleaner to let the system be consistent about mute behavior based on the AudioSession category, but we really need the ability to toggle between the ambient category (to let the user browse passively while, say, listening to music from another app) and the playback category (so the user can hear the audio from our app). The Instagram app updates its software mute button UI when the physical mute switch is toggled, so it must be possible? Any suggestions on how we can achieve the same thing?
Jun ’20
Reply to How to cache an HLS video while playing it
I initialize an AVPlayer for the user's current scroll position, the position above the user's current position, and the 3 positions below the user's current scroll position. Initializing the AVPlayer automatically loads the first HLS chunk. I just keep references to those 5 AVPlayers. So if the user scrolls down one position then scrolls back, I don't need to re-initialize the AVPlayer. But if the user scrolls far away and then scrolls back, I do need to re-load the video.
Mar ’21
Reply to How to cache an HLS video while playing it
Also, for the currently playing AVPlayer, I set player.preferredForwardBufferDuration = 0. This tells the system to use the default logic for how far ahead to load while playing. For the other players, I set player.preferredForwardBufferDuration = 1. This tells the players to just load one HLS chunk (generally 6-10 seconds).
Mar ’21