mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
Added VLC Strix audio service impl
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
#if OPENZUNE
|
||||
|
||||
using LibVLCSharp.Shared;
|
||||
using NAudio.Wave;
|
||||
using StrixMusic.Sdk.MediaPlayback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using StrixPlaybackState = StrixMusic.Sdk.MediaPlayback.PlaybackState;
|
||||
|
||||
namespace Microsoft.Zune.Playback
|
||||
{
|
||||
public class VlcAudioService : IAudioPlayerService
|
||||
{
|
||||
readonly LibVLC m_vlc;
|
||||
readonly MediaPlayer m_player;
|
||||
private Media m_media;
|
||||
private PlaybackItem m_currentSource;
|
||||
|
||||
public static VlcAudioService Instance => new();
|
||||
|
||||
private VlcAudioService()
|
||||
{
|
||||
Core.Initialize();
|
||||
|
||||
bool debug =
|
||||
#if DEBUG
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
|
||||
m_vlc = new(enableDebugLogs: debug);
|
||||
m_player = new(m_vlc);
|
||||
}
|
||||
|
||||
public PlaybackItem CurrentSource
|
||||
{
|
||||
get => m_currentSource;
|
||||
set
|
||||
{
|
||||
m_currentSource = value;
|
||||
CurrentSourceChanged?.Invoke(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan Position { get; private set; }
|
||||
|
||||
public StrixPlaybackState PlaybackState => m_player.State switch
|
||||
{
|
||||
VLCState.Playing => StrixPlaybackState.Playing,
|
||||
|
||||
VLCState.Paused or
|
||||
VLCState.Stopped => StrixPlaybackState.Paused,
|
||||
|
||||
VLCState.Opening or
|
||||
VLCState.Buffering => StrixPlaybackState.Loading,
|
||||
|
||||
VLCState.Error => StrixPlaybackState.Failed,
|
||||
|
||||
_ => StrixPlaybackState.None
|
||||
};
|
||||
|
||||
public double Volume
|
||||
{
|
||||
get => m_player.Volume / 100d;
|
||||
private set
|
||||
{
|
||||
m_player.Volume = (int)(value * 100);
|
||||
VolumeChanged?.Invoke(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double PlaybackSpeed
|
||||
{
|
||||
get => m_player.Rate;
|
||||
private set
|
||||
{
|
||||
m_player.SetRate((float)value);
|
||||
VolumeChanged?.Invoke(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler<PlaybackItem> CurrentSourceChanged;
|
||||
public event EventHandler<float[]> QuantumProcessed;
|
||||
public event EventHandler<TimeSpan> PositionChanged;
|
||||
public event EventHandler<StrixPlaybackState> PlaybackStateChanged;
|
||||
public event EventHandler<double> VolumeChanged;
|
||||
public event EventHandler<double> PlaybackSpeedChanged;
|
||||
|
||||
public Task ChangePlaybackSpeedAsync(double speed, CancellationToken cancellationToken = default)
|
||||
{
|
||||
PlaybackSpeed = speed;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task ChangeVolumeAsync(double volume, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Volume = (float)volume;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task PauseAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
m_player.Pause();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task Play(PlaybackItem sourceConfig, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (CurrentSource != sourceConfig)
|
||||
await Preload(sourceConfig, cancellationToken);
|
||||
|
||||
m_player.Play(m_media);
|
||||
}
|
||||
|
||||
public async Task Preload(PlaybackItem sourceConfig, CancellationToken cancellationToken = default)
|
||||
{
|
||||
CurrentSource = sourceConfig;
|
||||
var uri = sourceConfig.MediaConfig.MediaSourceUri;
|
||||
var stream = sourceConfig.MediaConfig.FileStreamSource;
|
||||
|
||||
if (uri != null)
|
||||
{
|
||||
m_media = new(m_vlc, uri);
|
||||
}
|
||||
else if (stream != null)
|
||||
{
|
||||
m_media = new(m_vlc, new StreamMediaInput(stream));
|
||||
}
|
||||
|
||||
await m_media.Parse(MediaParseOptions.ParseNetwork | MediaParseOptions.ParseLocal, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
public Task ResumeAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
m_player.Play();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task SeekAsync(TimeSpan position, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,7 @@
|
||||
<ApplicationVersion>4.8.0.0</ApplicationVersion>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
||||
<TargetFrameworks>net35;net40;netstandard2.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net35;net40;netstandard2.0;net6.0;net6.0-windows</TargetFrameworks>
|
||||
<Platforms>x64;x86</Platforms>
|
||||
<RootNamespace>Microsoft.Zune</RootNamespace>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<Choose>
|
||||
<When Condition=" '$(TargetFramework)' == 'net6.0' ">
|
||||
<When Condition=" $(TargetFramework.StartsWith('net6.0')) ">
|
||||
<PropertyGroup>
|
||||
<UseOpenZune>True</UseOpenZune>
|
||||
<DefineConstants>$(DefineConstants);NETSTANDARD2_1_OR_GREATER</DefineConstants>
|
||||
@@ -48,6 +48,9 @@
|
||||
<ItemGroup Condition="$(UseOpenZune)">
|
||||
<PackageReference Include="StrixMusic.Sdk" Version="0.0.11-alpha" />
|
||||
<PackageReference Include="StrixMusic.Cores.LocalFiles" Version="1.0.0" />
|
||||
|
||||
<PackageReference Include="LibVLCSharp" Version="3.6.6" />
|
||||
|
||||
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -60,4 +63,8 @@
|
||||
<ProjectReference Include="..\libs\Meziantou.Framework.Win32.CredentialManager\Meziantou.Framework.Win32.CredentialManager.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(TargetFramework.StartsWith('net6.0-windows')) ">
|
||||
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.17.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace Microsoft.Zune.Shell
|
||||
// Add plugins
|
||||
string mfAudioServiceId = Guid.NewGuid().ToString();
|
||||
PlaybackHandler = new PlaybackHandlerService();
|
||||
PlaybackHandler.RegisterAudioPlayer(MediaFoundationAudioService.Instance, localCore.InstanceId);
|
||||
PlaybackHandler.RegisterAudioPlayer(VlcAudioService.Instance, localCore.InstanceId);
|
||||
|
||||
DataRoot = new StrixDataRootPluginWrapper(mergedLayer,
|
||||
new PlaybackHandlerPlugin(PlaybackHandler)
|
||||
@@ -205,7 +205,7 @@ namespace Microsoft.Zune.Shell
|
||||
|
||||
DataRoot.Library.TracksChanged += LibraryTracksChanged;
|
||||
|
||||
//await DataRoot.Library.PlayTrackCollectionAsync();
|
||||
await DataRoot.Library.PlayTrackCollectionAsync();
|
||||
});
|
||||
#endif
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<Choose>
|
||||
<When Condition=" $(TargetFramework.StartsWith('net6.0-windows')) ">
|
||||
<PropertyGroup>
|
||||
<!--<UseOpenZune>True</UseOpenZune>-->
|
||||
<UseOpenZune>True</UseOpenZune>
|
||||
|
||||
<DefineConstants Condition="$(TargetFramework.StartsWith('net6.0-windows10'))">$(DefineConstants);WINDOWS10</DefineConstants>
|
||||
<DefineConstants Condition="$(TargetFramework.StartsWith('net6.0-windows8'))">$(DefineConstants);WINDOWS8</DefineConstants>
|
||||
|
||||
Reference in New Issue
Block a user