diff --git a/Content/Media/baboon.png b/Content/Media/baboon.png new file mode 100644 index 000000000..188cae51b Binary files /dev/null and b/Content/Media/baboon.png differ diff --git a/Content/Media/earth.mp4 b/Content/Media/earth.mp4 new file mode 100644 index 000000000..b11552f9c Binary files /dev/null and b/Content/Media/earth.mp4 differ diff --git a/Content/Media/lomonosov.jpg b/Content/Media/lomonosov.jpg new file mode 100644 index 000000000..1a68fbffd Binary files /dev/null and b/Content/Media/lomonosov.jpg differ diff --git a/Content/Media/newtons_cradle.gif b/Content/Media/newtons_cradle.gif new file mode 100644 index 000000000..7c05ee1e7 Binary files /dev/null and b/Content/Media/newtons_cradle.gif differ diff --git a/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj b/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj index 418312c80..d3638e7be 100644 --- a/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj +++ b/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj @@ -28,7 +28,8 @@ - + + diff --git a/DeviceTests/DeviceTests.Shared/MediaGallery_Tests.cs b/DeviceTests/DeviceTests.Shared/MediaGallery_Tests.cs new file mode 100644 index 000000000..df7382f57 --- /dev/null +++ b/DeviceTests/DeviceTests.Shared/MediaGallery_Tests.cs @@ -0,0 +1,36 @@ +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using Xamarin.Essentials; +using Xunit; + +namespace DeviceTests.Shared +{ + public class MediaGallery_Tests + { + const string jpgName = "lomonosov.jpg"; + + [Fact] + [Trait(Traits.InteractionType, Traits.InteractionTypes.Human)] + public async Task SaveAsync() + { + var platform = DeviceInfo.Platform; + await MainThread.InvokeOnMainThreadAsync(async () => + { + if (platform == DevicePlatform.iOS || platform == DevicePlatform.macOS) + await Permissions.RequestAsync(); + else if (platform == DevicePlatform.Android) + await Permissions.RequestAsync(); + }); + + var assembly = typeof(MediaGallery_Tests).GetTypeInfo().Assembly; + var resourceName = assembly + .GetManifestResourceNames() + .FirstOrDefault(n => n.EndsWith(jpgName)); + + using var fileStream = assembly.GetManifestResourceStream(resourceName); + + await MediaGallery.SaveAsync(MediaFileType.Image, fileStream, jpgName); + } + } +} diff --git a/Samples/Samples.Mac/Info.plist b/Samples/Samples.Mac/Info.plist index cd8219a3b..c81e407b8 100644 --- a/Samples/Samples.Mac/Info.plist +++ b/Samples/Samples.Mac/Info.plist @@ -45,5 +45,7 @@ NSContactsUsageDescription Contacts + NSPhotoLibraryUsageDescription + Photos diff --git a/Samples/Samples.UWP/Package.appxmanifest b/Samples/Samples.UWP/Package.appxmanifest index 58a3ef232..6d1c06da2 100644 --- a/Samples/Samples.UWP/Package.appxmanifest +++ b/Samples/Samples.UWP/Package.appxmanifest @@ -32,6 +32,8 @@ + + diff --git a/Samples/Samples/App.xaml.cs b/Samples/Samples/App.xaml.cs index ee6c39cef..f5032c1d3 100644 --- a/Samples/Samples/App.xaml.cs +++ b/Samples/Samples/App.xaml.cs @@ -24,10 +24,10 @@ public partial class App : Application public App() { - InitializeComponent(); - // Enable currently experimental features - Device.SetFlags(new string[] { "MediaElement_Experimental" }); + Device.SetFlags(new string[] { "MediaElement_Experimental", "RadioButton_Experimental" }); + + InitializeComponent(); VersionTracking.Track(); diff --git a/Samples/Samples/Helpers/EmbeddedResourceProvider.cs b/Samples/Samples/Helpers/EmbeddedResourceProvider.cs new file mode 100644 index 000000000..b4ca6d6a6 --- /dev/null +++ b/Samples/Samples/Helpers/EmbeddedResourceProvider.cs @@ -0,0 +1,44 @@ +using System.IO; +using System.Linq; +using System.Reflection; +using Xamarin.Forms; + +namespace Samples.Helpers +{ + public static class EmbeddedMedia + { + public const string baboonPng = "baboon.png"; + public const string earthMp4 = "earth.mp4"; + public const string lomonosovJpg = "lomonosov.jpg"; + public const string newtonsCradleGif = "newtons_cradle.gif"; + } + + public static class EmbeddedResourceProvider + { + static readonly Assembly assembly = typeof(EmbeddedResourceProvider).GetTypeInfo().Assembly; + static readonly string[] resources = assembly.GetManifestResourceNames(); + + public static Stream Load(string name) + { + name = GetFullName(name); + + if (string.IsNullOrWhiteSpace(name)) + return null; + + return assembly.GetManifestResourceStream(name); + } + + public static ImageSource GetImageSource(string name) + { + name = GetFullName(name); + + if (string.IsNullOrWhiteSpace(name)) + return null; + + return ImageSource.FromResource(name, assembly); + } + + static string GetFullName(string name) + => resources.FirstOrDefault(n => n.EndsWith($".Media.{name}")); + } +} diff --git a/Samples/Samples/Samples.csproj b/Samples/Samples/Samples.csproj index dd9a13ad1..fce159436 100644 --- a/Samples/Samples/Samples.csproj +++ b/Samples/Samples/Samples.csproj @@ -22,6 +22,7 @@ + diff --git a/Samples/Samples/View/MediaGalleryPage.xaml b/Samples/Samples/View/MediaGalleryPage.xaml new file mode 100644 index 000000000..a0a329751 --- /dev/null +++ b/Samples/Samples/View/MediaGalleryPage.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + +