3

我正在使用以下代码:

NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"MovieName" ofType:@"mov"];
        NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath isDirectory:NO];
        MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
        moviePlayerController.contentURL = fileURL;
        moviePlayerController.fullscreen = YES;
        [moviePlayerController prepareToPlay];
        [moviePlayerController play];

但是,当执行代码时,会出现电影播放器​​,但永远不会加载电影。

为了我自己的理智,我添加了以下行:

NSData *thedata = [[NSData alloc]initWithContentsOfFile:filepath];

而且我可以验证电影确实存在,因为它已加载到 NSData 对象中。

我要去哪里工作

4

1 回答 1

2

试试这个 :

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MovieName" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath isDirectory:NO];

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc]    initWithContentURL:fileURL];
moviePlayerController.view.frame = self.view.bounds;
moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
moviePlayerController.fullscreen = YES;

[self.view addSubview:moviePlayerController.view];
[moviePlayerController prepareToPlay];
[moviePlayerController play];
于 2012-11-05T10:38:59.373 回答