播放视频但没有图像 - 只有声音?
-
02-10-2019 - |
题
编辑: :如果您遇到这个问题并想知道我最终如何解决它,我最终放弃了下面的代码并执行了以下操作:
-(void)playMovieAtURL:(NSURL*)theURL{
mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.view.backgroundColor = [UIColor blackColor];
}
原帖:
这是我的代码 - 我把它从苹果网站上取下来,所以应该不是问题。
它在 UITableViewController 的 didSelectRowAtIndexPath 方法上运行。
当您选择该行时,视频开始播放 - 至少有声音输出 - 但没有图像。知道这是为什么吗?我已经包含了框架。
该视频是我用于测试的苹果网站上的一个(facetime 视频)。
-(void)playMovieAtURL:(NSURL*)theURL{
MPMoviePlayerController* theMovie =
[[MPMoviePlayerController alloc] initWithContentURL: theURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.controlStyle = MPMovieControlStyleNone;
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
解决方案
MPMoviePlayerController 的行为在 OS 3.2 中发生了变化 - 您现在需要显式地将电影播放器的视图添加到视图层次结构中 - 使用类似以下内容:
[aView addSubview:moviePlayerController.view];
moviePlayerController.view.frame = aView.frame;
或者,您可以使用 MPMoviePlayerViewController(3.2 中的新增功能)来管理视图。
如果您的目标是 3.2 之前和之后的设备(例如iOS 3.1 和 4.0),那么您将需要一些条件代码来确定代码运行的操作系统并进行相应的处理。我在之前的项目中使用过这个:
if ([moviePlayerController respondsToSelector:@selector(setFullscreen:animated:)]) {
// Running on OS 3.2 or above
// Code to add to a view here...
}
不隶属于 StackOverflow