由于 AVAssetDownloadURLSession、AVAssetDownloadDelegate for iOS 11 使用 makeAssetDownloadTask(...) 和 aggregateAssetDownloadTask(...) 方法,我正在下载离线视频。
一切正常,但我只想让用户尽可能准确地了解每次下载的进度。
为此,我使用:
- urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didLoad timeRange: CMTimeRange, totalTimeRangesLoaded loadedTimeRanges: [NSValue], timeRangeExpectedToLoad: CMTimeRange)
- urlSession(_ session: URLSession, aggregateAssetDownloadTask: AVAggregateAssetDownloadTask, didLoad timeRange: CMTimeRange, totalTimeRangesLoaded loadedTimeRanges: [NSValue], timeRangeExpectedToLoad: CMTimeRange, for mediaSelection: AVMediaSelection)
Run Code Online (Sandbox Code Playgroud)
使用这些方法,我可以分别计算视频和每个曲目(音频/字幕)的下载进度。所以我假设视频占下载量的 70%,对于曲目,它是 30% 除以曲目数量。我将每个项目的下载进度存储在一个临时字典中(乘以它们的比率),并添加每个下载进度以具有全局表示。
最后它工作正常,但并不像预期的那样顺利。例如,我花了 3 分钟来下载内容,但如果曲目的重量较轻,则进度会在 1 秒内从 70% 跳到 85%(如果我有 2 首曲目要下载),然后立即放慢速度。我想有一个全球性的进步。
我绝对对这个解决方案不满意,但我目前没有找到另一个解决方案。
你们中的一些人有什么想法/解决方案吗?
谢谢你们
我尝试将项目从NSMutableArray复制到另一个.
我在我的两个第一个MutableArray(storiesRSS1和storiesRSS2)中添加了项目:
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentImage forKey:@"image"];
[item setObject:currentMovie forKey:@"movie"];
[storiesRSS1 addObject:[item copy]];
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentImage forKey:@"image"];
[item setObject:currentMovie forKey:@"movie"];
[storiesRSS2 addObject:[item copy]];
Run Code Online (Sandbox Code Playgroud)
对于这两个阵列,它可以工作.
之后我想在第三个数组中混合(stories).
int i=0;
int nbElement=[storiesRSS1 count]+[storiesRSS2 count];
while (i<nbElement) {
if (i<[tempArrayTed count]) {
[stories addObject:[storiesRSS1 objectAtIndex:i]];
}
if (i<[tempArrayYoutube count]) {
[stories addObject:[storiesRSS2 objectAtIndex:i]];
}
i++;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我试图展示每件物品时,它总是如此 …
我想使用下面的方法连接两个带有+ =运算符重载的字典.
static func += <Key, Value> ( left: inout [Key : Value], right: [Key : Value]) {
for (key, value) in right {
left.updateValue(value, forKey: key)
}
}
Run Code Online (Sandbox Code Playgroud)
要么
static func +=<Key, Value>( left: inout Dictionary<Key ,Value>, right: Dictionary<Key, Value>) {
for (key, value) in right {
left.updateValue(value, forKey: key)
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个实现:
var properties = ["Key": "Value"]
var newProperties = ["NewKey": "NewValue"]
properties += newProperties
Run Code Online (Sandbox Code Playgroud)
我从xCode得到以下错误,
无法将'[String:Any]'类型的值转换为预期的参数类型'inout [_:]'(又名'inout'Dictionary <,_>)
它不起作用,任何人都可以帮助我,或者如果不可能,请解释我为什么?
avfoundation ×1
dictionary ×1
download ×1
ios ×1
iphone ×1
objective-c ×1
offline ×1
progress ×1
swift ×1