我在 iPhone 上播放视频时遇到问题。我在应用程序包中有一个文件,我试图在其中播放它,MPMoviePlayerController
但它只是显示黑屏。这是以下代码:
-(UIView*)createVideoPlayerOfWidth:(CGFloat)width
{
// The width for one of these can be half of the max width
//CGFloat widthAndHeight = width / 2.0f;
// TODO: Create a video player
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mov"]];
MPMoviePlayerController *playerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
[playerController prepareToPlay];
[playerController setShouldAutoplay:NO];
[playerController setScalingMode:MPMovieScalingModeAspectFit];
[playerController setControlStyle:MPMovieControlStyleEmbedded];
[playerController setRepeatMode:MPMovieRepeatModeNone];
// Resize the thumbnail of the video
[[playerController view] setFrame:CGRectMake(0, 0, width, width)];
return [playerController view];
}
它返回一个有效的 URL(如果找不到文件,pathForResource 将返回 nil)。我只是通过将 subView(函数返回的视图)添加到滚动视图来将其显示到屏幕上。我一直试图解决这个问题已经很久了,但一无所获。任何帮助深表感谢。
谢谢!