neekeetab / CachingPlayerItem

Play and cache media content simultaneously on your iOS device
MIT License
520 stars 89 forks source link

Delegate not called in iOS 10.2 #11

Closed nitingohel closed 5 years ago

nitingohel commented 6 years ago

We are using that great lib for playing audio from firebase url and that works well but we just get to know that wont working in ios 10.2 as following my source code:

 fileprivate func loadItem(_ url:URLConvertible,_ block:((CachingPlayerItem) -> Void)?) {
        if self.playerItem == nil {
            self.playerItem = CachingPlayerItem(url: url.asURL()!)
            self.playerItem.delegate = self
            self.preloadCompletionHandler = block
        } else {
            block?(self.playerItem)
        }
    }

Yes i am sure that url no nil that same code working in ios 11. That code trigger in Collection-view custom cell and we use that delegate method as extension like bellow:

extension DictationAudioCell: CachingPlayerItemDelegate {

    func playerItemPlaybackStalled(_ playerItem: CachingPlayerItem) {
        print("Not enough data for playback. Probably because of the poor network. Wait a bit and try to play later.")
        //self.iDelegate?.iPlayerPausedPlaying(self)
    }

    func playerItem(_ playerItem: CachingPlayerItem, didFinishDownloadingData data: Data) {
        //Tells the handler that PlayerItem has loaded the data so you can play the audio...
        print("File is downloaded and ready for storing")
        DispatchQueue.main.async {
            self.player = AVPlayer(playerItem: playerItem)
            self.player.automaticallyWaitsToMinimizeStalling = false
            self.preloadCompletionHandler?(playerItem)
            self.btnSkip.isUserInteractionEnabled = false
        }
    }

    func playerItem(_ playerItem: CachingPlayerItem, didDownloadBytesSoFar bytesDownloaded: Int, outOf bytesExpected: Int) {
        print("\(bytesDownloaded)/\(bytesExpected)")
    }

    func playerItem(_ playerItem: CachingPlayerItem, downloadingFailedWith error: Error) {
        //When Error occurs, skip the audio
        print("\n\n\t##--->CachingPlayerItem.downloadingError = \(error.localizedDescription)")
        self.btnSkip.isUserInteractionEnabled = true
    }
}

That never called with iOS 10.2 simulator and that works in ios 11+ simulator. Can you please help me to figur this out.

thanks

neekeetab commented 6 years ago

It may not work the way it should on simulators. Try testing on an actual device. It should be fine.

vsg24 commented 5 years ago

I can confirm that this only happens in simulator and real devices face no issues however @neekeetab is there anything that can be done to make this work also in simulator?