0

我正在尝试从我的应用程序的资源文件夹(即本地视频)播放视频文件(m4v)。但我无法播放视频。我提到了苹果的 MPMoviePlayer 示例项目。

此外,当我为我的movieplayercontroller 对象提供背景颜色时,它出现在一些黑色视图的后面,而前面的黑色视图显示某些东西正在加载几秒钟但没有加载,它只会导致黑屏。

有人可以帮我解决它。请告诉我我做错了什么。

另外,我已经截取了有问题的屏幕截图,以便你们都能理解我想说的,但我不知道如何在这里发布。:(

4

1 回答 1

0
NSString *urlString = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
NSURL *urlObj = [NSURL fileURLWithPath:urlString];

UIGraphicsBeginImageContext(CGSizeMake(1,1));
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:urlObj];
UIGraphicsEndImageContext();

[player.view setBounds:self.view.bounds];
// when playing from server source type shoud be MPMovieSourceTypeStreaming
[player.moviePlayer setMovieSourceType:MPMovieSourceTypeStreaming]; // I was missing this line therefore video was not playing
[player.moviePlayer setScalingMode:MPMovieScalingModeAspectFill];


[self.view addSubview:player.view];
[player.moviePlayer play];
于 2013-04-12T10:00:40.567 回答