Skip to content

Instantly share code, notes, and snippets.

@agammahajan1
Created August 30, 2020 12:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agammahajan1/03908bc99cb730b36aa7ed2bdfba0020 to your computer and use it in GitHub Desktop.
Save agammahajan1/03908bc99cb730b36aa7ed2bdfba0020 to your computer and use it in GitHub Desktop.
func asynchronouslyLoadURLAssets(_ newAsset: AVURLAsset) {
DispatchQueue.main.async {
newAsset.loadValuesAsynchronously(forKeys: self.assetKeysRequiredToPlay) {
for key in self.assetKeysRequiredToPlay {
var error: NSError?
if newAsset.statusOfValue(forKey: key, error: &error) == .failed {
self.delegate?.playerDidFailToPlay(message: "Can't use this AVAsset because one of it's keys failed to load")
return
}
}
if !newAsset.isPlayable || newAsset.hasProtectedContent {
self.delegate?.playerDidFailToPlay(message: "Can't use this AVAsset because it isn't playable or has protected content")
return
}
let currentItem = AVPlayerItem(asset: newAsset)
let currentPlayer = AVPlayer(playerItem: currentItem)
self.delegate?.playerDidSuccesToPlay(playerDetail: currentPlayer)
}
}
@Alma12-mid
Copy link

Can I get a project to learn this?

@trantorGurjitSingh
Copy link

trantorGurjitSingh commented Apr 18, 2022

Can you let me know what value need to set for assetKeysRequiredToPlay ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment