Commit 453c97e0 authored by Martin Finkel's avatar Martin Finkel

Add tiny F# sample

parent bae443d4
......@@ -26,5 +26,6 @@
<DefineConstants>$(DefineConstants);MONO;ANDROID</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
</PropertyGroup>
</Project>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibVLCSharp\LibVLCSharp.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
// Learn more about F# at http://fsharp.org
open System
open LibVLCSharp.Shared
open LibVLCSharp
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
Core.Initialize()
let instance = new Instance()
let mp = new MediaPlayer(instance)
let media = new Media(instance, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", Media.FromType.FromLocation);
mp.Media <- media
mp.Play() |> ignore
let result = Console.ReadKey()
0 // return an integer exit code
......@@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibVLCSharp.Android.AWindow", "LibVLCSharp.Android.AWindow\LibVLCSharp.Android.AWindow.csproj", "{239A82A5-19A1-4382-8F9B-4A9705648017}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "LibVLCSharp.FSharp.Sample", "LibVLCSharp.FSharp.Sample\LibVLCSharp.FSharp.Sample.fsproj", "{86AF6388-68E1-42A3-A655-0A9799FF46C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -97,6 +99,18 @@ Global
{239A82A5-19A1-4382-8F9B-4A9705648017}.Release|x64.Build.0 = Release|Any CPU
{239A82A5-19A1-4382-8F9B-4A9705648017}.Release|x86.ActiveCfg = Release|Any CPU
{239A82A5-19A1-4382-8F9B-4A9705648017}.Release|x86.Build.0 = Release|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Debug|x64.ActiveCfg = Debug|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Debug|x64.Build.0 = Debug|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Debug|x86.ActiveCfg = Debug|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Debug|x86.Build.0 = Debug|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Release|Any CPU.Build.0 = Release|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Release|x64.ActiveCfg = Release|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Release|x64.Build.0 = Release|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Release|x86.ActiveCfg = Release|Any CPU
{86AF6388-68E1-42A3-A655-0A9799FF46C9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -4,7 +4,7 @@
<Summary>.NET bindings for LibVLC</Summary>
<Description>.NET bindings for LibVLC</Description>
<PackageTags>libvlc native xamarin .net video audio media mediaplayer</PackageTags>
<TargetFrameworks>netstandard2.0;MonoAndroid80;net461;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;MonoAndroid80;net461;netcoreapp2.0;</TargetFrameworks>
<RootNamespace>LibVLCSharp</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);</DefineConstants>
......
......@@ -11,13 +11,12 @@ namespace LibVLCSharp.Shared
{
struct Native
{
#if WINDOWS_UWP
[DllImport("kernel32.dll", EntryPoint = "LoadPackagedLibrary", SetLastError = true)]
internal static extern IntPtr LoadLibrary(string dllToLoad);
#elif WINDOWS_CLASSIC
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr LoadPackagedLibrary(string dllToLoad);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr LoadLibrary(string dllToLoad);
#elif ANDROID
#if ANDROID
[DllImport("libvlc", EntryPoint = "JNI_OnLoad")]
internal static extern int JniOnLoad(IntPtr javaVm, IntPtr reserved = default(IntPtr));
#endif
......@@ -40,9 +39,19 @@ namespace LibVLCSharp.Shared
InitializeWindows();
#elif ANDROID
InitializeAndroid();
#elif NETCORE
InitializeNetCore();
#endif
}
#if NETCORE
static void InitializeNetCore()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
InitializeWindows();
}
#endif
#if ANDROID
static void InitializeAndroid()
{
......@@ -52,9 +61,7 @@ namespace LibVLCSharp.Shared
$"{nameof(JniRuntime.CurrentRuntime.InvocationPointer)}: {JniRuntime.CurrentRuntime.InvocationPointer}");
}
#endif
//TODO: check if Store app
//TODO: Add Unload library func using handles
#if WINDOWS
static void InitializeWindows()
{
var myPath = new Uri(typeof(Instance).Assembly.CodeBase).LocalPath;
......@@ -63,27 +70,29 @@ namespace LibVLCSharp.Shared
throw new NullReferenceException(nameof(appExecutionDirectory));
var arch = Environment.Is64BitProcess ? Win64 : Win86;
var libvlccorePath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc), Path.Combine(arch, $"{Libvlccore}.dll"));
var libvlcPath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc), Path.Combine(arch, $"{Libvlc}.dll"));
LoadLibvlcLibraries(libvlccorePath, libvlcPath);
var libvlccorePath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlccore}.dll"));
var libvlcPath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlc}.dll"));
LoadLibvlcLibraries(libvlccorePath, libvlcPath);
}
//TODO: check if Store app
static void LoadLibvlcLibraries(string libvlccorePath, string libvlcPath)
{
if(string.IsNullOrEmpty(libvlccorePath)) throw new NullReferenceException(nameof(libvlccorePath));
if(string.IsNullOrEmpty(libvlcPath)) throw new NullReferenceException(nameof(libvlcPath));
if (string.IsNullOrEmpty(libvlccorePath)) throw new NullReferenceException(nameof(libvlccorePath));
if (string.IsNullOrEmpty(libvlcPath)) throw new NullReferenceException(nameof(libvlcPath));
_libvlccoreHandle = Native.LoadLibrary(libvlccorePath);
if(_libvlccoreHandle == IntPtr.Zero)
throw new InvalidOperationException("failed to load libvlccore with path " + libvlccorePath + ". Aborting...");
if (_libvlccoreHandle == IntPtr.Zero)
throw new InvalidOperationException("failed to load libvlccore with path " + libvlccorePath +
". Aborting...");
_libvlcHandle = Native.LoadLibrary(libvlcPath);
if (_libvlcHandle == IntPtr.Zero)
throw new InvalidOperationException("failed to load libvlc with path " + libvlcPath + ". Aborting...");
}
#endif
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment