这是我正在播放视频的功能。但它只播放声音,视频未被观看
-(void)playMovieAtURL:(NSString *)moviePath
{
NSURL *movieURL=[NSURL URLWithString:moviePath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
NSLog(@"url : %@",movieURL);
[player setControlStyle:MPMovieControlStyleDefault];
[player setScalingMode:MPMovieScalingModeAspectFit];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidExitFullscreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[[player view]setFrame:[[self view]bounds]];
[[self view] addSubview:[player view]];
[player play];
}
答案 0 :(得分:0)
MPMoviePlayerController只是一个电影播放器,它实际上并不处理显示电影,如果这是有道理的。如果需要将视频嵌入到自己的视图层次结构中,则应该只使用MPMoviePlayerController。这听起来并不像你需要这样做,因为你是全屏播放并提到了自定义控件,所以请尝试使用MPMoviePlayerViewController。它可以执行从URL加载电影所需的一切,并使用本机控件显示视频。只需使用您的URL实例化MPMoviePlayerViewController并将其显示为模态视图,即
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL urlWithString:moviePath]];
[self presentModalViewController:player];
[player release];