当我尝试使用此 swift 库 ( https://github.com/piemonte/player ) 播放多个视频时出现此错误。不确定它是否与该播放器有关,或者与照片框架有关,还是什么。
实际情况是,我有一个将显示照片或视频的 View 。一切正常几次,直到播放了几个视频,然后会弹出此消息,然后所有视频都无法播放,而在它们的位置,您只会看到黑屏,然后出现内存使用错误。
我正在使用一个名为 SwipeView 的库,这里有一些可能有用的相关代码。
func swipeView(swipeView: SwipeView!, viewForItemAtIndex index: Int, reusingView view: UIView!) -> UIView! {
let asset: PHAsset = self.photosAsset[index] as PHAsset
// Create options for retrieving image (Degrades quality if using .Fast)
// let imageOptions = PHImageRequestOptions()
// imageOptions.resizeMode = PHImageRequestOptionsResizeMode.Fast
var imageView: UIImageView!
let screenSize: CGSize = UIScreen.mainScreen().bounds.size
let targetSize = CGSizeMake(screenSize.width, screenSize.height)
var options = PHImageRequestOptions()
options.resizeMode = PHImageRequestOptionsResizeMode.Exact
options.synchronous = true
if (asset.mediaType == PHAssetMediaType.Image) {
PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: targetSize, contentMode: .AspectFill, options: options, resultHandler: {(result, info) in
if (result.size.width > 200) {
imageView = UIImageView(image: result)
}
})
return imageView
} else if (asset.mediaType == PHAssetMediaType.Video) {
self.currentlyPlaying = Player()
PHImageManager.defaultManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {result, audio, info in
self.currentlyPlaying.delegate = self
self.currentlyPlaying.playbackLoops = true
self.addChildViewController(self.currentlyPlaying)
self.currentlyPlaying.didMoveToParentViewController(self)
var t = result as AVURLAsset
var url = t.valueForKey("URL") as NSURL
var urlString = url.absoluteString
self.currentlyPlaying.path = urlString
})
return self.currentlyPlaying.view
}
return UIView()
}
func swipeViewItemSize(swipeView: SwipeView!) -> CGSize {
return self.swipeView.bounds.size;
}
func swipeView(swipeView: SwipeView!, didSelectItemAtIndex index: Int) {
self.currentlyPlaying.playFromBeginning()
}
func swipeViewCurrentItemIndexDidChange(swipeView: SwipeView!) {
self.currentlyPlaying.stop()
}
任何想法都会很棒。
最佳答案
我遇到了同样的“与 assetsd 的连接中断或 assetsd 死亡”错误。
通常后跟一个内存警告。 我试图找到保留周期,但不是。
我的问题与已知事实有关,即任何 PHImageManager request...()
的 resultHandler block 是 < strong>不在主队列上调用。
因此,我们不能直接在这些 block 中运行 UIView 代码,否则会在以后的应用程序生命周期中出现问题。
为了解决这个问题,我们可能会在 dispatch_async(dispatch_get_main_queue(), block )
我遇到这个问题是因为我没有意识到我在我的应用程序的 resultHandler.s 之一中调用的函数之一最终调用了一些 UIView 代码下线。 所以我没有将该调用转发到主线程。
希望这对您有所帮助。
关于ios - 照片框架 : Connection to assetsd was interrupted or assetsd died,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27914846/