如何在iOS应用程序中播放.flv / .mp4格式的透明背景视频?

时间:2014-11-21 09:10:17

标签: ios iphone transparency mp4 flv

如何在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];

1 个答案:

答案 0 :(得分:0)

MPMoviePlayerController显示在它自己的上下文中。如果你想将一个视频添加到UIViewcontroller(我想这就是你想要在视频下方取消显示的内容),你应该使用AVPLayer来播放视频并使用AVPlayerLayer将视频添加到你的图。

相关问题