【发布时间】:2012-10-26 22:36:54
【问题描述】:
我有一个现有的 iPhone/iPad 通用应用程序,它使用 MPMoviePlayerController 通过 wi-fi (mp4) 和 3G 网络 (3gp) 流式传输视频。当 iOS 4.3 发布时,我们的 4.3 设备无法再通过 3G 网络播放 3gp 视频。我测试了一个本地 3gp 文件,但也失败了,但可以在运行 4.2.x 的 3G 手机上运行。
调试视图控制器后,我看到在尝试本地播放 3gp 文件或通过 URL 流式传输时未触发 MPMoviePlayerLoadStateDidChangeNotification 通知。
[APPDEL showStatusView: @"Please wait..."];
NSString * videoUrl = [[request.URL description] stringByReplacingOccurrencesOfString: @"idvideo:" withString: @"http:"];
DLog(@"Loading video %@", videoUrl);
_moviePlayer = [[IDMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString: videoUrl]];
_moviePlayer.view.backgroundColor = [UIColor clearColor];
_moviePlayer.allowsAirPlay = YES;
_moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
if ([_moviePlayer respondsToSelector:@selector(loadState)]) {
// May help to reduce latency
[_moviePlayer prepareToPlay];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:_moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerPreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:_moviePlayer];
//[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(moviePlayerTimerUp:) userInfo:nil repeats:NO];
}
else {
// Register to receive a notification when the movie is in memory and ready to play.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
}
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(onMovieDone:) name: MPMoviePlayerPlaybackDidFinishNotification object: nil];
if ([_moviePlayer respondsToSelector: @selector(view)]) {
[self.view addSubview: _moviePlayer.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
_moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
}
else {
_moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
}
_moviePlayer.view.frame = _webView.frame;
}
[_moviePlayer play];
始终满足 loadState 的第一个条件。对于 3gp 文件,代码永远不会到达 moviePlayerLoadStateChanged 选择器方法,该方法隐藏指示器/状态视图并创建其他全屏/方向通知。指标/状态视图将保持向上和旋转。在调试器中,我可以看到 onMovieDone 选择器方法被触发的时间远远早于视频真正完成的时间。
困惑。
【问题讨论】: