-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #627 from JuanuMusic/video-placeholder
Video placeholder for Xamarin.Forms
- Loading branch information
Showing
22 changed files
with
826 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ build/ | |
bld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
.vscode/ | ||
|
||
# Visual Studo 2015 cache/options directory | ||
.vs/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
MediaManager.Forms/Platforms/Android/ImageSourceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Android.Content; | ||
using Android.Graphics; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.Android; | ||
|
||
namespace MediaManager.Forms | ||
{ | ||
public static partial class ImageSourceExtensions | ||
{ | ||
public static ImageSource ToImageSource(this Bitmap bitmap) | ||
{ | ||
if (bitmap != null) | ||
{ | ||
var stream = new MemoryStream(); | ||
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream); | ||
var bitmapData = stream.ToArray(); | ||
return ImageSource.FromStream(() => new MemoryStream(bitmapData)); | ||
} | ||
return null; | ||
} | ||
|
||
public static async Task<Bitmap> ToNative(this ImageSource source) | ||
{ | ||
return await source.ToNative(Android.App.Application.Context); | ||
} | ||
|
||
public static async Task<Bitmap> ToNative(this ImageSource source, Context context) | ||
{ | ||
var imageHandler = source.GetImageSourceHandler(); | ||
if (imageHandler == null) | ||
return null; | ||
|
||
return await imageHandler.LoadImageAsync(source, context); | ||
} | ||
|
||
public static IImageSourceHandler GetImageSourceHandler(this ImageSource source) | ||
{ | ||
//check the specific source type and return the correct image source handler | ||
switch (source) | ||
{ | ||
case FileImageSource _: | ||
return new FileImageSourceHandler(); | ||
case StreamImageSource _: | ||
return new StreamImagesourceHandler(); | ||
case FontImageSource _: | ||
return new FontImageSourceHandler(); | ||
case UriImageSource _: | ||
default: | ||
return new ImageLoaderSourceHandler(); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Threading.Tasks; | ||
using CoreGraphics; | ||
using UIKit; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.iOS; | ||
|
||
namespace MediaManager.Forms | ||
{ | ||
public static partial class ImageSourceExtensions | ||
{ | ||
public static ImageSource ToImageSource(this CGImage cgImage) | ||
{ | ||
return ImageSource.FromStream(() => new UIImage(cgImage).AsPNG().AsStream()); | ||
} | ||
|
||
public static ImageSource ToImageSource(this UIImage uIImage) | ||
{ | ||
return ImageSource.FromStream(() => uIImage.AsPNG().AsStream()); | ||
} | ||
|
||
public static async Task<UIImage> ToNative(this ImageSource source) | ||
{ | ||
var imageHandler = source.GetImageSourceHandler(); | ||
if (imageHandler == null) | ||
return null; | ||
|
||
return await imageHandler.LoadImageAsync(source); | ||
} | ||
|
||
public static IImageSourceHandler GetImageSourceHandler(this ImageSource source) | ||
{ | ||
//check the specific source type and return the correct image source handler | ||
switch (source) | ||
{ | ||
case FileImageSource _: | ||
return new FileImageSourceHandler(); | ||
case StreamImageSource _: | ||
return new StreamImagesourceHandler(); | ||
case FontImageSource _: | ||
return new FontImageSourceHandler(); | ||
case UriImageSource _: | ||
default: | ||
return new ImageLoaderSourceHandler(); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using AppKit; | ||
using CoreGraphics; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.MacOS; | ||
|
||
namespace MediaManager.Forms | ||
{ | ||
public static partial class ImageSourceExtensions | ||
{ | ||
public static ImageSource ToImageSource(this CGImage cgImage) | ||
{ | ||
return ImageSource.FromStream(() => new NSImage(cgImage, new CGSize(cgImage.Width, cgImage.Height)).AsTiff().AsStream()); | ||
} | ||
|
||
public static IImageSourceHandler GetImageSourceHandler(this ImageSource source) | ||
{ | ||
//check the specific source type and return the correct image source handler | ||
switch (source) | ||
{ | ||
case FileImageSource _: | ||
return new FileImageSourceHandler(); | ||
case StreamImageSource _: | ||
return new StreamImagesourceHandler(); | ||
case FontImageSource _: | ||
case UriImageSource _: | ||
default: | ||
return new ImageLoaderSourceHandler(); | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
MediaManager.Forms/Platforms/Tizen/ImageSourceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.Tizen; | ||
|
||
namespace MediaManager.Forms | ||
{ | ||
public static partial class ImageSourceExtensions | ||
{ | ||
public static IImageSourceHandler GetImageSourceHandler(this ImageSource source) | ||
{ | ||
//check the specific source type and return the correct image source handler | ||
switch (source) | ||
{ | ||
case FileImageSource _: | ||
return new FileImageSourceHandler(); | ||
case StreamImageSource _: | ||
return new StreamImageSourceHandler(); | ||
case FontImageSource _: | ||
case UriImageSource _: | ||
default: | ||
return new UriImageSourceHandler(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Windows.Storage.Streams; | ||
using Windows.UI.Xaml.Media.Imaging; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.UWP; | ||
|
||
namespace MediaManager.Forms | ||
{ | ||
public static partial class ImageSourceExtensions | ||
{ | ||
public static async Task<ImageSource> ToImageSource(this BitmapImage bitmapImage) | ||
{ | ||
IRandomAccessStreamReference random = RandomAccessStreamReference.CreateFromUri(bitmapImage.UriSource); | ||
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(await random.OpenReadAsync()); | ||
var pixelData = await decoder.GetPixelDataAsync(); | ||
var bitmapData = pixelData.DetachPixelData(); | ||
|
||
return ImageSource.FromStream(() => new MemoryStream(bitmapData)); | ||
} | ||
|
||
public static IImageSourceHandler GetImageSourceHandler(this ImageSource source) | ||
{ | ||
//check the specific source type and return the correct image source handler | ||
switch (source) | ||
{ | ||
case FileImageSource _: | ||
return new FileImageSourceHandler(); | ||
case StreamImageSource _: | ||
return new StreamImageSourceHandler(); | ||
case FontImageSource _: | ||
return new FontImageSourceHandler(); | ||
case UriImageSource _: | ||
default: | ||
return new UriImageSourceHandler(); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.WPF; | ||
|
||
namespace MediaManager.Forms | ||
{ | ||
public static partial class ImageSourceExtensions | ||
{ | ||
|
||
public static IImageSourceHandler GetImageSourceHandler(this ImageSource source) | ||
{ | ||
//check the specific source type and return the correct image source handler | ||
switch (source) | ||
{ | ||
case FileImageSource _: | ||
return new FileImageSourceHandler(); | ||
case StreamImageSource _: | ||
return new StreamImageSourceHandler(); | ||
case FontImageSource _: | ||
case UriImageSource _: | ||
default: | ||
return new UriImageSourceHandler(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.