2011-10-23 8 views
0

因此,我爲每個頁面設置了一個帶有自定義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,然後將其退回到菜單,然後再回到那個時候開始發生。

任何想法?

回答

0

我改變了加載器不預先緩存的意見,它修復了它!現在在市場上發佈^^

0

雖然這固定了那個應用程序,但我正在處理的新應用程序幾乎是必要的,我有多個播放器控制器。我正在使用一塊用於加載資產(確認資產已加載)和觀看者在播放器上顯示ReadyToPlay狀態。另外,我確定avplayerlayer的超級玩家不是零,並且它是在該視圖上加載的最後一名玩家。在所有這些之後很少見,並且應用程序儘可能使用新媒體重新加載這些內容(再次使用塊和觀察者),但是仍然有時候我會切換到一個playercontroller,並且它會有一個空白空間應該。 (將資產報告爲已加載,並將avplayerlayer報告爲沒有超級圖層,並且電影的元數據是正確的)。真的失去了這一個。有任何想法嗎?!

謝謝, -Matt