Perhaps you are checking AVPlayerItem canPlayReverseor canPlayFastForwardbefore the property AVPlayerItem statuschanges to .readToPlay. If you do, you will always receive false.
Do not do this:
import AVFoundation
let anAsset = AVAsset(URL: <
let playerItem = AVPlayerItem(asset: anAsset)
let canPlayFastForward = playerItem.canPlayFastForward
if (canPlayFastForward){
print("This line won't execute")
}
Observe the property instead AVPlayerItem status. The following is Apple's documentation :
AVPlayerItem . AVPlayerItem.canPlayFastForward YES ( , ) . , , AVPlayerItem.status ().
import AVFoundation
dynamic var songItem:AVPlayerItem!
let anAsset = AVAsset(URL: <#A URL#>)
let songItem = AVPlayerItem(asset: anAsset)
playerItem.addObserver(self, forKeyPath: "status", options: .new, context: nil)
Ovveride observeValue :
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let status = change?[.newKey] as? Int{
if(status == AVPlayerItemStatus.readyToPlay.rawValue){
yourPlayer.rate = 2.0 // or whatever you want
}
}
}
songItem
deinit {
playerItem.removeObserver(self, forKeyPath: "status")
}