Skip to content

Commit

Permalink
Publish v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryx93 committed Jul 15, 2023
1 parent 810390f commit 6614b6f
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 103 deletions.
1 change: 0 additions & 1 deletion Avalonia.Bass/MediaPlayer.Avalonia.Bass.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>2.0</VersionPrefix>
<VersionSuffix>preview3</VersionSuffix>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
64 changes: 39 additions & 25 deletions Avalonia.Mpv/MediaPlayer.Avalonia.Mpv.csproj
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>HanumanInstitute.MediaPlayer.Avalonia.Mpv</RootNamespace>
<LangVersion>default</LangVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>HanumanInstitute.MediaPlayer.Avalonia.Mpv</RootNamespace>
<LangVersion>default</LangVersion>
<PackageId>MediaPlayer.Avalonia.Mpv</PackageId>
<Authors>Etienne Charland</Authors>
<LangVersion>default</LangVersion>
<Title>MediaPlayer.Avalonia.Mpv</Title>
<Description>MPV media player for Avalonia</Description>
<Copyright>Copyright © 2021-2023 Etienne Charland</Copyright>
<PackageProjectUrl>https://github.com/mysteryx93/MediaPlayerUI.NET</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/mysteryx93/MediaPlayerUI.NET</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>2.0</VersionPrefix>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\LibMpv-OpenGL\Src\LibMpv.Avalonia\LibMpv.Avalonia.csproj" />
<ProjectReference Include="..\..\LibMpv-OpenGL\Src\LibMpv\LibMpv.csproj" />
<ProjectReference Include="..\Avalonia\MediaPlayer.Avalonia.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Avalonia\MediaPlayer.Avalonia.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>test.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>test.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="HanumanInstitute.LibMpv.Avalonia" Version="0.9.1" />
</ItemGroup>

</Project>
72 changes: 32 additions & 40 deletions Avalonia.Mpv/MpvPlayerHost.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Interactivity;
using Avalonia.Threading;
using HanumanInstitute.LibMpv;
using HanumanInstitute.LibMpv.Avalonia;
Expand All @@ -21,7 +23,7 @@ public class MpvPlayerHost : PlayerHostBase, IDisposable
public MpvPlayerHost()
{
PlayerView = new MpvView();
this.VisualChildren.Add(PlayerView);
VisualChildren.Add(PlayerView);
}

/// <summary>
Expand All @@ -31,29 +33,22 @@ public MpvPlayerHost()
{
Dispose(false);
}

// MpvContext property
public static readonly DirectProperty<MpvView, MpvContext?> MpvContextProperty = AvaloniaProperty.RegisterDirect<MpvView, MpvContext?>(
nameof(MpvContext), o => o.MpvContext, defaultBindingMode: BindingMode.OneWayToSource);
public MpvContext? MpvContext => PlayerView.MpvContext;

/// <summary>
/// Gets the MpvView class instance.
/// </summary>
public MpvView PlayerView { get; private set; }

/// <summary>
/// Gets the MpvContext class instance.
/// </summary>
public MpvContext? Player { get; private set; }

public bool IsMediaLoaded { get; private set; }

// /// <summary>
// /// Occurs after the media player is initialized.
// /// </summary>
// public event EventHandler? MediaPlayerInitialized;

/// <summary>
/// Occurs when a file playback ends. Reason contains the reason.
/// </summary>
public event EventHandler<MpvEndFileEventArgs>? MediaEndFile;

private bool _initLoaded;

/// <inheritdoc />
Expand All @@ -69,7 +64,7 @@ protected override void SourceChanged(string? value)
else
{
Status = PlaybackStatus.Stopped;
Player?.Stop().Invoke();
MpvContext?.Stop().Invoke();
}
}

Expand All @@ -93,22 +88,21 @@ protected set
}
}

protected override async void OnLoaded()
protected override async void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded();
base.OnLoaded(e);

await Task.Delay(100); // Fails to load if we don't give a slight delay.

Player = PlayerView.MpvContext!;
Player.FileLoaded += Player_FileLoaded;
Player.EndFile += Player_EndFile;
MpvContext!.FileLoaded += Player_FileLoaded;
MpvContext!.EndFile += Player_EndFile;

Player.TimePos.Changed += Player_PositionChanged;
MpvContext.TimePos.Changed += Player_PositionChanged;

