Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maui winui #370

Open
wants to merge 14 commits into
base: 3.x
Choose a base branch
from
7 changes: 1 addition & 6 deletions samples/LibVLCSharp.MAUI.Sample/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LibVLCSharp.MAUI.Sample"
Shell.FlyoutBehavior="Disabled">

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

<ShellContent ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />
</Shell>
13 changes: 8 additions & 5 deletions samples/LibVLCSharp.MAUI.Sample/LibVLCSharp.MAUI.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>LibVLCSharp.MAUI.Sample</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<!-- Display name -->
<ApplicationTitle>LibVLCSharp.MAUI.Sample</ApplicationTitle>

<ApplicationTitle>LibVLCSharp.MAUI.SampleX</ApplicationTitle>
<WindowsPackageType>None</WindowsPackageType>
<!-- App Identifier -->
<ApplicationId>com.companyname.libvlcsharp.maui.sample</ApplicationId>
<ApplicationId>com.companyname.libvlcsharp.maui.samplex</ApplicationId>
<ApplicationIdGuid>49861f9e-48d3-45c0-b6a8-f591ad6d2010</ApplicationIdGuid>

<!-- Versions -->
Expand All @@ -24,7 +24,7 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -64,4 +64,7 @@
<ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
<PackageReference Include="VideoLAN.LibVLC.iOS" Version="3.3.18" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion samples/LibVLCSharp.MAUI.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<local:MainViewModel />
</ContentPage.BindingContext>

<shared:VideoView x:Name="VideoView" MediaPlayer="{Binding MediaPlayer}" MediaPlayerChanged="VideoView_MediaPlayerChanged" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<shared:VideoView x:Name="VideoView" MediaPlayer="{Binding MediaPlayer}" MediaPlayerChanged="VideoView_MediaPlayerChanged" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HandlerChanged="VideoView_HandlerChanged" />

</ContentPage>
15 changes: 15 additions & 0 deletions samples/LibVLCSharp.MAUI.Sample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public MainPage()
protected override void OnAppearing()
{
base.OnAppearing();
#if !WINDOWS
((MainViewModel)BindingContext).OnAppearing();
#endif
}

protected override void OnDisappearing()
Expand All @@ -25,5 +27,18 @@ private void VideoView_MediaPlayerChanged(object sender, MediaPlayerChangedEvent
{
((MainViewModel)BindingContext).OnVideoViewInitialized();
}

private void VideoView_HandlerChanged(object sender, EventArgs e)
{
#if WINDOWS
var windowsView = ((LibVLCSharp.Platforms.Windows.VideoView)VideoView.Handler.PlatformView);

windowsView.Initialized += (s, e) =>
{
((MainViewModel)BindingContext).Initialize(e.SwapChainOptions);
((MainViewModel)BindingContext).OnAppearing();
};
#endif
}
}
}
6 changes: 4 additions & 2 deletions samples/LibVLCSharp.MAUI.Sample/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class MainViewModel : INotifyPropertyChanged

public MainViewModel()
{
#if !WINDOWS
Initialize();
#endif
}

private LibVLC LibVLC { get; set; }
Expand All @@ -33,9 +35,9 @@ private void Set<T>(string propertyName, ref T field, T value)
}
}

