Как воспроизвести видео с прозрачным фоном в формате.flv / .mp4 в iOS-приложении?

Как воспроизвести видео с прозрачным фоном в формате.flv / .mp4 в iOS-приложении?

Я получаю черный фон вместо прозрачного фона при воспроизведении видео с помощью 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 ответ

MPMoviePlayerController отображается в своем собственном контексте. Если вы хотите добавить видео в UIViewcontroller (и я думаю, это то, что вы хотите, чтобы отобразить что-то под видео), вы должны использовать AVPLayer для воспроизведения видео и AVPlayerLayer для добавления видео в ваш просмотр.

Другие вопросы по тегам