Avkit
AVKit
Libraries involved
AVKit
AVFoundation
AVPlayer
Video Terminologies
SwiftUI POC
SwiftUI + Video player to stream.
hls-streaming-with-avkit-and-swiftui
DRM
HLS
AVPlayer
AVAsset
avPlayerItem
Guides
Video thumbnail
This below snippet code should be able to extract the thumbnail image from the given video source. We can also create random time value to generate different thumbnails but we have ensure that the video is at least 13 secs long in this code snippet. You can safe guard yourself with a range of video duration and generate random thumbnail out of it.
let asset = AVAsset(url: url)
let avAssetImageGen = AVAssetImageGenerator(asset: asset)
avAssetImageGen.appliesPreferredTrackTransform = true
let thumbnailSnapTime = CMTimeMake(value: 13, timescale: 1)
do {
let thumbCGImage = try avAssetImageGen
.copyCGImage(at: thumbanailSnaptime, actualTime: nil)
let thumbImage = UIImage(cgImage: thumbCGImage)
} catch {
print(error)
}
Multiple Tracks
https://developer.apple.com/documentation/avfoundation/media_playback/selecting_subtitles_and_alternative_audio_tracks
Loading media data async
apple dev | Loading media data asynchronously
Quirks
Impossible to stop AVPlayer
Blank Video but audio audible
iOS 16.4 simulator bug for HLS
streams. Confirmed on Apple developer website. Spent around 20 mins debugging what is wrong with my code overall.
Interview Questions
Video Geeking
Reference
Using AVFoundation to Play and Persist HTTP Live Streams
Video article ios-fairplay-drm-integration