2011-12-15 73 views
2

我尝试这个但不工作我可以听到声音,但我看不到图像..我该如何解决这个问题?在视频中播放视频c

在应用程序委托类:

- (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]; 
} 

回答

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]; 
} 
+0

你为什么叫释放? –

1

看着你[R .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),你将所有的theMovie但在运行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]; 

} 

希望它的帮助。