在setFrame方法中播放视频

时间:2014-05-05 04:46:20

标签: ios objective-c video mpmovieplayercontroller

我必须在给定CGRectMake的情况下播放我的视频。但它总是只播放全屏。我正在使用MPMoviewPlayerViewController。

NSString *path;

    path=[[NSBundle mainBundle] pathForResource:@"solar" ofType:@"mp4"];

 mpviewController = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
mpviewController.view.frame = CGRectMake(0, 0, 200, 300);

    [self.view addSubview:mpviewController.view];

    [self presentMoviePlayerViewControllerAnimated:mpviewController];

3 个答案:

答案 0 :(得分:0)

你必须将MpMoiveScalling模式设置为宽高比适合所以只需设置这行代码即可。

  MPMoviePlayerController *obj; [obj   
    setScalingMode:MPMovieScalingModeFill];

它对我有用。

答案 1 :(得分:0)

删除此行,

[self presentMoviePlayerViewControllerAnimated:mpviewController];

工作示例代码,

 - (IBAction)playVideoAction:(id)sender
{
    float width = 200;
    float height = 300;
    MPMoviePlayerViewController* theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:moviePathURL];
    theMovie.view.frame = CGRectMake((self.view.frame.size.width - width)/2, (self.view.frame.size.height - height)/2, width, height);
    [self.view addSubview:theMovie.view];
}

答案 2 :(得分:0)

我在我的申请中应用此代码。

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
theMovie.view.frame = CGRectMake(0, 0, 200, 300);

感谢。