Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
add new media implementation for UWP which adds more functionality an…
Browse files Browse the repository at this point in the history
…d fixes some problems

- fixes #308, #448, #705, #774
  • Loading branch information
bruzkovsky committed Mar 25, 2020
1 parent 7bf789f commit dafccd7
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 2 deletions.
9 changes: 8 additions & 1 deletion nuget/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ Such as:
<string>This app needs access to the photo gallery.</string>

UWP
Set Webcam permission.
Set Webcam, Pictures Library and Videos Library permissions.

To enable the new media implementation, set the flag "UwpUseNewMediaImplementation" in the App.xaml.cs like this:

```c#
CrossMedia.SetFlags("UwpUseNewMediaImplementation");
Xamarin.Forms.Forms.Init(e);
```

Tizen
Please add the following Privileges in tizen-manifest.xml file:
Expand Down
3 changes: 3 additions & 0 deletions src/Media.Plugin.Sample/Media.Plugin.Sample.UWP/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Plugin.Media;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
Expand Down Expand Up @@ -50,6 +51,8 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

CrossMedia.SetFlags("UwpUseNewMediaImplementation");

rootFrame.NavigationFailed += OnNavigationFailed;
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
Xamarin.Forms.Forms.Init(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@

<Capabilities>
<Capability Name="internetClient" />
<uap:Capability Name="picturesLibrary"/>
<uap:Capability Name="videosLibrary"/>
<DeviceCapability Name="webcam"/>
</Capabilities>
</Package>
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public MediaPage()
var file = await CrossMedia.Current.TakeVideoAsync(new StoreVideoOptions
{
Name = "video.mp4",
Directory = "DefaultVideos",
Directory = "DefaultVideos"
});

if (file == null)
Expand Down
5 changes: 5 additions & 0 deletions src/Media.Plugin/Media.Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<DisableExtraReferences>false</DisableExtraReferences>

</PropertyGroup>

<PropertyGroup Condition=" $(TargetFramework.StartsWith('uap10.0')) ">
<DefineConstants>$(DefineConstants);UWP</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
<DebugSymbols>true</DebugSymbols>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
Expand Down
31 changes: 31 additions & 0 deletions src/Media.Plugin/Shared/CrossMedia.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Plugin.Media.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Plugin.Media
{
Expand Down Expand Up @@ -35,11 +37,40 @@ static IMedia CreateMedia()
{
#if NETSTANDARD1_0 || NETSTANDARD2_0
return null;
#elif UWP
return Flags.Contains(FeatureFlags.UwpUseNewMediaImplementation)
? (IMedia)new NewMediaImplementation()
: new MediaImplementation();
#else
return new MediaImplementation();
#endif
}

public static bool FlagsSet;
static IReadOnlyList<string> flags;
#if NETSTANDARD1_0
public static IReadOnlyList<string> Flags => flags ?? (flags = new List<string>());
#else
public static IReadOnlyList<string> Flags => flags ?? (flags = new List<string>().AsReadOnly());
#endif

public static void SetFlags(params string[] flags)
{
if (FlagsSet)
{
// Don't try to set the flags again if they've already been set
// (e.g., during a configuration change where OnCreate runs again)
return;
}

#if NETSTANDARD1_0
CrossMedia.flags = flags.ToList();
#else
CrossMedia.flags = flags.ToList().AsReadOnly();
#endif
FlagsSet = true;
}

internal static Exception NotImplementedInReferenceAssembly() =>
new NotImplementedException("This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.");

Expand Down
9 changes: 9 additions & 0 deletions src/Media.Plugin/Shared/FeatureFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Plugin.Media
{
static class FeatureFlags
{
#if UWP
internal const string UwpUseNewMediaImplementation = "UwpUseNewMediaImplementation";
#endif
}
}
Loading

0 comments on commit dafccd7

Please sign in to comment.