[英]How do I display video from AppDelegate in iOS4
现在,我想我知道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];
}
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%(在我的情况下是流媒体频道)
就我而言,我已经将
[window makeKeyAndVisible];
从
didFinishLaunchingWithOptions
并进入我的
movieDidFinish
通过放回去它起作用了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.