var options = new MpvAsyncOptions { WaitForResponse = false };
await Player.Volume.SetAsync(base.Volume, options);
await Player.Speed.SetAsync(base.GetSpeed(), options);
await Player.LoopFile.SetAsync(base.Loop ? "yes" : "no", options);
await MpvContext.Volume.SetAsync(Volume, options);
await MpvContext.Speed.SetAsync(GetSpeed(), options);
await MpvContext.LoopFile.SetAsync(Loop ? "yes" : "no", options);

if (!string.IsNullOrEmpty(Source) && !_initLoaded)
{
Expand All @@ -120,29 +114,27 @@ private void Player_FileLoaded(object sender, EventArgs e)
{
Dispatcher.UIThread.Post(() =>
{
IsMediaLoaded = true;
Status = PlaybackStatus.Playing;
base.Duration = TimeSpan.FromSeconds(Player!.Duration.Get()!.Value);
base.OnMediaLoaded();
Duration = TimeSpan.FromSeconds(MpvContext!.Duration.Get()!.Value);
OnMediaLoaded();
});
}

private void Player_EndFile(object sender, MpvEndFileEventArgs e)
{
Dispatcher.UIThread.Post(() =>
{
IsMediaLoaded = false;
if (e.Reason == MpvEndFileReason.Error)
{
Status = PlaybackStatus.Error;
}
base.OnMediaUnloaded();
OnMediaUnloaded();
});
}

private void Player_PositionChanged(object sender, MpvValueChangedEventArgs<double, double> e)
{
Dispatcher.UIThread.Post(new Action(() => base.SetPositionNoSeek(TimeSpan.FromSeconds(e.NewValue!.Value))));
Dispatcher.UIThread.Post(() => base.SetPositionNoSeek(TimeSpan.FromSeconds(e.NewValue!.Value)));
}

/// <inheritdoc />
Expand All @@ -151,7 +143,7 @@ protected override void SetDisplayText()
Text = Status switch
{
PlaybackStatus.Loading => Properties.Resources.Loading,
PlaybackStatus.Playing => Title ?? System.IO.Path.GetFileName(Source),
PlaybackStatus.Playing => Title ?? Path.GetFileName(Source),
PlaybackStatus.Error => Properties.Resources.MediaError,
_ => ""
};
Expand All @@ -161,11 +153,11 @@ protected override void SetDisplayText()
protected override void PositionChanged(TimeSpan value, bool isSeeking)
{
base.PositionChanged(value, isSeeking);
lock (Player!)
lock (MpvContext!)
{
if (IsMediaLoaded && isSeeking)
{
Player.TimePos.Set(value.TotalSeconds);
MpvContext.TimePos.Set(value.TotalSeconds);
}
}
}
Expand All @@ -174,41 +166,41 @@ protected override void PositionChanged(TimeSpan value, bool isSeeking)
protected override void IsPlayingChanged(bool value)
{
base.IsPlayingChanged(value);
Player?.Pause.Set(!value);
MpvContext?.Pause.Set(!value);
}

/// <inheritdoc />
protected override void VolumeChanged(int value)
{
base.VolumeChanged(value);
Player?.Volume.Set(value);
MpvContext?.Volume.Set(value);
}

/// <inheritdoc />
protected override void SpeedChanged(double value)
{
base.SpeedChanged(value);
Player?.Speed.Set(value);
MpvContext?.Speed.Set(value);
}

/// <inheritdoc />
protected override void LoopChanged(bool value)
{
base.LoopChanged(value);
Player?.LoopFile.Set(value ? "yes" : "no");
MpvContext?.LoopFile.Set(value ? "yes" : "no");
}

private async Task LoadMediaAsync()
{
if (!IsLoaded || Design.IsDesignMode) { return; }

Player!.Stop().Invoke();
MpvContext!.Stop().Invoke();
if (!string.IsNullOrEmpty(Source))
{
_initLoaded = true;
Thread.Sleep(10);
Player.Pause.Set(!base.AutoPlay);
await Player.LoadFile(Source!).InvokeAsync();
MpvContext.Pause.Set(!AutoPlay);
await MpvContext.LoadFile(Source!).InvokeAsync();
}
}

Expand All @@ -234,7 +226,7 @@ protected virtual void Dispose(bool disposing)
}

