So I set up an ATPagingView(ScrollView)(https://github.com/andreyvit/SoloComponents-iOS/tree/master/ATPagingView) with a custom PageView for each page. The page view is loaded with a AVPlayerLayer which was/is loaded with a AVPlayer(was because as part of trying to fix this I have tried using an AVQueuePlayer). Now the ATPagingView had page recycling built in so that I shouldn’t be loading all 15 video at once(have it set to 3) and I added a reload function to the PageView that basically loads the video for the new page index without re-initing everything, but before I just re-inited everything and it still didn’t work. I’m pretty positive it’s a memory thing with the avplayers, but the profiler shows no leaks and a constant memory footprint. I now that the ATPagingView is sending the right index and everything because I also have labels on the PageViews that are correct.
I have tried this: Playing many different videos on iphone using AVPlayer with no luck. As well as trying to use AVQueuePlayers to handle the reloading instead of replaceCurrentItemWithPlayerItem:. Again no luck.
Here is roughly the init code now:
NSURL* m =[[NSBundle mainBundle] URLForResource:page.video withExtension:page.videoExt];
self.player = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObject:[AVPlayerItem playerItemWithURL:m]]];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.playerLayer.frame = self.frame;
[img.layer addSublayer: self.playerLayer];
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.player currentItem]];
[self.player play];
And the reload code looks something like this:
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:[self.player currentItem]];
[self.player removeAllItems];
NSURL* m =[[NSBundle mainBundle] URLForResource:page.video withExtension:page.videoExt];
//AVPlayer version
url = m;
AVAsset *newAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *newPlayerItem = [AVPlayerItem playerItemWithAsset:newAsset];
[self.player insertItem:newPlayerItem afterItem:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:newPlayerItem];
[self.player play];
Like I said, it’s not everytime it reloads, but if I go into the ATPagingView and then exit it back to the menu and then go back in that’s when it’ll start happening.
Any ideas?
I changed the loader to not pre-cache the views and it fixed it! Released on the market now^^