Iphone MediaPlayer框架iOS SDK

Iphone MediaPlayer框架iOS SDK,iphone,objective-c,ios,xcode,ipad,Iphone,Objective C,Ios,Xcode,Ipad,我正在尝试将视频应用到我的应用程序中,但我遇到了困难。我尝试过这个教程,它非常有用 但现在,当我试着运行我的应用程序并点击按钮时,视频框就会出现,并保持黑色。我的视频格式正确,我还确保使用MediaPlayer框架。以前有没有人遇到过这个问题,或者知道为什么会发生这种情况 这就是我所拥有的: -(IBAction)playMovie:(id)sender { UIButton *playButton = (UIButton *) sender; NSString *filep

我正在尝试将视频应用到我的应用程序中,但我遇到了困难。我尝试过这个教程,它非常有用

但现在,当我试着运行我的应用程序并点击按钮时,视频框就会出现,并保持黑色。我的视频格式正确,我还确保使用MediaPlayer框架。以前有没有人遇到过这个问题,或者知道为什么会发生这种情况

这就是我所拥有的:

-(IBAction)playMovie:(id)sender
{
    UIButton *playButton = (UIButton *) sender; 

    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"big-buck-bunny-clip" ofType:@"m4v"];

    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayerController];

    [moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)];

    [self.view addSubview:moviePlayerController.view];
    //moviePlayerController.fullscreen = YES;

    moviePlayerController.initialPlaybackTime = 5;

    [moviePlayerController play];

}

您是否已将MPMoviePlayerController的视图添加到视图中

MPMoviePlayerController *movieController = ...;
movieController.view.frame = self.view.bounds;
[self.view addSubview:movieController.view];
如果您将
shouldAutoplay
设置为YES,将controlStyle设置为
MPMovieControlStyleNone

--编辑 这就是我初始化我的播放器的方式,也许这会有所帮助。它正在播放HTTP实时流媒体视频,但它将播放您放入其中的任何内容。您应该尝试此示例中的url。如果它能工作,那么你的contentUrl肯定有问题

  url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
  self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
  moviePlayerController.view.frame = self.view.bounds;
  [self.view insertSubview:moviePlayerController.view atIndex:0];
  moviePlayerController.controlStyle = MPMovieControlStyleNone;
  moviePlayerController.shouldAutoplay = YES;
  [moviePlayerController prepareToPlay];

我也有同样的问题,也遵循同样的教程,但后来我发现类moviePlayerViewController更易于使用,您甚至不必担心关闭按钮

我使用了以下代码:(我认为它在ios5中工作得更好)


MoviePlayerController使用URL进行初始化需要一些时间,因此您可能还需要收听MPMovieMediaTypesAvailableNotification。如果您只需要播放视频,请删除[moviePlayerController play];消息并将其替换为moviePlayerController.shouldAutoplay=YES;这似乎不起作用。我还创建了一个新项目,以防我做错了什么,即使新项目不起作用。你知道其他针对iOS 5的MediaPlayer框架的好教程吗?不,唉,我不知道任何教程。您是否也尝试将fileURL和filePath变量放入NSLog?可能它们没有正确初始化。谢谢您的帮助。我已经运行了它,它工作得很好。您的moviePlayerController的引用很弱,因为它是在playMovie方法中定义的,并在电影开始播放之前发布。您需要为moviePlayerController提供强大的属性。
self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:finalurl];
moviePlayerViewController.view.frame = self.view.bounds;
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
moviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayerViewController.moviePlayer.shouldAutoplay = YES;
[moviePlayerViewController.moviePlayer prepareToPlay];
moviePlayerViewController.moviePlayer.fullscreen=YES;