2016-07-30 55 views
0

AVPlayer視頻無法從其離開的位置恢復,而是視頻從頭開始。這是我的代碼。任何人都可以幫助我?AVPlayer視頻在應用變爲活動狀態後無法恢復

-(void)appEnteredForeground:(NSNotification*)notification { 
    if(playerViewController.player.status == AVPlayerStatusReadyToPlay && 
     playerViewController.player.currentItem.status == AVPlayerItemStatusReadyToPlay) { 
      total_duration = self.playerViewController.player.currentItem.duration; 
      [self.playerViewController.player seekToTime:currentTime]; 
      [_playerViewController.player play]; 
    } 
}  

-(void)appEnteredBackground:(NSNotification*)notification { 
    [playerViewController.player pause]; 
    currentTime = [playerViewController.player currentTime]; 
    [playerViewController.player seekToTime:currentTime]; 
} 

回答

0

1.尋求時間問題,當你要求它尋求時間,它不能完成,因爲它已經在後臺。你爲什麼在你進入背景時尋找時間?暫停應該沒問題。刪除以下行。

[playerViewController.player seekToTime:currentTime]; 

2.您最好在主動通知而不是後臺通知中暫停。因爲最後一個應在幾秒鐘後按下主頁按鈕後觸發

+0

它正在處理其他應用程序,但在此應用程序中無法正常工作。 – Bharathi

+0

您是否有任何其他地方操作該播放器? – ronan

+0

一些視頻正在恢復,很少沒有恢復。 – Bharathi

相關問題