【问题标题】:MPMoviePlayerViewController videos with transparent background具有透明背景的 MPMoviePlayerViewController 视频
【发布时间】:2013-05-05 19:32:23
【问题描述】:

我想在我的应用中播放一个具有透明背景的视频。它有一个人在透明背景上四处走动。唯一的问题是 MPMovieePlayer 似乎有黑色背景。如何让它透明?

这是我试过的代码:

-(void)playMovie
{
       NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"syncink movie" ofType:@"m4v"];
       NSLog(@"%@",resourcePath);
       NSURL *url = [NSURL fileURLWithPath:resourcePath];
       NSLog(@"%@",url);

       MPMoviePlayerViewController *moviePlayer;

       moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

       moviePlayer.moviePlayer.shouldAutoplay=YES;
       moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
       [moviePlayer.moviePlayer setFullscreen:NO animated:YES];
       [self.view addSubview:moviePlayer.view];

       moviePlayer.view.frame = CGRectMake(200, 600, 400, 300);

       [moviePlayer.moviePlayer play];

       moviePlayer.view.backgroundColor = [UIColor clearColor];

       for(UIView *aSubView in moviePlayer.view.subviews) 
       {
          aSubView.backgroundColor = [UIColor clearColor];
       }
}

但是

aSubView.backgroundColor = [UIColor clearColor];

似乎是在移除播放器的框架,而不是实际的背景。感谢您的帮助。

【问题讨论】:

    标签: ios


    【解决方案1】:

    您应该在这里使用MPMoviePlayerController,而不是MPMoviePlayerViewController。后者是呈现的视图控制器(通常以模态方式)。

    这样,当您将 moviePlayer.view 作为子视图添加到您的层次结构时,您将添加电影播放器​​视图本身,而不是包含电影播放器​​的视图(这是您看到的纯黑屏幕) .

    此外,通过使用MPMoviePlayerController,您可以将代码中的moviePlayer.moviePlayer 简化为moviePlayer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多