繁体   English   中英

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

[英]How to play a transparent background video of .flv / .mp4 format in iOS application?

如何在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在其自己的上下文中显示。 如果要将视频添加到UIViewcontroller中(我想这就是您要在视频下方进行某些内容的显示),则应使用AVPLayer播放视频,并使用AVPlayerLayer将视频添加到视图中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM