Skip to content

Commit

Permalink
Fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn00 committed Aug 1, 2019
1 parent 84d5be1 commit c26fef8
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
29 changes: 29 additions & 0 deletions MediaManager.Forms/ImageSourceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xamarin.Forms;

namespace MediaManager.Forms
{
public static class ImageSourceHelper
{
public static ImageSource ToImageSource(this object image)
{
#if ANDROID
if (image is Android.Graphics.Bitmap bitmap)
return MediaManager.Forms.Platforms.Android.ImageSourceHelper.ToImageSource(bitmap);
#elif IOS
if (image is CoreGraphics.CGImage cgImage)
return MediaManager.Forms.Platforms.Ios.ImageSourceHelper.ToImageSource(cgImage);
else if (image is UIKit.UIImage uIImage)
return MediaManager.Forms.Platforms.Ios.ImageSourceHelper.ToImageSource(uIImage);
#elif WINDOWS
//TODO: This one should not be async. It might deadlock
if (image is Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage)
return MediaManager.Forms.Platforms.Uap.ImageSourceHelper.ToImageSource(bitmapImage).GetAwaiter().GetResult();
#endif
return null;
}
}
}
24 changes: 24 additions & 0 deletions MediaManager.Forms/Platforms/Uap/ImageSourceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using Xamarin.Forms;
using System.IO;
using System.Threading.Tasks;

namespace MediaManager.Forms.Platforms.Uap
{
public static class ImageSourceHelper
{
public static async Task<ImageSource> ToImageSource(this BitmapImage bitmapImage)
{
IRandomAccessStreamReference random = RandomAccessStreamReference.CreateFromUri(bitmapImage.UriSour‌​ce);
Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(await random.OpenReadAsync());
Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();
byte[] bitmapData = pixelData.DetachPixelData();

return ImageSource.FromStream(() => new MemoryStream(bitmapData));
}
}
}
4 changes: 3 additions & 1 deletion Samples/ElementPlayer.Core/ElementPlayer.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -16,9 +16,11 @@
<PackageReference Include="MvvmCross" Version="6.3.1" />
<PackageReference Include="MvvmCross.Plugin.Json" Version="6.3.1" />
<PackageReference Include="MvvmCross.Plugin.Visibility" Version="6.3.1" />
<PackageReference Include="Xamarin.Forms" Version="4.1.0.581479" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\MediaManager.Forms\MediaManager.Forms.csproj" />
<ProjectReference Include="..\..\MediaManager.Reactive\MediaManager.Reactive.csproj" />
<ProjectReference Include="..\..\MediaManager\MediaManager.csproj" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion Samples/ElementPlayer.Core/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ private async Task SelectItem(IMediaItem mediaItem)
await this.NavigationService.Navigate<PlayerViewModel>();

var item = await CrossMediaManager.Current.MediaExtractor.CreateMediaItem("https://file-examples.com/wp-content/uploads/2018/04/file_example_MOV_480_700kB.mov");
var image = await CrossMediaManager.Current.MediaExtractor.GetVideoFrame(item, new System.TimeSpan(0,0,2));
//var image = await CrossMediaManager.Current.MediaExtractor.GetVideoFrame(item, new System.TimeSpan(0,0,2));

await MediaManager.Play(item);

//await MediaManager.Play(mediaItem);
//await MediaManager.Play(Mp3UrlList);
Expand Down
16 changes: 16 additions & 0 deletions Samples/ElementPlayer.Core/ViewModels/PlayerViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using System.Threading.Tasks;
using MediaManager;
using MediaManager.Forms;
using MediaManager.Media;
using MediaManager.Playback;
using MediaManager.Player;
using MvvmCross.Commands;
using MvvmCross.Logging;
using MvvmCross.Navigation;
using Xamarin.Forms;

namespace ElementPlayer.Core.ViewModels
{
Expand Down Expand Up @@ -42,6 +45,19 @@ public PlayerViewModel(IMvxLogProvider logProvider, IMvxNavigationService naviga

public IMediaItem Current => MediaManager.MediaQueue.Current;

private ImageSource _image;
public ImageSource Image {
get => _image;
set => SetProperty(ref _image, value);
}

public override async Task Initialize()
{
var item = await CrossMediaManager.Current.MediaExtractor.CreateMediaItem("https://file-examples.com/wp-content/uploads/2018/04/file_example_MOV_480_700kB.mov");
var image = await MediaManager.MediaExtractor.GetVideoFrame(item, TimeSpan.FromSeconds(5));
Image = image.ToImageSource();
}

public string CurrentTitle => Current.GetTitle();
public string CurrentSubtitle => Current.GetContentTitle();

Expand Down
3 changes: 2 additions & 1 deletion Samples/ElementPlayer.Forms.UI/Pages/PlayerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
x:Class="ElementPlayer.Forms.UI.Pages.PlayerPage"
x:TypeArguments="viewModels:PlayerViewModel">
<ContentPage.Content>
<StackLayout>
<StackLayout Orientation="Vertical">
<Image Source="{Binding Image}" HorizontalOptions="FillAndExpand" HeightRequest="200" />
<mm:VideoView VerticalOptions="FillAndExpand" ShowControls="True" />
</StackLayout>
</ContentPage.Content>
Expand Down

0 comments on commit c26fef8

Please sign in to comment.