mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
Added LocalFilesCore, added impl of IAudioPlayerHandlerService
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
#if OPENZUNE
|
||||
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using NAudio.Wave;
|
||||
using StrixMusic.Sdk.MediaPlayback;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using StrixPlaybackState = StrixMusic.Sdk.MediaPlayback.PlaybackState;
|
||||
|
||||
namespace Microsoft.Zune.Playback
|
||||
{
|
||||
public class MediaFoundationAudioService : IAudioPlayerService
|
||||
{
|
||||
readonly WaveOutEvent m_audio = new();
|
||||
private PlaybackItem m_currentSource;
|
||||
|
||||
public static MediaFoundationAudioService Instance => new();
|
||||
|
||||
private MediaFoundationAudioService() { }
|
||||
|
||||
public PlaybackItem CurrentSource
|
||||
{
|
||||
get => m_currentSource;
|
||||
set
|
||||
{
|
||||
m_currentSource = value;
|
||||
CurrentSourceChanged?.Invoke(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan Position { get; private set; }
|
||||
|
||||
public StrixPlaybackState PlaybackState => m_audio.PlaybackState switch
|
||||
{
|
||||
NAudio.Wave.PlaybackState.Playing => StrixPlaybackState.Playing,
|
||||
|
||||
NAudio.Wave.PlaybackState.Paused or
|
||||
NAudio.Wave.PlaybackState.Stopped => StrixPlaybackState.Paused,
|
||||
|
||||
_ => StrixPlaybackState.None
|
||||
};
|
||||
|
||||
public double Volume
|
||||
{
|
||||
get => m_audio.Volume;
|
||||
private set
|
||||
{
|
||||
m_audio.Volume = (float)value;
|
||||
VolumeChanged?.Invoke(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double PlaybackSpeed { get; private set; }
|
||||
|
||||
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_audio.Pause();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Play(PlaybackItem sourceConfig, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var stream = sourceConfig.MediaConfig.FileStreamSource;
|
||||
Guard.IsNotNull(stream, "sourceConfig.MediaConfig.FileStreamSource");
|
||||
|
||||
StreamMediaFoundationReader mfr = new(sourceConfig.MediaConfig.FileStreamSource);
|
||||
m_audio.Init(mfr);
|
||||
m_audio.Play();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Preload(PlaybackItem sourceConfig, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task ResumeAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
m_audio.Play();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task SeekAsync(TimeSpan position, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -32,7 +32,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="$(UseOpenZune)">
|
||||
<PackageReference Include="StrixMusic.Sdk" Version="0.0.2-alpha" />
|
||||
<PackageReference Include="StrixMusic.Sdk" Version="0.0.3-alpha" />
|
||||
<PackageReference Include="StrixMusic.Cores.LocalFiles" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition=" $(UseOpenZune) ">
|
||||
|
||||
@@ -24,6 +24,16 @@ using System.Threading;
|
||||
using UIXControls;
|
||||
using ZuneUI;
|
||||
using ZuneXml;
|
||||
using System.Linq;
|
||||
|
||||
#if OPENZUNE
|
||||
using Microsoft.Zune.Playback;
|
||||
using StrixMusic.Sdk.AdapterModels;
|
||||
using StrixMusic.Sdk.CoreModels;
|
||||
using StrixMusic.Sdk.MediaPlayback;
|
||||
using StrixMusic.Sdk.PluginModels;
|
||||
using StrixMusic.Sdk.Plugins.PlaybackHandler;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.Zune.Shell
|
||||
{
|
||||
@@ -121,10 +131,65 @@ namespace Microsoft.Zune.Shell
|
||||
Telemetry.Instance.StartUpload();
|
||||
FeaturesChanged.Instance.StartUp();
|
||||
CultureHelper.CheckValidRegionAndLanguage();
|
||||
|
||||
#if OPENZUNE
|
||||
string id = Guid.NewGuid().ToString();
|
||||
|
||||
var fileService = new OwlCore.AbstractStorage.Win32FileSystemService(@"D:\OneDrive\Music");
|
||||
OwlCore.AbstractStorage.SystemIOFolderData settingsFolder =
|
||||
new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\Zune\OpenZune"));
|
||||
settingsFolder.EnsureExists().Wait();
|
||||
StrixMusic.Cores.LocalFiles.Services.LocalFilesCoreSettings settings = new(settingsFolder)
|
||||
{
|
||||
InitWithEmptyMetadataRepos = true,
|
||||
ScanWithTagLib = true,
|
||||
};
|
||||
|
||||
var localCore = new StrixMusic.Cores.LocalFiles.LocalFilesCore(
|
||||
id, settings, fileService, null);
|
||||
|
||||
var prefs = new MergedCollectionConfig
|
||||
{
|
||||
CoreRanking = new string[]
|
||||
{
|
||||
localCore.InstanceId
|
||||
}
|
||||
};
|
||||
var mergedLayer = new MergedCore(new ICore[] { localCore }, prefs);
|
||||
|
||||
// Perform any async initialization needed. Authenticating, connecting to database, etc.
|
||||
mergedLayer.InitAsync().ContinueWith(async task =>
|
||||
{
|
||||
mergedLayer.Library.TracksCountChanged += LibraryTracksAdded;
|
||||
|
||||
// Add plugins
|
||||
string mfAudioServiceId = Guid.NewGuid().ToString();
|
||||
PlaybackHandlerService playbackHandler = new();
|
||||
playbackHandler.RegisterAudioPlayer(MediaFoundationAudioService.Instance, mfAudioServiceId);
|
||||
|
||||
StrixDataRootPluginWrapper pluginLayer = new(mergedLayer,
|
||||
new PlaybackHandlerPlugin(playbackHandler)
|
||||
);
|
||||
await pluginLayer.InitAsync();
|
||||
});
|
||||
#endif
|
||||
|
||||
((ZuneUI.Shell)ZuneShell.DefaultInstance).ApplicationInitializationIsComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
#if OPENZUNE
|
||||
private static async void LibraryTracksAdded(object sender, int count)
|
||||
{
|
||||
if (sender is StrixMusic.Sdk.AppModels.ILibrary library && count > 50)
|
||||
{
|
||||
library.TracksCountChanged -= LibraryTracksAdded;
|
||||
var tracks = await library.GetTracksAsync(limit: 100, offset: 0).ToListAsync();
|
||||
await library.PlayTrackCollectionAsync(tracks[0]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private static void Phase2InitializationUIStage(object arg)
|
||||
{
|
||||
_initializationFailsafe.Initialize(delegate
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Win32FileSystemService : IFileSystemService
|
||||
|
||||
public Task<IFolderData> PickFolder()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
return Task.FromResult(RootFolder);
|
||||
}
|
||||
|
||||
public Task RevokeAccess(IFolderData folder) => Task.CompletedTask;
|
||||
|
||||
@@ -58,10 +58,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(UseOpenZune) ">
|
||||
<PackageReference Include="StrixMusic.Sdk" Version="0.0.2-alpha" />
|
||||
<Reference Include="StrixMusic.Cores.LocalFiles">
|
||||
<HintPath>..\..\..\Arlodotexe\strix-music\src\Cores\Files\StrixMusic.Cores.LocalFiles\bin\Debug\netstandard2.0\StrixMusic.Cores.LocalFiles.dll</HintPath>
|
||||
</Reference>
|
||||
<PackageReference Include="StrixMusic.Sdk" Version="0.0.3-alpha" />
|
||||
<PackageReference Include="StrixMusic.Cores.LocalFiles" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition=" $(UseOpenZune) ">
|
||||
|
||||
Reference in New Issue
Block a user