0

这是我播放视频的功能。但它只播放声音,没有观看视频

  -(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];

    }
4

1 回答 1

0

MPMoviePlayerController只是一个电影播放器​​,如果有意义的话,它实际上并不处理电影的显示。如果您需要将视频嵌入到您自己的视图层次结构中,您应该只使用 MPMoviePlayerController。听起来您不需要这样做,因为您正在全屏播放并且提到了自定义控件,因此请尝试使用MPMoviePlayerViewController。它可以完成从 URL 加载电影并使用本机控件显示视频所需的一切。只需使用您的 URL 实例化 MPMoviePlayerViewController 并将其呈现为模式视图,即

MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL urlWithString:moviePath]];
[self presentModalViewController:player];
[player release];
于 2011-07-06T16:45:22.037 回答