Created
August 30, 2020 12:38
-
-
Save agammahajan1/03908bc99cb730b36aa7ed2bdfba0020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
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
Can I get a project to learn this?