// Unmanaged resources.
Player?.Dispose();
MpvContext?.Dispose();

_disposed = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Avalonia.Sample/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<Grid>
<ui:MediaPlayer x:Name="Player">
<!-- <bass:BassPlayerHost x:Name="PlayerHost" Source="E:\NaturalGrounding\AOA\Like a Cat.mp4" AutoPlay="true" /> -->
<mpv:MpvPlayerHost Source="/run/media/hanuman/Storage-ntfs/NaturalGrounding/AOA/Like a Cat.mp4" Volume="50" Loop="True" />
<mpv:MpvPlayerHost Source="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" Volume="80" Loop="True" />
<!-- Source="E:\Music\INNA\Body And The Sun\CD1\07 Fool Me.mp3" Pitch="0.9818181818181818181818" -->
</ui:MediaPlayer>
<!-- <ui:MediaPlayer Height="50" /> -->
Expand Down
8 changes: 4 additions & 4 deletions Avalonia.Sample/MediaPlayer.Avalonia.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-rc1.1" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-rc1.1" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.0-rc1.1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-rc1.1" />
<PackageReference Include="Avalonia" Version="11.0.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
</ItemGroup>
<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions Avalonia/MediaPlayer.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>2.0</VersionPrefix>
<VersionSuffix>preview3</VersionSuffix>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down Expand Up @@ -46,8 +45,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-rc1.1" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Avalonia" Version="11.0.0" />
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
Expand Down
3 changes: 2 additions & 1 deletion Avalonia/Styles/Default/Theme.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@
RecognizesAccessKey="True"
TextBlock.Foreground="{TemplateBinding Foreground}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
TextAlignment="Justify" />
</Border>
</ControlTemplate>
</Setter>
Expand Down
28 changes: 0 additions & 28 deletions MediaPlayerUI.Avalonia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaPlayer.Avalonia.Sample
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BassDlls", "BassDlls\BassDlls.csproj", "{9EC3DF89-E522-4ADF-8723-6D85F109CF29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMpv", "..\LibMpv-OpenGL\Src\LibMpv\LibMpv.csproj", "{D1D3224F-754B-4478-9935-6413CF454316}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMpv.Avalonia", "..\LibMpv-OpenGL\Src\LibMpv.Avalonia\LibMpv.Avalonia.csproj", "{2B29E570-ABFF-4879-89ED-B36D3C85401F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaPlayer.Avalonia.Mpv", "Avalonia.Mpv\MediaPlayer.Avalonia.Mpv.csproj", "{8ECD1532-B9CC-4352-857D-C97F6E67F3D6}"
EndProject
Global
Expand Down Expand Up @@ -80,30 +76,6 @@ Global
{9EC3DF89-E522-4ADF-8723-6D85F109CF29}.Release|x64.Build.0 = Release|Any CPU
{9EC3DF89-E522-4ADF-8723-6D85F109CF29}.Release|x86.ActiveCfg = Release|Any CPU
{9EC3DF89-E522-4ADF-8723-6D85F109CF29}.Release|x86.Build.0 = Release|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Debug|x64.ActiveCfg = Debug|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Debug|x64.Build.0 = Debug|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Debug|x86.ActiveCfg = Debug|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Debug|x86.Build.0 = Debug|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Release|Any CPU.Build.0 = Release|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Release|x64.ActiveCfg = Release|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Release|x64.Build.0 = Release|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Release|x86.ActiveCfg = Release|Any CPU
{D1D3224F-754B-4478-9935-6413CF454316}.Release|x86.Build.0 = Release|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Debug|x64.ActiveCfg = Debug|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Debug|x64.Build.0 = Debug|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Debug|x86.ActiveCfg = Debug|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Debug|x86.Build.0 = Debug|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Release|Any CPU.Build.0 = Release|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Release|x64.ActiveCfg = Release|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Release|x64.Build.0 = Release|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Release|x86.ActiveCfg = Release|Any CPU
{2B29E570-ABFF-4879-89ED-B36D3C85401F}.Release|x86.Build.0 = Release|Any CPU
{8ECD1532-B9CC-4352-857D-C97F6E67F3D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8ECD1532-B9CC-4352-857D-C97F6E67F3D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8ECD1532-B9CC-4352-857D-C97F6E67F3D6}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down

0 comments on commit 6614b6f

Please sign in to comment.