Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在obj c中的avplayer视频上添加覆盖?_Ios_Objective C_Iphone_Overlay_Avplayer - Fatal编程技术网

Ios 如何在obj c中的avplayer视频上添加覆盖?

Ios 如何在obj c中的avplayer视频上添加覆盖?,ios,objective-c,iphone,overlay,avplayer,Ios,Objective C,Iphone,Overlay,Avplayer,我试图在视频上添加覆盖,但是使用上面的代码什么也没发生。你能建议我该如何处理代码吗。我无法在视频上看到任何效果,与以前的视频完全相同。您需要使用AVPlayerViewController的contentOverlayView属性。请在我的答案中找到示例代码: - (void)playMethod { NSURL *url = [[NSURL alloc] initWithString:@"https://www.rmp-streaming.com/media///bbb-360p.mp

我试图在视频上添加覆盖,但是使用上面的代码什么也没发生。你能建议我该如何处理代码吗。我无法在视频上看到任何效果,与以前的视频完全相同。

您需要使用AVPlayerViewController的contentOverlayView属性。请在我的答案中找到示例代码:

- (void)playMethod
{
    NSURL *url = [[NSURL alloc] initWithString:@"https://www.rmp-streaming.com/media///bbb-360p.mp4"];
    player = [AVPlayer playerWithURL:url];
    controller = [[AVPlayerViewController alloc] init];
    [self addChildViewController:controller];
    [self.view addSubview:controller.view];

    //to rotate to the landscape on click of play button
    [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@"orientation"];
    [UINavigationController attemptRotationToDeviceOrientation];

    //to open the view
    controller.view.frame = CGRectMake(0,0,667,375);
    controller.player = player;
    controller.showsPlaybackControls = YES;
    player.closedCaptionDisplayEnabled = NO;




    CALayer* overlayLayer = [CALayer layer];
    UIImage* overlayImage = nil;

    overlayImage = [UIImage imageNamed:@"apple.png"];
    //Create the parent layer
    CALayer *parentLayer = [CALayer layer];
    parentLayer.frame = CGRectMake(0, 0, 20, 20);
    CALayer *videoLayer = [CALayer layer];
    videoLayer.frame = CGRectMake(0, 0, 20, 20);

    [parentLayer addSublayer: videoLayer];
    [parentLayer addSublayer: overlayLayer];

    //Composes the composited video frame with a core animation layer
    AVVideoCompositionCoreAnimationTool *animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer: videoLayer inLayer: parentLayer];




    // to add the back button on player
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button1 addTarget:self
                action:@selector(backMethod)
      forControlEvents:UIControlEventTouchUpInside];
    [button1 setTitle:@"Back" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
     button1.frame = CGRectMake(50.0, CGRectGetMinY(controller.view.frame)+10, 160.0, 40.0);
    button1.tag = 1001;
    [self.view addSubview:button1];
    [controller.view  bringSubviewToFront:button1];
    [player pause];
    [player play];
}