如何在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];
MPMoviePlayerController 显示在它自己的上下文中。如果你想将视频添加到UIView控制器(我想这就是你想要的,因为你想在视频下面播放一些东西),你应该使用AVPLayer播放视频并使用AVPlayerlayer将视频添加到你的视图中。