private void Initialize()
internal void Initialize(string[] swapchainOptions = null)
{
LibVLC = new LibVLC(enableDebugLogs: true);
LibVLC = new LibVLC(enableDebugLogs: true, swapchainOptions);
using var media = new Media(LibVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"));

MediaPlayer = new Shared.MediaPlayer(LibVLC)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"nativeDebugging": false
"commandName": "Project",
"nativeDebugging": true
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<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> -->
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>LibVLCSharp.MAUI.Sample.MediaElement</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<WindowsPackageType>None</WindowsPackageType>
<!-- Display name -->
<ApplicationTitle>LibVLCSharp.MAUI.Sample.MediaElement</ApplicationTitle>
<!-- App Identifier -->
Expand All @@ -21,9 +21,7 @@
<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 -->
Expand All @@ -49,6 +47,9 @@
<ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
<PackageReference Include="VideoLAN.LibVLC.iOS" Version="3.3.18" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\LibVLCSharp.MAUI\LibVLCSharp.MAUI.csproj" />
<ProjectReference Include="..\..\..\src\LibVLCSharp\LibVLCSharp.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
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">
Appearing="ContentPage_Appearing"
Disappearing="ContentPage_Disappearing">

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

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

</vlc:MediaPlayerElement>
Expand Down
19 changes: 17 additions & 2 deletions samples/MAUI/LibVLCSharp.MAUI.Sample.MediaElement/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@ public partial class MainPage : ContentPage
public MainPage()
{
InitializeComponent();
MediaPlayerElement.PlaybackControls.VideoView.HandlerChanged += VideoView_HandlerChanged;
}

void OnAppearing(object sender, System.EventArgs e)
private void VideoView_HandlerChanged(object sender, EventArgs e)
{
#if WINDOWS
var windowsView = ((LibVLCSharp.Platforms.Windows.VideoView)MediaPlayerElement.PlaybackControls.VideoView.Handler.PlatformView);

windowsView.Initialized += (s, e) =>
{
((MainViewModel)BindingContext).OnAppearing(e.SwapChainOptions);
};
#endif
}

private void ContentPage_Appearing(object sender, EventArgs e)
{
base.OnAppearing();
#if !WINDOWS
((MainViewModel)BindingContext).OnAppearing();
#endif
}

void OnDisappearing(object sender, System.EventArgs e)
private void ContentPage_Disappearing(object sender, EventArgs e)
{
base.OnDisappearing();
((MainViewModel)BindingContext).OnDisappearing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public LibVLCSharp.Shared.MediaPlayer MediaPlayer
/// <summary>
/// Initialize LibVLC and playback when page appears
/// </summary>
public void OnAppearing()
public void OnAppearing(string[] swapchainOptions = null)
{
if (LibVLC == null)
{
LibVLC = new LibVLC(enableDebugLogs: true);
LibVLC = new LibVLC(enableDebugLogs: true, swapchainOptions);
}

if (MediaPlayer == null)
Expand All @@ -71,10 +71,10 @@ public void OnAppearing()
public void OnDisappearing()
{
MediaPlayer?.Dispose();
MediaPlayer = null;
//MediaPlayer = null;

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

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"nativeDebugging": false
"commandName": "Project",
"nativeDebugging": true
}
}
}
2 changes: 2 additions & 0 deletions src/LibVLCSharp.MAUI/Handlers/VideoViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using VideoViewImpl = LibVLCSharp.Platforms.Android.VideoView;
#elif IOS
using VideoViewImpl = LibVLCSharp.Platforms.iOS.VideoView;
#elif WINUI
using VideoViewImpl = LibVLCSharp.Platforms.Windows.VideoView;
#endif

namespace LibVLCSharp.MAUI
Expand Down
1 change: 1 addition & 0 deletions src/LibVLCSharp.MAUI/LibVLCSharp.MAUI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
2 changes: 1 addition & 1 deletion src/LibVLCSharp/Platforms/Windows/VideoViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class VideoViewBase : Control, IVideoView
/// </summary>
public VideoViewBase()
{
DefaultStyleKey = typeof(VideoViewBase);
DefaultStyleKey = typeof(VideoView);

Unloaded += (s, e) => DestroySwapChain();
#if !WINUI
Expand Down
6 changes: 4 additions & 2 deletions src/LibVLCSharp/Shared/MediaPlayerElement/SeekBarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ private bool ErrorOrEnded
{
get
{
var mediaPlayer = MediaPlayer;
return mediaPlayer == null ? true : mediaPlayer.State == VLCState.Error || mediaPlayer.State == VLCState.Ended;
var state = MediaPlayer?.State;
if (state == null)
return true;
return state == VLCState.Error || state == VLCState.Ended;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/LibVLCSharp/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vlc="using:LibVLCSharp.Platforms.Windows">

<Style TargetType="vlc:VideoViewBase">
<Style TargetType="vlc:VideoView">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="vlc:VideoViewBase">
<ControlTemplate TargetType="vlc:VideoView">
<SwapChainPanel x:Name="SwapChainPanel" />
</ControlTemplate>
</Setter.Value>
Expand Down