7

我正在开发一个 IOS 应用程序(使用 Storyoard)。我有一个视图控制器:

//movieViewController.h

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface movieViewController : UIViewController {

    MPMoviePlayerViewController *moviePlayer;

}

@property (strong, nonatomic) MPMoviePlayerViewController *moviePlayer;
-(void) playMovie;

@end


//movieViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.
    [self playMovie];
}

-(void)playMovie
{
    NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"movie"
                                                      ofType:@"mov"];

    moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL
                                                     fileURLWithPath:videoPath]];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}

当我运行时,我看到我的 viewController 带有一个“正在加载...”,这需要永远。 在此处输入图像描述

4

2 回答 2

1

你应该打电话-prepareToPlay和/或-play。PerMPMoviePlayerController的文档:

从 iOS 5.0 开始,为了便于更细粒度的播放控制,新的电影播放器​​不会自动准备播放。

于 2013-04-08T21:13:26.470 回答
0
-(IBAction)startVideo:(id)sender
{
    NSURL *video = [[NSURL alloc] initWithString:@"http://www.w3schools.com/html/movie.mp4"];
    MPMoviePlayerViewController *controller = [[MPMoviePlayerViewController alloc]initWithContentURL:video];
    controller.view.frame = CGRectMake(20, 50, 280, 180);

    控制器.movi​​ePlayer.view.center = self.view.center;
    [self.view addSubview:controller.view];

    [controller.movi​​ePlayer prepareToPlay];
    [controller.movi​​ePlayer 播放];
}
于 2015-03-05T07:11:02.407 回答