MediaFilesManager 1.0.1

Simple cross platform plugin to access images and videos on Android and iOS

There is a newer version of this package available.
See the version list below for details.
Install-Package MediaFilesManager -Version 1.0.1
dotnet add package MediaFilesManager --version 1.0.1
<PackageReference Include="MediaFilesManager" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MediaFilesManager --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Simple cross platform plugin to access images and videos on Android and iOS.

Platform Support

  • iOS 8+
  • Android API 14+

API Usage

Call CrossMediaFileManager.Current.GetAlbumsAsync()

Task<IMediaAlbum[]> GetAlbumsAsync();

The result is an array of all device's imagens and videos albums (IMediaAlbum[])

public interface IMediaAlbum
{
    string Title { get; }

    IMediaFile[] GetAllMediaFiles(MediaAlbumContentType contentTypes = MediaAlbumContentType.All);
    
    MediaAlbumContentType GetContentTypes();
    
    IMediaFile GetMediaFileAtIndex(int index, MediaAlbumContentType contentTypes = MediaAlbumContentType.All);
    
    int GetMediaFilesCount(MediaAlbumContentType contentTypes = MediaAlbumContentType.All);
}

Get all images and videos from an album:

IMediaFile[] files = album.GetAllMediaFiles(MediaAlbumContentType.Images | MediaAlbumContentType.Videos);

Get the file's thumbnail:

 var file = files[0] as IMediaFileWithImage;

 ImageStream stream = file.GetImage(MediaFileGetImageOptions.CreateDefaultThumb());

Get custom image:

var file = files[0] as IMediaFileWithImage;

var options = new MediaFileGetImageOptions
{
    Width = 500,
    Height = 500,
    Quality = 90,
    Orientation = MediaFileImageOrientation.Right,                          // Rotate image to right
    ResizeAspect = MediaFileGetImageOptions.ImageResizeAspect.AspectFit     
};

ImageStream stream = file.GetImage(options);

Get the full size file's stream:

Stream stream = files[0].GetStream();

Android specific in your BaseActivity or MainActivity (for Xamarin.Forms) add this code:

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);

    MediaFileManager.Initialize(Forms.Context);

    LoadApplication(new App());
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);

    MediaFileManager.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Samples

  • Albums

  • Photos

  • Rotated

Simple cross platform plugin to access images and videos on Android and iOS.

Platform Support

  • iOS 8+
  • Android API 14+

API Usage

Call CrossMediaFileManager.Current.GetAlbumsAsync()

Task<IMediaAlbum[]> GetAlbumsAsync();

The result is an array of all device's imagens and videos albums (IMediaAlbum[])

public interface IMediaAlbum
{
    string Title { get; }

    IMediaFile[] GetAllMediaFiles(MediaAlbumContentType contentTypes = MediaAlbumContentType.All);
    
    MediaAlbumContentType GetContentTypes();
    
    IMediaFile GetMediaFileAtIndex(int index, MediaAlbumContentType contentTypes = MediaAlbumContentType.All);
    
    int GetMediaFilesCount(MediaAlbumContentType contentTypes = MediaAlbumContentType.All);
}

Get all images and videos from an album:

IMediaFile[] files = album.GetAllMediaFiles(MediaAlbumContentType.Images | MediaAlbumContentType.Videos);

Get the file's thumbnail:

 var file = files[0] as IMediaFileWithImage;

 ImageStream stream = file.GetImage(MediaFileGetImageOptions.CreateDefaultThumb());

Get custom image:

var file = files[0] as IMediaFileWithImage;

var options = new MediaFileGetImageOptions
{
    Width = 500,
    Height = 500,
    Quality = 90,
    Orientation = MediaFileImageOrientation.Right,                          // Rotate image to right
    ResizeAspect = MediaFileGetImageOptions.ImageResizeAspect.AspectFit     
};

ImageStream stream = file.GetImage(options);

Get the full size file's stream:

Stream stream = files[0].GetStream();

Android specific in your BaseActivity or MainActivity (for Xamarin.Forms) add this code:

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);

    MediaFileManager.Initialize(Forms.Context);

    LoadApplication(new App());
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);

    MediaFileManager.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Samples

  • Albums

  • Photos

  • Rotated

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.2 578 2/4/2018
1.0.1 390 12/13/2017
1.0.0 471 11/8/2017