neekeetab / CachingPlayerItem

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

CachingPlayerItem crashes on iOS 14 #39

Open MrdotSpock opened 3 years ago

MrdotSpock commented 3 years ago

Hi,

Whenever I initialize CachingPlayerItem the app crashes because alsooverride init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?) is called multiple times. But this initializer is not implemented. I tried to implement it myself but it creates a huge delay before the playing starts and I don't know which track I should play anyway.

This happens only on iOS 14. I've checked multiple times that I do not call the initializer myself and I really don't understand why it is happening. It seems like multiple instances of CachingPlayerItem are being created. (One with correct initializer and the rest with this one) Does anyone else also encounter this issue? Did anyone find a solution?

Thanks

ealeksandrov commented 3 years ago

Same for me, crash appeared in analytics for all iOS14 users.

satyres commented 3 years ago

I have the same problem ,it's not stable sometimes it crashes please help if you have find a solution ? i don't understand what happen in iOS 14 ! this is really odd

kandhalarjan commented 3 years ago

same here, if anyone has a solution please help

satyres commented 3 years ago

Hi has anyone tested on the iOS 14,2 ? please provide us your feedback so we can find a solution Regards

Sulman012 commented 2 years ago

This issue still persists on iOS 14.7 as well.

If I setup a playerItem -> CachingPlayerItem, and set it to some AVPlayer or AVQueuePlayer it plays fine.

but when I try to launch it for next cells/items in my pagerViewCotroller, it does not start download automatically and when user scrolls to next page or cell/item -> it crashes with fatalError breakpoint on line

override init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?) { fatalError("not implemented") }

Can we have a quick look into this.
calsmith commented 2 years ago

+1 this is still broken.

It appears AVQueuePlayer and AVPlayerLooper are not compatible with this project

QEllis commented 1 year ago

I was able to solve this issue by adding override of the init it is complaining about:

override init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?) {
   self.url = URL(fileURLWithPath: "")
   super.init(asset: asset, automaticallyLoadedAssetKeys: automaticallyLoadedAssetKeys)
 }

Making sure to set empty URL before super.init call.

dreampowder commented 1 year ago

i had to add these lines too for @QEllis 's answer:

override init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?) {
        self.url = URL(fileURLWithPath: "")
        self.initialScheme = nil
        super.init(asset: asset, automaticallyLoadedAssetKeys: automaticallyLoadedAssetKeys)

        addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.new, context: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(playbackStalledHandler), name:NSNotification.Name.AVPlayerItemPlaybackStalled, object: self)

     }
lsamaria commented 1 year ago

To everyone with this issue. When initializing your playerItem use:

let playerItem = CachePlayerItem(url: url, avUrlAssetOptions: nil) <<< make sure to set this to nil

This is the incorrect one to use and what causes the crash

let playerItem = CachePlayerItem(url: url) <<< DON'T USE THIS alone without the avUrlAssetOptions param

JaidynBluesky commented 1 year ago

The solution given by @QEllis and @dreampowder works even when you are using AVQueuePlayer and AVPlayerLooper.

ParnaMaliot commented 1 year ago

To everyone with this issue. When initializing your playerItem use:

let playerItem = CachePlayerItem(url: url, avUrlAssetOptions: nil) <<< make sure to set this to nil

This is the incorrect one to use and what causes the crash

let playerItem = CachePlayerItem(url: url) <<< DON'T USE THIS alone without the avUrlAssetOptions param

Thanks @lsamaria! This solution works for me

Krm1v commented 5 months ago

i had to add these lines too for @QEllis 's answer:

override init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?) {
        self.url = URL(fileURLWithPath: "")
        self.initialScheme = nil
        super.init(asset: asset, automaticallyLoadedAssetKeys: automaticallyLoadedAssetKeys)

        addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.new, context: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(playbackStalledHandler), name:NSNotification.Name.AVPlayerItemPlaybackStalled, object: self)

     }

Big thanks! 🙏