1

Edit: if you come across this and want to know how I eventually solved it I gave up on that code below eventually and did this:

-(void)playMovieAtURL:(NSURL*)theURL{
    mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];

    [self presentMoviePlayerViewControllerAnimated:mediaPlayer];
    mediaPlayer.view.backgroundColor = [UIColor blackColor];

}

Original post:

This is my code - I took it off the apple site so shouldn't be a problem.

It runs in a UITableViewController on the didSelectRowAtIndexPath method.

When you select the row the video starts playing - the sound outputs at least - but there's no picture. Any idea why this is? I have included the framework.

The video is one off the apple website (a facetime video) that I used for testing.

 -(void)playMovieAtURL:(NSURL*)theURL{



        MPMoviePlayerController* theMovie =

        [[MPMoviePlayerController alloc] initWithContentURL: theURL];



        theMovie.scalingMode = MPMovieScalingModeAspectFill;

        theMovie.controlStyle = MPMovieControlStyleNone;



        // Register for the playback finished notification

        [[NSNotificationCenter defaultCenter]

         addObserver: self

         selector: @selector(myMovieFinishedCallback:)

         name: MPMoviePlayerPlaybackDidFinishNotification

         object: theMovie];



        // Movie playback is asynchronous, so this method returns immediately.

        [theMovie play];

    }
4

1 回答 1

1

MPMoviePlayerController 的行为在 OS 3.2 中发生了变化 - 您现在需要将电影播放器​​的视图显式添加到您的视图层次结构中 - 使用类似:

[aView addSubview:moviePlayerController.view];
moviePlayerController.view.frame = aView.frame;

或者,您可以使用 MPMoviePlayerViewController(3.2 中的新功能)来管理视图。

如果您的目标是 3.2 之前和之后的设备(例如 iOS 3.1 和 4.0),那么您将需要一些条件代码来确定代码正在运行的操作系统并进行相应的处理。我在以前的项目中使用过这个:

if ([moviePlayerController respondsToSelector:@selector(setFullscreen:animated:)]) {
    // Running on OS 3.2 or above
    // Code to add to a view here...
}
于 2010-08-29T14:29:04.080 回答