视频播放,但没有图片 - 只是声音?
问题描述:
编辑:如果你遇到这一点,并想知道如何我终于解决它,我放弃了在低于最终的代码,做这样的:视频播放,但没有图片 - 只是声音?
-(void)playMovieAtURL:(NSURL*)theURL{
mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.view.backgroundColor = [UIColor blackColor];
}
原帖:
这是我的代码 - 我把它从苹果网站拿下来,所以不应该成为一个问题。
它在didSelectRowAtIndexPath方法的UITableViewController中运行。
当您选择视频开始播放的行时 - 声音输出至少 - 但没有图片。任何想法为什么这是?我已经包含了这个框架。
该视频是我用于测试的苹果网站(一个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...
}
现在使用MPMoviePlayerViewController ...要简单得多。 :) 谢谢。 – 2010-08-29 15:28:30
好东西!真高兴你做到了。 :) – 2010-08-29 17:45:33