-1

我想在 iPhone 模拟器中播放视频。我尝试过使用 MPMoviePlayerViewController,但它没有播放。有人知道怎么做吗?如果有什么好的教程,请帮我找一个。谢谢。

注意:与 MPMoviePlayerViewController 不是 MPMoviePlayerController 相关的问题

4

4 回答 4

3

只需将视频文件拖放到您的 Xcode 项目中

在“videourl”中给出视频的url

NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];     
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];

它将在模拟器中完美运行

这个链接也可以帮助你

于 2012-09-03T10:00:56.290 回答
2

假设弧。

例如,您可以在 viewDidLoad 方法中调用它,并使用以下方法将该控制器添加到您的视图中:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"test" ofType:@"m4v"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];

   [self.view addSubview:theMovie.view];
    [self addChildViewController:theMovie];
}
于 2012-09-03T10:01:53.697 回答
2

在我的头文件中我写:

MPMoviePlayerController *moviePlayer;

使用此属性:

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;

在我初始化moviePlayer的方法中:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;
于 2012-09-03T10:02:00.483 回答
2

使用以下代码

MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:yourVideoURL];

moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self 
                                        selector:@selector(movieFinishedCallback:)
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:moviePlayer1];
[moviePlayer1 play];
于 2012-09-03T10:20:12.097 回答