因此,我爲每個頁面設置了一個帶有自定義PageView的ATPagingView(滾動視圖)(https://github.com/andreyvit/SoloComponents-iOS/tree/master/ATPagingView)。頁面視圖加載了一個AVPlayerLayer,該AVPlayerLayer被加載了一個AVPlayer(因爲我嘗試使用AVQueuePlayer試圖解決這個問題)。現在,ATPagingView內置了頁面回收功能,因此我不應該一次加載所有15個視頻(將其設置爲3),並且我向頁面視圖添加了重新加載功能,基本上爲新頁面索引加載視頻,啓動一切,但在我重新引入所有內容之前,它仍然無法工作。我相當積極,這是一個與avplayers的記憶,但分析器顯示沒有泄漏和持續的內存足跡。我現在認爲ATPagingView正在發送正確的索引和所有內容,因爲我在PageView上也有正確的標籤。使用ATPagingView(ScrollView)顯示多個頁面,但有些顯示爲空白,如果我出去並返回
我試過這個:Playing many different videos on iphone using AVPlayer沒有運氣。以及嘗試使用AVQueuePlayers來處理重載而不是replaceCurrentItemWithPlayerItem :.再次沒有運氣。
這裏大致是現在的初始化代碼:
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];
和重加載代碼看起來是這樣的:
[[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];
就像我說的,這不是每次它重新加載,但如果我進入ATPagingView,然後將其退回到菜單,然後再回到那個時候開始發生。
任何想法?