I want to play stream through my delegate to apply my client certificate there. But no one event handled in delegate. When I turn off client certificate on the streaming server side, playback works fine. Otherwise - 400 Bad request (Client do not send client certificate). I try to send certificate in authentication challenge in delegate, but this event not handled.
(tvOS 10 with swift 3.)
Here it is code that initialize playback:
let movieAsset:AVURLAsset = AVURLAsset(url: plurl!, options: nil)
let plCont:PlayerViewDelegate = PlayerViewDelegate()
movieAsset.resourceLoader.setDelegate(plCont, queue: DispatchQueue.main)
let playerItem:AVPlayerItem = AVPlayerItem(asset: movieAsset)
playerController.player = AVPlayer(playerItem: playerItem)
playerController.player?.play()
Here it is code that describes delegate:
class PlayerViewDelegate: NSObject, AVAssetResourceLoaderDelegate {
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool{
return true
}
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForRenewalOfRequestedResource renewalRequest: AVAssetResourceRenewalRequest) -> Bool{
return true
}
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, didCancel loadingRequest: AVAssetResourceLoadingRequest){
}
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, didCancel authenticationChallenge: URLAuthenticationChallenge){
print("PLAY CHALLENGE 2")
}
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForResponseTo authenticationChallenge: URLAuthenticationChallenge) -> Bool {
print("PLAY CHALLENGE")
return true
}
}
"PLAY CHALLENGE" (and all others events) are never occurred.
What I do wrong?
UPDATED!
I saw this topic Delegates methods not invokes without custom_scheme.
When I change my scheme to custom one: https -> ss_https, only one method was invoked:
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool
But I need to change scheme back to original, because the other events are still not handled. All examples in internet written in objective-c and just change scheme with request.scheme = "https". But in swift 3 all important objects are immutable! So I cannot change request, url, scheme, etc in the resourceLoader event.