如何在iPhone模拟器中播放视频

时间:2012-09-03 09:56:10

标签: ios-simulator mpmovieplayer

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

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

4 个答案:

答案 0 :(得分:3)

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

即可

在“videourl”中提供视频网址

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

它将在模拟器中完美运行

link也可以帮助您

答案 1 :(得分:2)

假设ARC。

例如,您可以在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];
}

答案 2 :(得分:2)

我写的头文件中的

MPMoviePlayerController *moviePlayer;

使用此属性:

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;

并在我初始化moviePlayer的方法中:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;

答案 3 :(得分: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];