Iphone 在iOS应用程序中播放视频:音频但无图片

Iphone 在iOS应用程序中播放视频:音频但无图片,iphone,video,audio,Iphone,Video,Audio,我想在我的iphone应用程序中播放一段短视频。当我使用下面的代码时,我只听到音频并看到 应用程序的常规视图。我想在这个视图上播放视频。 我能做些什么 NSBundle *bundle = [NSBundle mainBundle]; NSString *moviePath = [bundle pathForResource:@"LEADER" ofType:@"mov"]; NSURL *movieURL = [[NSURL fileURLWithPath:movie

我想在我的iphone应用程序中播放一段短视频。当我使用下面的代码时,我只听到音频并看到 应用程序的常规视图。我想在这个视图上播放视频。 我能做些什么

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"LEADER" ofType:@"mov"];
    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];

不要混淆
MPMoviePlayerController
mpmovieplayervewcontroller
。当您使用MPMoviePlayerController时,请这样使用它(通常用于iPad上的嵌入式视频):


当您使用MPMoviePlayServiceController时,请使用
PresentMoviePlayServiceController演示视频:
(通常用于全屏视频)。

唯一对我有效的魔法是

 - (void) playMovie {
    NSURL *url = [NSURL URLWithString: 
        @"http://www.example.com/video.mp4"];
    MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] 
        initWithContentURL:url];

    self.mc = controller; //Super important
    controller.view.frame = self.view.bounds; //Set the size

    [self.view addSubview:controller.view]; //Show the view
    [controller play]; //Start playing
}
在头文件中

@property (nonatomic,strong) MPMoviePlayerController* mc;

谢谢你的回答。尝试用您的建议替换MPMoviePlayerController部分,但不断出现错误。。。
 - (void) playMovie {
    NSURL *url = [NSURL URLWithString: 
        @"http://www.example.com/video.mp4"];
    MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] 
        initWithContentURL:url];

    self.mc = controller; //Super important
    controller.view.frame = self.view.bounds; //Set the size

    [self.view addSubview:controller.view]; //Show the view
    [controller play]; //Start playing
}
@property (nonatomic,strong) MPMoviePlayerController* mc;