0

I am using the youtube cocoapod library to embed a video in my app. I am playing it inline. I have a requirement to take some screenshot of the app. I use the following code to take the screenshot

UIGraphicsBeginImageContext(self.view.frame.size);
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

In the generated image, the place that has the youtube video running is empty. How can I get the screenshot of the video as well ? Is it cause because, the youtube video runs inside an iframe in a webview ??

Golak Sarangi
  • 809
  • 7
  • 22

2 Answers2

0

Here is a undocumented way to do this.

OBJC_EXTERN UIImage *_UICreateScreenUIImage(void);

// ...

- (IBAction)doScreenshotButton:(id)sender {
    UIImage *screenImage = _UICreateScreenUIImage();
    // do something with your screenshot
}

Still looking for an API-safe alternative.

AniV
  • 3,997
  • 1
  • 12
  • 17
  • That worked on the Simulator but not on device (which yielded only a black frame). Also hoping for a solution. – Joe Rosen Sep 25 '17 at 23:02
0

A member's response from the below Stackoverflow link pointed me in the right direction and helped solve the issue. My own solution's a kluge but it does work (my code/solution also included in my comment at the below URL).

Get a current frame from Youtube YTPlayerView

Joe Rosen
  • 171
  • 1
  • 9