我使用 MPMoviePlayer 播放视频,但遇到了问题:当用户按设备上的home按钮时,我会保存视频的当前位置,然后当用户重新启动应用程序时,我希望能让他从离开的地方继续观看,所以我使用 setCurrentPlaybackTime 函数,在iOS 5 中它工作得很好,但在iOS 5.1中,视频会从开头开始播放。
有没有人有解决这种问题的方法?
有没有人有解决这种问题的方法?
currentPlaybackTime = nan
在收到MPMoviePlayerLoadStateDidChangeNotification通知后,我们应该设置currentPlaybackTime。
要知道moviePLayer是否已加载,首先需要注册MPMoviePlayerLoadStateDidChangeNotification。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
- (void)movieLoadStateDidChange:(NSNotification *)notification
{
MPMoviePlayerController *player = notification.object;
MPMovieLoadState loadState = player.loadState;
/* Enough data has been buffered for playback to continue uninterrupted. */
if (loadState & MPMovieLoadStatePlaythroughOK)
{
//should be called only once , so using self.videoLoaded - only for first time movie loaded , if required. This function wil be called multiple times after stalled
if(!self.videoLoaded)
{
self.moviePlayerController.currentPlaybackTime = self.currentPlaybackTime;
self.videoLoaded = YES;
}
}
}