【问题标题】:playing intro movie on ipad在 ipad 上播放介绍电影
【发布时间】:2010-10-21 21:59:19
【问题描述】:

我正在尝试播放介绍电影(如闪屏)。它曾经适用于 sdk 3.0,但现在我正在为 iPad 做这件事。它没有运行电影,而是在视图出现之前显示黑屏。 这是我的代码

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"m4v" inDirectory:nil];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.fullscreen=YES;
moviePlayer.view.frame = CGRectMake(0, 0,1024,768);
[moviePlayer setShouldAutoplay:YES];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setRepeatMode:MPMovieRepeatModeNone];

[moviePlayer prepareToPlay];
[moviePlayer play];

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlaybackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:moviePlayer]; 
return YES;
}

这是我的电影PlaybackDidFinish

- (void) moviePlaybackDidFinish:(NSNotification*)notification
{

MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:theMovie];
theMovie.initialPlaybackTime = -1;
[theMovie pause]; 

[theMovie stop];
[theMovie release];
[window addSubview:viewController.view];
[window makeKeyAndVisible];


 }

我不知道我在这里缺少什么?
感谢您的帮助....
更新我刚刚发现它可以播放声音但没有视频....这很明显吗?请帮助

【问题讨论】:

    标签: iphone ipad ios4 mpmovieplayercontroller


    【解决方案1】:

    当您使用 MPMoviePlayerController 而不是 MPMoviePlayerViewController 时,我认为您需要在调用 play 之前将播放器的视图添加到您的视图层次结构中,根据文档:

    [player.view setFrame: myView.bounds];  // player's frame must match parent's
    [myView addSubview: player.view]; //add the player' view
    

    这可能解释了为什么您听到音频但什么都看不到,很确定您也需要先设置应用程序窗口(@98​​7654324@ 等)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多