2014-11-21 70 views
0

如何在iOS應用程序中播放.flv/.mp4格式的透明背景視頻?如何在iOS應用程序中播放.flv/.mp4格式的透明背景視頻?

當使用MPMoviePlayerController播放視頻時,我使用黑色背景而不是透明背景。

任何想法如何玩透明背景?

  MPMoviePlayerController *player = [[MPMoviePlayerController alloc] init]; 
      player.controlStyle = MPMovieControlStyleNone; 
      player.repeatMode = MPMovieRepeatModeOne; 
      player.view.frame = videoImageView.frame; 
      player.shouldAutoplay = YES; 
      for(UIView* subV in player.view.subviews) { 
       subV.backgroundColor = [UIColor clearColor]; 
      } 
      for(UIView* subV in player.backgroundView.subviews) { 
       subV.backgroundColor = [UIColor clearColor]; 
      } 
      player.view.backgroundColor = [UIColor clearColor]; 
      player.backgroundView.backgroundColor = [UIColor clearColor]; 

      player.view.superview.backgroundColor = [UIColor clearColor]; 
      player.backgroundView.superview.backgroundColor = [UIColor clearColor]; 

      player.view.layer.backgroundColor = [[UIColor clearColor]CGColor]; 
      player.backgroundView.layer.backgroundColor = [[UIColor clearColor]CGColor]; 

我原來也用過AVPlayer,它也呈現出黑色的背景

 avAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Video_Thumb_01" ofType:@"mp4"]]]; 
     avPlayerItem =[[AVPlayerItem alloc]initWithAsset:avAsset]; 
     avPlayer = [[AVPlayer alloc]initWithPlayerItem:avPlayerItem]; 
     avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:avPlayer]; 
     [avPlayerLayer setFrame:videoImageView.frame]; 
     [avPlayerLayer setBackgroundColor:[[UIColor clearColor]CGColor]]; 
     [avPlayer seekToTime:kCMTimeZero]; 
     [avPlayer play]; 

回答

0

的MPMoviePlayerController顯示在它自己的環境。如果你想添加一個視頻到一個UIViewcontroller(我想這就是你想要的,因爲你想在視頻下面展示一些東西),你應該使用AVPLayer來播放視頻並使用AVPlayerLayer將視頻添加到你的視圖。

+0

我也曾使用AVPlayer,它也顯示黑色的背景,看更新的問題 – Rachit 2014-11-21 09:57:50

+0

也許這個教程可以幫助你:http://emilytoop.com/2012/05/16/playing-movies-with-an-alpha -channel-on-the-ipad/ – Amandir 2014-11-21 10:25:18

+0

./qtexportani .mov 未創建任何文件export_ .mov – Rachit 2014-11-21 11:50:47