Skip to content

Instantly share code, notes, and snippets.

@atulkhatri
Created July 12, 2021 17:51
Show Gist options
  • Save atulkhatri/e16ba76847e20cb5a5006589b692607b to your computer and use it in GitHub Desktop.
Save atulkhatri/e16ba76847e20cb5a5006589b692607b to your computer and use it in GitHub Desktop.
tvOS Bootcamp Player 6
private func createPlayerItem(url: URL) -> AVPlayerItem {
let playerItem = AVPlayerItem(url: url)
// Add advertisement timerange
var timeRanges: [AVInterstitialTimeRange] = []
for index in stride(from: 60, to: 600, by: 60) {
let range = AVInterstitialTimeRange(timeRange: CMTimeRange(start: CMTime(seconds: Double(index), preferredTimescale: .max), duration: CMTime(seconds: 1, preferredTimescale: .max)))
timeRanges.append(range)
}
playerItem.interstitialTimeRanges = timeRanges
return playerItem
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment