-1

I want to get the screenshot while video is playing.

Xamarin.Forms.VideoPlayer did't provide the capture method.

So I use DependencyService to call my ios Capture method below

public class ScreenshotService : IScreenshotService
{

    public byte[] Capture(VideoPlayer videoPlayer)
    {
        var capture = UIScreen.MainScreen.Capture();

        using (NSData data = capture.AsJPEG())
        {
            var bytes = new byte[data.Length];
            Marshal.Copy(data.Bytes, bytes, 0, Convert.ToInt32(data.Length));
            return bytes;
        }
    }
}

Then:

var img = ImageSource.FromStream(() => new MemoryStream(screenshotData));

In the image, my video player is a black area.

Is there any solution I can do?

1 Answers1

0

Solution:

According to the Definition of the function:

you can use OpenTK.Platform.iPhoneOS.iPhoneOSGameView.Capture() to capture a video content.

 // Summary:
    //     Captures a screenshot of the entire screen.
    //
    // Returns:
    //     A screenshot as a UIKit.UIImage.
    //
    // Remarks:
    //     This API will only capture UIKit and Quartz drawing, because it uses the screen's
    //     CALayer's RenderInContext method to perform the screenshot. It will not capture
    //     OpenGL ES or video content.
    //     If you want to capture an OpenGL ES or video content use the OpenTK.Platform.iPhoneOS.iPhoneOSGameView.Capture()
    //     method.
    public UIImage Capture();
nevermore
  • 15,432
  • 1
  • 12
  • 30