简体   繁体   中英

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

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

I am getting black background instead of transparent background when I play the video using MPMoviePlayerController.

Any idea how to play with transparent background?

            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];

I had also Used AVPlayer and it is also showing black background

        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 is displayed in it's own context. If you want to add a video to a UIViewcontroller (and I guess that's what you want as you want to deisplay something below the video), you should use AVPLayer to play the Video and use AVPlayerLayer to add the Video to your View.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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