Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CachingPlayerItem crashes on iOS 14 #39

Open
MrdotSpock opened this issue Aug 31, 2020 · 13 comments
Open

CachingPlayerItem crashes on iOS 14 #39

MrdotSpock opened this issue Aug 31, 2020 · 13 comments

Comments

@MrdotSpock
Copy link

MrdotSpock commented Aug 31, 2020

Hi,

Whenever I initialize CachingPlayerItem the app crashes because also override 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
Copy link

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

@satyres
Copy link

satyres commented Sep 29, 2020

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
Copy link

same here, if anyone has a solution please help

@satyres
Copy link

satyres commented Dec 7, 2020

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

@Sulman012
Copy link

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
Copy link

calsmith commented Feb 4, 2022

+1 this is still broken.

It appears AVQueuePlayer and AVPlayerLooper are not compatible with this project

@QEllis
Copy link

QEllis commented Jul 15, 2022

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
Copy link

dreampowder commented Aug 3, 2022

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
Copy link

lsamaria commented Oct 23, 2022

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
Copy link

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

@ParnaMaliot
Copy link

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
Copy link

Krm1v commented Jan 8, 2024

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! 🙏

@dfmuir
Copy link

dfmuir commented Aug 15, 2024

Thanks to everyone who posted this solution. I wanted to note that the responses given do not set the resourceLoaderDelegate.owner which cause the delegate methods to not be fired correctly and for the file to be only played when the file has been fully downloaded. Not ideal.

This resolved it for me:

override init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?) {
        self.url = URL(fileURLWithPath: "")
        self.initialScheme = nil
        super.init(asset: asset, automaticallyLoadedAssetKeys: automaticallyLoadedAssetKeys)
        
        resourceLoaderDelegate.owner = self
        
        addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.new, context: nil)
        
        NotificationCenter.default.addObserver(self, selector: #selector(playbackStalledHandler), name:NSNotification.Name.AVPlayerItemPlaybackStalled, object: self)
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests