2

使用 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];
}
}
4

0 回答 0