我正在尝试在 MPMoviePlayerViewController 中设置 MPMoviePlayerController 的 currentPlaybackTime 属性,以使其从那时起恢复播放视频(HLS 流),当应用程序退出事件时它已停止。这是我的代码:
//the functinon that sets playback time
- (void)setCurrentPlayTime:(NSNumber *)time {
if (self.moviePlayer.currentPlaybackTime < [time floatValue] - 10.0) {
[self.moviePlayer setCurrentPlaybackTime:(NSTimeInterval)[time floatValue]];
}
}
//app did become active callback
- (void) applicationDidBecomeActiveNotification:(NSNotification*)notification {
if (!isnan(_curPlayTime) && _curPlayTime > 0.0) {
[self performSelector:@selector(setCurrentPlayTime:) withObject:[NSNumber numberWithFloat:_curPlayTime] afterDelay:0.1];
}
}
//player load state did change callback
-(void)playerLoadStateDidChange:(NSNotification *)notification {
MPMoviePlayerController *player = notification.object;
MPMovieLoadState loadState = player.loadState;
if (loadState & MPMovieLoadStatePlaythroughOK) {
if (!isnan(_curPlayTime) && _curPlayTime > 0.0) {
[self performSelector:@selector(setCurrentPlayTime:) withObject:[NSNumber numberWithFloat:_curPlayTime] afterDelay:0.1];
_curPlayTime = 0.0;
}
}
当我只需点击主页按钮然后重新打开应用程序时,如果我接到来电但拒接,它也能正常工作。但是如果我接听来电,在我结束通话后,播放从 0.0 开始,忽略 setCurrentPlaybackTime 方法调用。有谁知道,问题出在哪里,可能是应该如何正确工作的任何例子?
最佳答案
不确定这是否是问题所在,但您搜索的选择器是 setCurrentPlayTime 而不是 setCurrentPlay*back*Time。
关于objective-c - MPMoviePlayerViewController 无法设置当前播放时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9786328/