在使用MPMoviePlayerController显示视频时,我有时会出现黑屏。 我使用UIImagePickerController创建一个新视频或选择一个保存的视频。
我在下面的imagePickerController ::中创建了MPMoviePlayerController。 我在viewDidAppear中播放:。
如果创建了新电影,则电影可以正常播放,但在选择现有电影时则是黑屏。 在这两种情况下,我都有一个有效的电影上传。
我已经尝试了播放消息和没有播放消息。 有什么想法吗?
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage;
// Handle a still image picked from a photo album
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo)
{
editedImage = (UIImage *) [info objectForKey: UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage];
_image = (editedImage == nil) ? originalImage : editedImage;
_imageView.image = _image;
_imageParentView.hidden = NO;
}
// Handle a video picked from a photo album
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
{
_rawVideoURL = [info objectForKey: UIImagePickerControllerMediaURL];
_videoParentView.hidden = NO;
_player = [[MPMoviePlayerController alloc] initWithContentURL: _rawVideoURL];
}
[self dismissModalViewControllerAnimated: YES];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (_player != nil)
{
[_player prepareToPlay];
[_player.view setFrame: _videoView.bounds]; // player's frame must match parent's
[_videoView addSubview: _player.view];
_player.repeatMode = MPMovieRepeatModeOne;
_player.scalingMode = MPMovieScalingModeAspectFit;
[_player play];
}
}