现在我想我知道3.X和4之间在MPMoviePlaybackController方面的差异以及需要设置视图并让它在子视图控制器中完全工作。但是,尽管以下代码看起来是正确的(对我而言),我仍然只是在电影的持续时间内得到一个空白屏幕。我知道它会成功播放,因为moviePlayBackDidFinish会触发。
此时我是否需要将其添加到模态或类似物中?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
player.fullscreen = YES;
player.controlStyle = MPMovieControlStyleNone;
[[player view] setFrame:window.bounds];
[window addSubview: [player view]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
}
答案 0 :(得分:1)
MPMoviePlayerController没有view属性。
您应该/必须使用 MPMoviePlayerViewController
。
这就是我的所作所为:
moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:currentChannel.StreamURI]];
[moviePlayerViewController.moviePlayer setControlStyle:MPMovieControlStyleNone];
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
moviePlayerViewController.moviePlayer.shouldAutoplay = YES;
[moviePlayerViewController.moviePlayer setScalingMode: MPMovieScalingModeAspectFit];
moviePlayerViewController.view.frame = CGRectMake(0, 0, 480, 320);
[self.view addSubview:moviePlayerViewController.view];
请注意,您可能希望将movieSourceType更改为MPMovieSourceTypeFile或MPMovieSourceTypeUnknown。 上面的代码是我播放电影所需的100%(在我的情况下是一个流媒体频道)
答案 1 :(得分:1)
在我的情况下,我移动了
[window makeKeyAndVisible];
从
出来didFinishLaunchingWithOptions
进入我的
movieDidFinish
通过把它放回去工作