I had the same problem. I was because I used the url received in param willDownloadTo of function
urlSession(_:aggregateAssetDownloadTask:willDownloadTo:)
I always received the error -12865
To solve it when download finished in function :
urlSession(_:task:didCompleteWithError:)
I create un bookmarkData with the previous mentioned url, and store it in User defaults with an unique identifier for de asset:
let userDefaults = UserDefaults.standard
let bookmark = try downloadURL.bookmarkData()
userDefaults.set(bookmark, forKey: AssetIdentifier)
With this, when I need the url to playback a recover it from user defaults:
func localAssetFor(withID identifier: String) -> AVURLAsset? {
let userDefaults = UserDefaults.standard
guard let localFileLocation = userDefaults.value(forKey: identifier) as? Data else { return nil }
var asset: AVURLAsset?
var bookmarkDataIsStale = false
do {
let url = try URL(resolvingBookmarkData: localFileLocation,
bookmarkDataIsStale: &bookmarkDataIsStale)
if bookmarkDataIsStale {
fatalError("Bookmark data is stale!")
}
let urlAsset = AVURLAsset(url: url)
return urlAsset
} catch {
fatalError("Failed to create URL from bookmark with error: \(error)")
}
}
With this changes I always have to playback offline content without error 12865.
Hope this help
Pedro
Post
Replies
Boosts
Views
Activity
I had the same problem. I was because I used the url received in param willDownloadTo of function:
urlSession(_:aggregateAssetDownloadTask:willDownloadTo:)
I always received the error -12865
To solve it when download finished in function :
urlSession(_:task:didCompleteWithError:)
I create un bookmarkData with the previous mentioned url, and store it in User defaults with an unique identifier for de asset:
let userDefaults = UserDefaults.standard
let bookmark = try downloadURL.bookmarkData()
userDefaults.set(bookmark, forKey: AssetIdentifier)
With this, when I need the url to playback a recover it from user defaults:
func localAssetFor(withID identifier: String) -> AVURLAsset? { let userDefaults = UserDefaults.standard guard let localFileLocation = userDefaults.value(forKey: identifier) as? Data else { return nil }
var asset: AVURLAsset?
var bookmarkDataIsStale = false
do {
let url = try URL(resolvingBookmarkData: localFileLocation,
bookmarkDataIsStale: &bookmarkDataIsStale)
if bookmarkDataIsStale {
fatalError("Bookmark data is stale!")
}
let urlAsset = AVURLAsset(url: url)
return urlAsset
} catch {
fatalError("Failed to create URL from bookmark with error: \(error)")
}
}
With this changes I always have to playback offline content without error 12865.
Hope this help
Pedro
I had the same problem. I was because I used the url received in param willDownloadTo of function:
urlSession(_:aggregateAssetDownloadTask:willDownloadTo:)
I always received the error -12865
To solve it when download finished in function :
urlSession(_:task:didCompleteWithError:)
I create un bookmarkData with the previous mentioned url, and store it in User defaults with an unique identifier for de asset:
let userDefaults = UserDefaults.standard
let bookmark = try downloadURL.bookmarkData()
userDefaults.set(bookmark, forKey: AssetIdentifier)
With this, when I need the url to playback a recover it from user defaults:
func localAssetFor(withID identifier: String) -> AVURLAsset? { let userDefaults = UserDefaults.standard guard let localFileLocation = userDefaults.value(forKey: identifier) as? Data else { return nil }
var asset: AVURLAsset?
var bookmarkDataIsStale = false
do {
let url = try URL(resolvingBookmarkData: localFileLocation,
bookmarkDataIsStale: &bookmarkDataIsStale)
if bookmarkDataIsStale {
fatalError("Bookmark data is stale!")
}
let urlAsset = AVURLAsset(url: url)
return urlAsset
} catch {
fatalError("Failed to create URL from bookmark with error: \(error)")
}
}
With this changes I always have to playback offline content without error 12865.
Hope this help
Pedro