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.
#r "nuget: Xamarin.MediaCapture, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Xamarin.MediaCapture as a Cake Addin
#addin nuget:?package=Xamarin.MediaCapture&version=1.0.0

// Install Xamarin.MediaCapture as a Cake Tool
#tool nuget:?package=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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 592 10/22/2018