我尝试这个但不行,我能听到声音,但我看不到图像......我怎么能解决这个问题?
在app delegate类中:
- (IBAction)tanitimVideo:(id)sender {
// create our UnifeyeMobileViewController and present it
video* unifeyeMobileViewController = [[video alloc] initWithNibName:@"video" bundle:nil];
unifeyeMobileViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController presentModalViewController:unifeyeMobileViewController animated:YES];
[unifeyeMobileViewController release];
}
在video.m课程中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
答案 0 :(得分:1)
尝试使用 MPMoviePlayerViewController ,只需很少的代码即可使其正常工作,您可以从应用代理处完成所有操作;)
- (IBAction)tanitimVideo:(id)sender {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[self presentMoviePlayerViewControllerAnimated:mp];
[mp release];
}
答案 1 :(得分:1)
查看你的.m文件 -
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
////////// <<<<<>>>>>>>>>> //////////
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc]
initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
为什么要制作2个控制器(theMovie,moviePlayer),然后在电影中设置全部但运行moviePlayer。
它应该是这样的: - (void)viewDidLoad { [super viewDidLoad]; //从笔尖加载视图后进行任何其他设置。
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"debutteaser" ofType:@"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie setShouldAutoplay:YES];
[self presentMoviePlayerViewControllerAnimated:theMovie];
}
希望它有所帮助。