Skip to content

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

License

Notifications You must be signed in to change notification settings

FelipeNicoletto/MediaFilesManager

Repository files navigation

MediaFilesManager

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

Platform Support

Platform Version
Xamarin.iOS iOS 8+
Xamarin.Android API 14+

Installing

Install the NuGet package MediaFilesManager:

nuget install MediaFilesManager

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:

using MediaFilesManager;
using Xamarin.Forms;

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

Releases

No releases published

Packages

No packages published

Languages