All Projects → dimonovdd → Xamarin.MediaGallery

dimonovdd / Xamarin.MediaGallery

Licence: MIT license
This plugin is designed to picking and save images and video files from native gallery of Android and iOS devices and capture photos

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Xamarin.MediaGallery

VersionTrackingPlugin
Version Tracking Plugin for Xamarin and Windows
Stars: ✭ 62 (-41.51%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
LaunchMapsPlugin
Launch External Maps Plugin for Xamarin and Windows
Stars: ✭ 49 (-53.77%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Improvexamarinbuildtimes
Tips and tricks on how to speed up the time it takes to compile a Xamarin app
Stars: ✭ 180 (+69.81%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
UITestSampleApp
A sample app to demonstrate how to create Xamarin UITests using the Page Object architecture, Backdoor Methods and App Links (aka Deep Linking)
Stars: ✭ 38 (-64.15%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
XamUI
Xamarin UI Challenges 🏆
Stars: ✭ 57 (-46.23%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Cognitive-Face-Xamarin
A client library that makes it easy to work with the Microsoft Cognitive Services Face API on Xamarin.iOS, Xamarin.Android, and Xamarin.Forms and/or Portable Class Libraries.
Stars: ✭ 18 (-83.02%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Prototype.Forms.Controls
This sample app contains a random mixture of Xamarin/Xamarin.Forms controls, views, and functionality snippets that I've created.
Stars: ✭ 21 (-80.19%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Simpleauth
The Simplest way to Authenticate and make Rest API calls in .Net
Stars: ✭ 148 (+39.62%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
SKOR.UI
UI Controls for Xamarin.Forms
Stars: ✭ 56 (-47.17%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Connectivityplugin
Connectivity Plugin for Xamarin and Windows
Stars: ✭ 253 (+138.68%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
XamSvg-Samples
Samples for Xamarin Svg enterprise cross platform and full featured Svg image control
Stars: ✭ 25 (-76.42%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
XamarinClipboardPlugin
Cross Platform Clipboard access for Xamarin
Stars: ✭ 24 (-77.36%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
WheelPicker-Samples
WheelPicker samples for the WheelPicker Xamarin Component
Stars: ✭ 18 (-83.02%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Xamarin.Plugin.ImageEdit
Image Edit Plugin for Xamarin
Stars: ✭ 52 (-50.94%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Microsoft.maui.graphics
Stars: ✭ 160 (+50.94%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Xamarin Playground
Random cool stuff I play around using Xamarin.. :3 Some of these cool projects I feature them on my blog, with step by step explanation. :) Don't forget to check it out. Go to: theconfuzedsourcecode.wordpress.com
Stars: ✭ 183 (+72.64%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Plugin.audiorecorder
Audio Recorder plugin for Xamarin and Windows
Stars: ✭ 140 (+32.08%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Xamarin.forms.videoplayer
A Xamarin Forms control to render the native video player on every platform.
Stars: ✭ 140 (+32.08%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
Xamarin Demos
This repository contains the Syncfusion Xamarin UI control’s samples and the guide to use them.
Stars: ✭ 218 (+105.66%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android
XamarinHOL
Xamarin ハンズオン用のレポジトリ&ドキュメントです。
Stars: ✭ 52 (-50.94%)
Mutual labels:  xamarin, xamarin-forms, xamarin-ios, xamarin-android

Xamarin.MediaGallery

header

NuGet Badge NuGet downloads license Xamarin.MediaGallery on fuget.org YouTube Video Views

This plugin is designed for picking and saving photos and video files from the native gallery of Android and iOS devices and capture photo.

Unfortunately, at the time of the release of this plugin, MediaPlugin by @jamesmontemagno is no longer supported, and Xamarin.Essentials has not received updates for about 2 months. This plugin has fixed bugs and added some features that are missing in Xamarin.Essentials. I hope that in the future it will be ported to MAUI so that developers have an easy way to add these features to their apps.

"Buy Me A Coffee"

Available Platforms

Platform Minimum OS Version
Android 5.0
iOS 11.0

TargetFrameworks

  • Xamarin.iOS10, net6.0-ios
  • MonoAndroid10.0, MonoAndroid11.0, net6.0-android
  • netstandard2.0, net6.0

Getting started

You can just watch the Video that @jfversluis published

Migration to 2.X.X version

Android

In the Android project's MainLauncher or any Activity that is launched, this plugin must be initialized in the OnCreate method:

protected override void OnCreate(Bundle savedInstanceState)
{
    //...
    base.OnCreate(savedInstanceState);
    NativeMedia.Platform.Init(this, savedInstanceState);
    //...
}

iOS (Optional)

In the iOS project's AppDelegate that is launched, this plugin can be initialized in the FinishedLaunching method:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    NativeMedia.Platform.Init(GetTopViewController);
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());
    return base.FinishedLaunching(app, options);
}

public UIViewController GetTopViewController()
{
    var vc = UIApplication.SharedApplication.KeyWindow.RootViewController;

    if (vc is UINavigationController navController)
        vc = navController.ViewControllers.Last();

    return vc;
}

PickAsync

This method does not require requesting permissions from users

var cts = new CancellationTokenSource();
IMediaFile[] files = null;

try
{
    var request = new MediaPickRequest(1, MediaFileType.Image, MediaFileType.Video)
    {
        PresentationSourceBounds = System.Drawing.Rectangle.Empty,
        UseCreateChooser = true,
        Title = "Select"
    };

    cts.CancelAfter(TimeSpan.FromMinutes(5));

    var results = await MediaGallery.PickAsync(request, cts.Token);
    files = results?.Files?.ToArray();
}
catch (OperationCanceledException)
{
    // handling a cancellation request
}
catch (Exception)
{
    // handling other exceptions
}
finally
{
    cts.Dispose();
}


if (files == null)
    return;

foreach (var file in files)
{
    var fileName = file.NameWithoutExtension; //Can return an null or empty value
    var extension = file.Extension;
    var contentType = file.ContentType;
    using var stream = await file.OpenReadAsync();
    //...
    file.Dispose();
}

This method has two overloads:

  • Task<MediaPickResult> PickAsync(int selectionLimit = 1, params MediaFileType[] types)
  • Task<MediaPickResult> PickAsync(MediaPickRequest request, CancellationToken token = default)

Android

To handle runtime results on Android, this plugin must receive any OnActivityResult.

protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
{
   if (NativeMedia.Platform.CheckCanProcessResult(requestCode, resultCode, intent))
   NativeMedia.Platform.OnActivityResult(requestCode, resultCode, intent);
   
   base.OnActivityResult(requestCode, resultCode, intent);
}
  • When using the PickAsync method the selectionLimit parameter just sets multiple pick allowed
  • A request to cancel PickAsync method will cancel a task, but the picker UI can remain open until it is closed by the user
  • The use of Title property depends on each device
  • UseCreateChooser property has not been used since version 2.0.0

iOS

  • Multi picking is supported since iOS version 14.0+ On older versions, the plugin will prompt the user to select a single file
  • The NameWithoutExtension property on iOS versions before 14 returns a null value if the permission to access photos was not granted
  • Title property not used
  • UseCreateChooser property not used

Presentation Location

When picking files on iPadOS you have the ability to present in a pop over control. This specifies where the pop over will appear and point an arrow directly to. You can specify the location using the PresentationSourceBounds property. Setting this property has the same behavior as Launcher or Share in Xamarin.Essentials.

PresentationSourceBounds property takes System.Drawing.Rectangle for Xamarin or Microsoft.Maui.Graphics.Rectangle for .net6(MAUI)

Screenshots:

Сapture Photo with Metadata

//...
if (!MediaGallery.CheckCapturePhotoSupport())
    return;

var status = await Permissions.RequestAsync<Permissions.Camera>();

if (status != PermissionStatus.Granted)
    return;

using var file = await MediaGallery.CapturePhotoAsync()

NameWithoutExtension will always return $"IMG_{DateTime.Now:yyyyMMdd_HHmmss}" value.

Android

Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node.

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />

If Camera is not required in your application, you can specify false.

<queries>
  <intent>
    <action android:name="android.media.action.IMAGE_CAPTURE" />
  </intent>
</queries>

iOS

In your Info.plist add the following keys:

<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>

SaveAsync

//...
var status = await Permissions.RequestAsync<SaveMediaPermission>();

if (status != PermissionStatus.Granted)
    return;

await MediaGallery.SaveAsync(MediaFileType.Video, filePath);

//OR Using a byte array or a stream

await MediaGallery.SaveAsync(MediaFileType.Image, stream, fileName);

//The name or the path to the saved file must contain the extension.

//...

Permission

Add Xamarin.MediaGallery.Permision or Xamarin.MediaGallery.Permision.Maui nuget package to use the SaveMediaPermission

Android

Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node.

<!-- for saving photo/video -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • When saving media files, the date and time are appended to the file name

iOS

In your Info.plist add the following keys:

<!-- for saving photo/video on iOS 14+ -->
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery for saving photos and videos</string>

<!-- for saving photo/video on older versions -->
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to the photo gallery for saving photos and videos</string>

Screenshots

______________ iOS Android ______________
iOS Android
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].