Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LibVLCSharp.MAUI.Sample.MediaElement"
x:Class="LibVLCSharp.MAUI.Sample.MediaElement.App">
<Application.Resources>

</Application.Resources>
</Application>
51 changes: 51 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;

namespace LibVLCSharp.MAUI.Sample.MediaElement
{
/// <summary>
/// Represents the main App.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Initializes a new instance of <see cref="App"/> class.
/// </summary>
public App()
{
InitializeComponent();
ConfigureUnhandledExceptionHandling();

MainPage = new MainPage();
}

private static void ConfigureUnhandledExceptionHandling()
{
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
if (e.ExceptionObject is Exception ex)
{
HandleException(ex);
}
};

TaskScheduler.UnobservedTaskException += (sender, e) =>
{
if (e.Exception is Exception ex)
{
HandleException(ex);
}
e.SetObserved(); // Prevents the process from terminating.
};
}

private static void HandleException(Exception ex)
{
if (ex != null)
{
Console.WriteLine(ex.Message);
}
}
}
}
14 changes: 14 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="LibVLCSharp.MAUI.Sample.MediaElement.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LibVLCSharp.MAUI.Sample.MediaElement"
Shell.FlyoutBehavior="Disabled">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
16 changes: 16 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace LibVLCSharp.MAUI.Sample.MediaElement
{
/// <summary>
/// Represents the main shell of the application.
/// </summary>
public partial class AppShell : Shell
{
/// <summary>
/// Initializes a new instance of the <see cref="AppShell"/> class.
/// </summary>
public AppShell()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>LibVLCSharp.MAUI.Sample.MediaElement</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<!-- Display name -->
<ApplicationTitle>LibVLCSharp.MAUI.Sample.MediaElement</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.companyname.libvlcsharp.maui.sample.mediaelement</ApplicationId>
<ApplicationIdGuid>3e92aff6-59b5-48cd-a2a0-3ecb5d63d8fb</ApplicationIdGuid>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
<PackageReference Include="VideoLAN.LibVLC.Android" Version="3.5.3" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
<PackageReference Include="VideoLAN.LibVLC.iOS" Version="3.3.18" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\LibVLCSharp.MAUI\LibVLCSharp.MAUI.csproj" />
<ProjectReference Include="..\..\..\src\LibVLCSharp\LibVLCSharp.csproj" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties XamarinHotReloadDebuggerTimeoutExceptionLibVLCSharpMAUISampleMediaElementHideInfoBar="True" />
</VisualStudio>
</ProjectExtensions>
</Project>
22 changes: 22 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LibVLCSharp.MAUI.Sample.MediaElement"
xmlns:vlc="clr-namespace:LibVLCSharp.MAUI;assembly=LibVLCSharp.MAUI"
x:Class="LibVLCSharp.MAUI.Sample.MediaElement.MainPage"
Appearing="OnAppearing"
Disappearing="OnDisappearing">

<ContentPage.BindingContext>
<local:MainViewModel />
</ContentPage.BindingContext>

<vlc:MediaPlayerElement MediaPlayer="{Binding MediaPlayer}" LibVLC="{Binding LibVLC}" EnableRendererDiscovery="True" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<vlc:MediaPlayerElement.PlaybackControls>
<vlc:PlaybackControls
IsAspectRatioButtonVisible="True" IsSeekButtonVisible="True" IsCastButtonVisible="True" />
</vlc:MediaPlayerElement.PlaybackControls>

</vlc:MediaPlayerElement>

</ContentPage>
30 changes: 30 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Maui.Controls;

namespace LibVLCSharp.MAUI.Sample.MediaElement
{
/// <summary>
/// Represnets the Main Page.
/// </summary>
public partial class MainPage : ContentPage
{
/// <summary>
/// Initializes a new instance of <see cref="MainPage"/> class.
/// </summary>
public MainPage()
{
InitializeComponent();
}

void OnAppearing(object sender, System.EventArgs e)
{
base.OnAppearing();
((MainViewModel)BindingContext).OnAppearing();
}

void OnDisappearing(object sender, System.EventArgs e)
{
base.OnDisappearing();
((MainViewModel)BindingContext).OnDisappearing();
}
}
}
92 changes: 92 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using LibVLCSharp.Shared;

namespace LibVLCSharp.MAUI.Sample.MediaElement
{
/// <summary>
/// Represents the main viewmodel.
/// </summary>
public class MainViewModel : INotifyPropertyChanged
{
/// <summary>
/// Property changed event
/// </summary>
public event PropertyChangedEventHandler PropertyChanged = null!;

/// <summary>
/// Initializes a new instance of <see cref="MainViewModel"/> class.
/// </summary>
public MainViewModel()
{
}

private LibVLC _libVLC;

/// <summary>
/// Gets the <see cref="LibVLCSharp.Shared.LibVLC"/> instance.
/// </summary>
public LibVLC LibVLC
{
get => _libVLC;
private set => SetProperty(ref _libVLC, value);
}

private LibVLCSharp.Shared.MediaPlayer _mediaPlayer;
/// <summary>
/// Gets the <see cref="LibVLCSharp.Shared.MediaPlayer"/> instance.
/// </summary>
public LibVLCSharp.Shared.MediaPlayer MediaPlayer
{
get => _mediaPlayer;
private set => SetProperty(ref _mediaPlayer, value);
}

/// <summary>
/// Initialize LibVLC and playback when page appears
/// </summary>
public void OnAppearing()
{
if (LibVLC == null)
{
LibVLC = new LibVLC(enableDebugLogs: true);
}

if (MediaPlayer == null)
{
var media = new Media(LibVLC, new Uri("http://streams.videolan.org/streams/mkv/multiple_tracks.mkv"));
MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(media)
{
EnableHardwareDecoding = true
};
media.Dispose();
MediaPlayer.Play();
}
}

/// <summary>
/// Dispose MediaPlayer and LibVLC when page disappears
/// </summary>
public void OnDisappearing()
{
MediaPlayer?.Dispose();
MediaPlayer = null;

LibVLC?.Dispose();
LibVLC = null;
}

/// <summary>
/// Set property and notify UI
/// </summary>
private void SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
{
if (!Equals(field, value))
{
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
33 changes: 33 additions & 0 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.Extensions.Logging;

namespace LibVLCSharp.MAUI.Sample.MediaElement
{
/// <summary>
/// The MauiProgram class is responsible for creating and configuring the MAUI application.
/// </summary>
public static class MauiProgram
{
/// <summary>
/// Creates and configures the MAUI application.
/// </summary>
/// <returns>The configured MAUI application.</returns>
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.UseLibVLCSharp(); // Add your custom fonts and handler from your library

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Android.App;
using Android.Content.PM;
using Android.OS;
using Microsoft.Maui;

namespace LibVLCSharp.MAUI.Sample.MediaElement
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Runtime;

namespace LibVLCSharp.MAUI.Sample.MediaElement
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
Loading
Loading