2zgroupsolutionsarticles / article_ez002 Goto Github PK
View Code? Open in Web Editor NEWUnderstanding AVAssetResourceLoaderDelegate
Understanding AVAssetResourceLoaderDelegate
Hi, Yevhenii!
I tried to use a delegate from your project, but since my project is written in Swift 5.1, I was forced to make small changes.
private func checkAndRespond(forRequest dataRequest: AVAssetResourceLoadingDataRequest) -> Bool {
let downloadedData = self.mediaData
let downloadedDataLength = Int64(downloadedData.count)
let requestRequestedOffset = dataRequest.requestedOffset
let requestRequestedLength = Int64(dataRequest.requestedLength)
let requestCurrentOffset = dataRequest.currentOffset
if downloadedDataLength < requestCurrentOffset {
return false
}
let downloadedUnreadDataLength = downloadedDataLength - requestCurrentOffset
let requestUnreadDataLength = requestRequestedOffset + requestRequestedLength - requestCurrentOffset
let respondDataLength = min(requestUnreadDataLength, downloadedUnreadDataLength)
dataRequest.respond(
with: downloadedData.subdata(
in: Range(Int(requestCurrentOffset)...Int(respondDataLength))
)
)
let requestEndOffset = requestRequestedOffset + requestRequestedLength
return requestCurrentOffset >= requestEndOffset
}
Here I changed the shaping of the range, and this is where the program crashes, as sometimes requestCurrentOffset is greater than respondDataLength. Moreover, respondDataLength is -1 at this point.
If i add a condition before dataRequest.respond:
if requestCurrentOffset > respondDataLength { return false }
the program stops crashing and even reaches the end of this function several times during the video download period.
But never returns true. And accordingly, request.finishLoading()
is never called
P.S. The entire project (without any changes) I also failed to get it to work, although I substituted different urls - the download wheel just spins.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.