Xamarin.MediaCapture 1.0.0

A cross platform wrapper for MediaCapture on iOS and Android

Install-Package Xamarin.MediaCapture -Version 1.0.0
dotnet add package Xamarin.MediaCapture --version 1.0.0
<PackageReference Include="Xamarin.MediaCapture" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xamarin.MediaCapture --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NetworkManager

A cross platform wrapper for MediaCapture on iOS and Android

Usage:

    using Subsystems.MediaCaptureShared.External;;

...
...

    private CMPMediaCaptureSharedProxy _mediaCaptureProxy;

Initialize

    _mediaCaptureProxy = new CMPMediaCaptureSharedProxy();

CaptureMediaAsync

    var capturedBytes = await _mediaCaptureProxy?.CaptureMediaAsync();
    CapturedImage.Source = ImageSource.FromStream(() =>
    {

        return (new MemoryStream(capturedBytes));

    });

CheckSelfPermission (Android)

    var capturePermissionInfo = CheckSelfPermission(Manifest.Permission.Camera);
    if (capturePermissionInfo == Permission.Denied)
        RequestPermissions(new string[] { Manifest.Permission.Camera }, 1);
    else
    {

        _mediaCaptureProxy = new CMPMediaCaptureSharedProxy(this);
        Xamarin.Forms.Application.Current.Properties["p1"] = _mediaCaptureProxy;
    }

OnRequestPermissionsResult (Android)

    public override void OnRequestPermissionsResult(int requestCode,
                                                            string[] permissions,
                                                            Permission[]
                                                            grantResults)
    {
        base.OnRequestPermissionsResult(requestCode,
                                        permissions,
                                        grantResults);
        if (requestCode != 1)
            return;

        if (grantResults[0] != Permission.Granted)
            return;

        _mediaCaptureProxy = new CMPMediaCaptureSharedProxy(this);
        Xamarin.Forms.Application.Current.Properties["p1"] = _mediaCaptureProxy;


    }

OnActivityResult (Android)

    protected override void OnActivityResult(int requestCode,
                                                Result resultCode,
                                                Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (requestCode != 1)
            return;

        if (data == null)
            return;

        Bitmap bitmap = null;

        if (data.Data == null) // camera            
            bitmap = data.Extras.Get("data") as Bitmap;
        else
        {

            var uri = data.Data;
            var imageStream = ContentResolver.OpenInputStream(uri);
            bitmap = BitmapFactory.DecodeStream(imageStream);

        }

        _mediaCaptureProxy.CancelCapture(bitmap);

    }

NetworkManager

A cross platform wrapper for MediaCapture on iOS and Android

Usage:

    using Subsystems.MediaCaptureShared.External;;

...
...

    private CMPMediaCaptureSharedProxy _mediaCaptureProxy;

Initialize

    _mediaCaptureProxy = new CMPMediaCaptureSharedProxy();

CaptureMediaAsync

    var capturedBytes = await _mediaCaptureProxy?.CaptureMediaAsync();
    CapturedImage.Source = ImageSource.FromStream(() =>
    {

        return (new MemoryStream(capturedBytes));

    });

CheckSelfPermission (Android)

    var capturePermissionInfo = CheckSelfPermission(Manifest.Permission.Camera);
    if (capturePermissionInfo == Permission.Denied)
        RequestPermissions(new string[] { Manifest.Permission.Camera }, 1);
    else
    {

        _mediaCaptureProxy = new CMPMediaCaptureSharedProxy(this);
        Xamarin.Forms.Application.Current.Properties["p1"] = _mediaCaptureProxy;
    }

OnRequestPermissionsResult (Android)

    public override void OnRequestPermissionsResult(int requestCode,
                                                            string[] permissions,
                                                            Permission[]
                                                            grantResults)
    {
        base.OnRequestPermissionsResult(requestCode,
                                        permissions,
                                        grantResults);
        if (requestCode != 1)
            return;

        if (grantResults[0] != Permission.Granted)
            return;

        _mediaCaptureProxy = new CMPMediaCaptureSharedProxy(this);
        Xamarin.Forms.Application.Current.Properties["p1"] = _mediaCaptureProxy;


    }

OnActivityResult (Android)

    protected override void OnActivityResult(int requestCode,
                                                Result resultCode,
                                                Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (requestCode != 1)
            return;

        if (data == null)
            return;

        Bitmap bitmap = null;

        if (data.Data == null) // camera            
            bitmap = data.Extras.Get("data") as Bitmap;
        else
        {

            var uri = data.Data;
            var imageStream = ContentResolver.OpenInputStream(uri);
            bitmap = BitmapFactory.DecodeStream(imageStream);

        }

        _mediaCaptureProxy.CancelCapture(bitmap);

    }

Release Notes

1. Initial Release for Media Capture component
2. Supports latest iOS nad Android

Version History

Version Downloads Last updated
1.0.0 210 10/22/2018