Photo structure: connection to assets was interrupted or assets died

I get this error when I try to play multiple videos using this quick library ( https://github.com/piemonte/player ). Not sure if this is related to this player or to a framework or something else.

What happens, I have a view that will display either a photo or a video. Everything works fine several times until several videos are played, and then this message appears, followed by all the videos that cannot be played, and in their place you see a black screen, and then I get a memory usage error.

I am using a library called SwipeView, and here is some relevant code that might be useful.

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() } 

Any thoughts would be wonderful.

+6
source share
2 answers

I had the same β€œ Asset connection d was interrupted or the assets died ”.

A warning usually follows. . I tried to find retention cycles, but that was not the case.

The problem for me is related to the well-known fact that the resultHandler block of any PHImageManager request...() does not call in the main queue.

Thus, we cannot run UIView code directly inside these blocks without asking problems later in the life of the application.

To fix this, we can, for example, run all the UIView code that will be executed as part of the resultHandler block inside dispatch_async(dispatch_get_main_queue(), block)

I had this problem because I did not understand that one of the functions that I called in one of the resultHandler.s of my application ended up calling some UIView code in a string. And so I did not redirect this call to the main thread.

Hope this helps.

+14
source

Perhaps the problem is that you create a new Player object each time you start the video:

  self.currentlyPlaying = Player() 

I would recommend you either delete it after the file has finished the game, or create one player that you will reuse. Otherwise, it will remain in .v memory

0
source

Source: https://habr.com/ru/post/980903/


All Articles