sukov / CachingPlayerItem

An AVPlayerItem subclass that lets you stream and cache media content on iOS
MIT License
75 stars 19 forks source link

I can't get the Caching to a file to Work I get an error `No such file or directory` #11

Closed Xenolion closed 1 year ago

Xenolion commented 1 year ago

I want to be able to play media while caching to a file. There is an option called saveFilePath, also custom extension (I also don't know why I have to set it manually while all my url has extensions) Now I need the library to save file at the given directory and later on when I play it again to use the local copy instead of streaming (Isn't that the importance of caching?)

My current example of implementations is:

let playerItem = CachingPlayerItem(url: url, saveFilePath: "nDNtKz3BQogGuLtg6XRI.mp4", customFileExtension: "mp4")

The error I get: FileAttribute error: Error Domain=NSCocoaErrorDomain Code=260 "The file “nDNtKz3BQogGuLtg6XRI.mp4” couldn’t be opened because there is no such file." UserInfo={NSFilePath=nDNtKz3BQogGuLtg6XRI.mp4, NSUnderlyingError=0x283d055f0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}FileAttribute error: Error Domain=NSCocoaErrorDomain Code=260 "The file “nDNtKz3BQogGuLtg6XRI.mp4” couldn’t be opened because there is no such file." UserInfo={NSFilePath=nDNtKz3BQogGuLtg6XRI.mp4, NSUnderlyingError=0x283d055f0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

How do I get this to work. Stream while downloading, later play the downloaded file not streaming again??

sukov commented 1 year ago

In your example you are not providing a valid saveFilePath. Please check the demo app for how to handle the saveFilePath parameter.