2013-05-05 205 views
0

MPMoviePlayerViewController視頻,我想我的應用程序裏面播放的具有透明背景的視頻。它有一個人在透明背景上移動。唯一的問題是,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];

似乎是刪除玩家的框架,而不是實際的背景。謝謝你的幫助。

回答

0

您應該使用MPMoviePlayerController這裏,而不是MPMoviePlayerViewController。後者是呈現的視圖控制器(通常以模態方式)。

這樣,當您將moviePlayer.view作爲子視圖添加到層​​次結構中時,您將添加電影播放器​​視圖本身,而不是包含電影播放器​​的視圖(這是您看到的平面黑色屏幕)。

另外,通過使用MPMoviePlayerController,您可以簡化您的代碼中的moviePlayer.moviePlayer到只有moviePlayer