Skip to content

Commit 10809dd

Browse files
committed
fix(Avalonia): remove LibVLC for dependency on ffplay
1 parent ab362c9 commit 10809dd

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

SnapX.Avalonia/SnapX.Avalonia.csproj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<AssemblyName>snapx-ui</AssemblyName>
1212
<AssemblyTitle>SnapX UI</AssemblyTitle>
1313
<ApplicationIcon>Assets\SnapX_Icon.ico</ApplicationIcon>
14-
<InvariantGlobalization>true</InvariantGlobalization>
14+
<InvariantGlobalization>false</InvariantGlobalization>
1515
<!-- Recommended Avalonia trimming settings for Native AOT -->
1616
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
1717
<BuiltInComInteropSupport>false</BuiltInComInteropSupport>
1818
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1919
<TrimMode>full</TrimMode>
2020
<PublishTrimmed>true</PublishTrimmed>
2121
<Optimize>true</Optimize>
22-
<AvaloniaVersion>11.3.1</AvaloniaVersion>
22+
<AvaloniaVersion>11.3.2</AvaloniaVersion>
2323
<SkiaSharpVersion>3.119.0</SkiaSharpVersion>
2424
<HarfBuzzSharpVersion>8.3.1.1</HarfBuzzSharpVersion>
2525
<!-- After investigation, this needs to be an absolute path. It should be set by our build script later down the road. -->
@@ -57,22 +57,17 @@
5757
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="$(HarfBuzzSharpVersion)" />
5858
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="$(HarfBuzzSharpVersion)" />
5959
<PackageReference Include="HarfBuzzSharp.NativeAssets.Win32" Version="$(HarfBuzzSharpVersion)" />
60-
<PackageReference Include="LibVLCSharp.Avalonia" Version="3.9.3" />
6160
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
6261
<PackageReference Include="SkiaSharp" Version="$(SkiaSharpVersion)" />
6362
<!-- We prefer the NoDependencies flavor -->
6463
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="$(SkiaSharpVersion)" ExcludeAssets="all" />
6564
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="$(SkiaSharpVersion)" />
6665
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="$(SkiaSharpVersion)" />
6766
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="$(SkiaSharpVersion)" />
68-
<PackageReference Condition="$([MSBuild]::IsOsPlatform('OSX'))" Include="VideoLAN.LibVLC.Mac" Version="3.1.3.1" />
69-
<PackageReference Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
70-
<PackageReference Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="VideoLAN.LibVLC.Windows.GPL" Version="3.0.21" />
7167
<ProjectReference Include="..\SnapX.CommonUI\SnapX.CommonUI.csproj" />
7268
</ItemGroup>
7369
<ItemGroup>
7470
<Folder Include="Controls\" />
75-
<VlcWindowsX86ExcludeFiles Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="%2A%2A" />
7671

7772
</ItemGroup>
7873
</Project>

SnapX.Avalonia/SnapXAvalonia.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using LibVLCSharp.Shared;
1+
using System.Diagnostics;
22
using SnapX.Core;
3+
using SnapX.Core.Utils.Extensions;
34

45
namespace SnapX.Avalonia;
56

@@ -8,22 +9,35 @@ public class SnapXAvalonia : Core.SnapX
89
public override async Task PlaySound(Stream stream)
910
{
1011
DebugHelper.WriteLine($"PlaySound {stream.Length} bytes {stream.Position} {stream.CanSeek} {stream.CanRead}");
11-
var vlc = new LibVLC(enableDebugLogs: false);
12-
DebugHelper.WriteLine($"VLC Version: {vlc.Version}");
13-
var MediaPlayer = new MediaPlayer(vlc);
14-
var input = new StreamMediaInput(stream);
15-
var mediaOptions = new[] { ":input-title-format=flac" };
16-
17-
var media = new Media(vlc, input, mediaOptions);
18-
media.AddOption(":input-title-format=flac");
19-
MediaPlayer.EnableHardwareDecoding = true;
20-
MediaPlayer.Play(media);
21-
MediaPlayer.Stopped += async (Sender, Args) =>
12+
var tempFilePath = Path.GetTempFileName();
13+
stream.Seek(0, SeekOrigin.Begin);
14+
stream.WriteToFile(tempFilePath);
15+
var psi = new ProcessStartInfo
2216
{
23-
await stream.DisposeAsync();
24-
media.Dispose();
25-
input.Dispose();
26-
vlc.Dispose();
17+
FileName = "ffplay", // Even on Windows, we expect ffplay to be in the $PATH. https://winstall.app/apps/Gyan.FFmpeg
18+
Arguments = $"-nodisp -autoexit -hide_banner -loglevel warning \"{tempFilePath}\"",
19+
UseShellExecute = false,
20+
RedirectStandardOutput = false,
21+
RedirectStandardError = false,
22+
CreateNoWindow = true
2723
};
24+
25+
try
26+
{
27+
using var process = Process.Start(psi);
28+
if (process is not null) await process.WaitForExitAsync();
29+
}
30+
finally
31+
{
32+
try
33+
{
34+
File.Delete(tempFilePath);
35+
}
36+
catch
37+
{
38+
/* ignore */
39+
}
40+
}
41+
2842
}
2943
}

0 commit comments

Comments
 (0)