2012-07-06 63 views
0

我能夠使用MPMoviePlayerViewController播放視頻文件,一切工作正常。但是,如果我按Home按鈕,現在打開應用程序,視頻將從超級視圖中刪除。我知道如何獲取通知。你能告訴我如何恢復相同的視頻?在MPMoviePlayerViewController中恢復視頻

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"adv" ofType:@"mp4"]; 
NSURL* url = [NSURL fileURLWithPath:filePath]; 

_moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
[_moviePlayer.view setFrame:self.view.bounds]; 
[self.view addSubview:_moviePlayer.view]; 

我正在使用上面的代碼播放視頻。如果我按下主頁按鈕,然後回到應用程序,視頻就消失了。我能看到的只有中..爲MPMoviePlayerPlaybackStateDidChangeNotification通知

+0

請檢查我更新的問題 – Perseus 2012-07-06 15:22:49

回答

0

登記和檢查_moviePlayer.movi​​ePlayer財產endPlaybackTime值

那麼球員顯示下一次設置initialPlaybackTime以前的終值

+0

當應用程序啓動時,MPMoviePlayerPlaybackStateDidChangeNotification正在被調用。當我按home鍵並再次打開應用程序時,它不會被調用 – Perseus 2012-07-06 15:59:31

5

當應用程序再次處於活動狀態時,您應該可以通過調用[_moviePlayer play]重新開始播放。

你既可以調用從AppDelegate中的applicationDidBecomeActive方法背部,或做類似:

[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication] queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { 
    [_moviePlayer play]; 
}]; 

添加一個觀察員通知(不要忘了在以後進行刪除)。

相關問題