From 151a3222766320d145d97a835ee09d8ba6c0270c Mon Sep 17 00:00:00 2001 From: mikahjc Date: Sat, 5 Mar 2022 00:43:36 -0700 Subject: [PATCH] Initial commit --- .gitignore | 398 ++++++++++++++++++ .idea/.idea.MediaPlayer/.idea/.gitignore | 13 + .idea/.idea.MediaPlayer/.idea/.name | 1 + .idea/.idea.MediaPlayer/.idea/encodings.xml | 4 + .idea/.idea.MediaPlayer/.idea/indexLayout.xml | 8 + README.md | 13 + .../TechMedia.Backend.Vlc.csproj | 18 + TechMedia.Backend.Vlc/VlcAudioBackend.cs | 85 ++++ .../MediaPlayer.Backend.WinAudio.csproj | 13 + TechMedia.Backend.WinAudio/WinAudioBackend.cs | 11 + TechMedia.Core/Backend/IAudioBackend.cs | 14 + TechMedia.Core/Backend/ProgressListener.cs | 10 + TechMedia.Core/ITechMediaCore.cs | 22 + TechMedia.Core/Model/Track.cs | 11 + TechMedia.Core/TechMedia.Core.csproj | 9 + TechMedia.Core/TechMediaCore.cs | 158 +++++++ TechMedia.Interface.WindowsDesktop/App.xaml | 9 + .../App.xaml.cs | 17 + .../AssemblyInfo.cs | 10 + .../MainWindow.xaml | 29 ++ .../MainWindow.xaml.cs | 37 ++ .../TechMedia.Interface.WindowsDesktop.csproj | 15 + TechMedia.Interface.Wpf/App.xaml | 9 + TechMedia.Interface.Wpf/App.xaml.cs | 17 + TechMedia.Interface.Wpf/AssemblyInfo.cs | 10 + TechMedia.Interface.Wpf/MainWindow.xaml | 58 +++ TechMedia.Interface.Wpf/MainWindow.xaml.cs | 98 +++++ .../TechMedia.Interface.Wpf.csproj | 15 + TechMedia.sln | 59 +++ 29 files changed, 1171 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.idea.MediaPlayer/.idea/.gitignore create mode 100644 .idea/.idea.MediaPlayer/.idea/.name create mode 100644 .idea/.idea.MediaPlayer/.idea/encodings.xml create mode 100644 .idea/.idea.MediaPlayer/.idea/indexLayout.xml create mode 100644 README.md create mode 100644 TechMedia.Backend.Vlc/TechMedia.Backend.Vlc.csproj create mode 100644 TechMedia.Backend.Vlc/VlcAudioBackend.cs create mode 100644 TechMedia.Backend.WinAudio/MediaPlayer.Backend.WinAudio.csproj create mode 100644 TechMedia.Backend.WinAudio/WinAudioBackend.cs create mode 100644 TechMedia.Core/Backend/IAudioBackend.cs create mode 100644 TechMedia.Core/Backend/ProgressListener.cs create mode 100644 TechMedia.Core/ITechMediaCore.cs create mode 100644 TechMedia.Core/Model/Track.cs create mode 100644 TechMedia.Core/TechMedia.Core.csproj create mode 100644 TechMedia.Core/TechMediaCore.cs create mode 100644 TechMedia.Interface.WindowsDesktop/App.xaml create mode 100644 TechMedia.Interface.WindowsDesktop/App.xaml.cs create mode 100644 TechMedia.Interface.WindowsDesktop/AssemblyInfo.cs create mode 100644 TechMedia.Interface.WindowsDesktop/MainWindow.xaml create mode 100644 TechMedia.Interface.WindowsDesktop/MainWindow.xaml.cs create mode 100644 TechMedia.Interface.WindowsDesktop/TechMedia.Interface.WindowsDesktop.csproj create mode 100644 TechMedia.Interface.Wpf/App.xaml create mode 100644 TechMedia.Interface.Wpf/App.xaml.cs create mode 100644 TechMedia.Interface.Wpf/AssemblyInfo.cs create mode 100644 TechMedia.Interface.Wpf/MainWindow.xaml create mode 100644 TechMedia.Interface.Wpf/MainWindow.xaml.cs create mode 100644 TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj create mode 100644 TechMedia.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a30d25 --- /dev/null +++ b/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml diff --git a/.idea/.idea.MediaPlayer/.idea/.gitignore b/.idea/.idea.MediaPlayer/.idea/.gitignore new file mode 100644 index 0000000..efe26a5 --- /dev/null +++ b/.idea/.idea.MediaPlayer/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/contentModel.xml +/.idea.MediaPlayer.iml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.MediaPlayer/.idea/.name b/.idea/.idea.MediaPlayer/.idea/.name new file mode 100644 index 0000000..a79b2ed --- /dev/null +++ b/.idea/.idea.MediaPlayer/.idea/.name @@ -0,0 +1 @@ +MediaPlayer \ No newline at end of file diff --git a/.idea/.idea.MediaPlayer/.idea/encodings.xml b/.idea/.idea.MediaPlayer/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.MediaPlayer/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.MediaPlayer/.idea/indexLayout.xml b/.idea/.idea.MediaPlayer/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.MediaPlayer/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0096cf3 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# TechMedia + +## Requirements + +* Utilize a playlist +* Play music +* Facilitate requests (external media control, searching current playlist for available matching songs) +* Make metadata externally available (album art, track info, etc) + +## Wish List + +* Queue Update (allow updating playlist without taking requests offline) +* Playback/request statistics \ No newline at end of file diff --git a/TechMedia.Backend.Vlc/TechMedia.Backend.Vlc.csproj b/TechMedia.Backend.Vlc/TechMedia.Backend.Vlc.csproj new file mode 100644 index 0000000..c231b20 --- /dev/null +++ b/TechMedia.Backend.Vlc/TechMedia.Backend.Vlc.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/TechMedia.Backend.Vlc/VlcAudioBackend.cs b/TechMedia.Backend.Vlc/VlcAudioBackend.cs new file mode 100644 index 0000000..db0a212 --- /dev/null +++ b/TechMedia.Backend.Vlc/VlcAudioBackend.cs @@ -0,0 +1,85 @@ +using LibVLCSharp.Shared; +using TechMedia.Core.Backend; +using TechMedia.Core.Model; + +namespace TechMedia.Backend.Vlc; + +public class VlcAudioBackend : IAudioBackend +{ + private readonly LibVLC _libVlc; + private readonly MediaPlayer _player; + private readonly Dictionary, EventHandler> _progressReporters = new(); + + public VlcAudioBackend() + { + LibVLCSharp.Shared.Core.Initialize(); + _libVlc = new LibVLC(); + _player = new MediaPlayer(_libVlc); + } + + public void JustPlay() + { + _player.Play(); + } + + public void PlayFile(string filename) + { + //_player.Stop(); + var media = new Media(_libVlc, filename); + _player.Media = media; + + media.Dispose(); + + _player.Play(); + //_player.Position = 0.97f; + } + + public async Task GetFileMetadata(string filename) + { + using var media = new Media(_libVlc, filename); + await Task.Run(async () => await media.Parse()); + if (media.Duration <= 0) + { + return null; + } + + return new Track + { + Title = media.Meta(MetadataType.Title), + Album = media.Meta(MetadataType.Album), + AlbumArt = media.Meta(MetadataType.ArtworkURL), + Duration = media.Duration, + Filename = filename + }; + } + + public void StopPlayback() + { + _player.Stop(); + } + + public void RegisterProgressWatcher(IProgress reporter) + { + void Handler(object? _, MediaPlayerPositionChangedEventArgs args) + { + reporter.Report(args.Position); + } + + _player.PositionChanged += Handler; + _progressReporters.Add(reporter, Handler); + } + + public void RemoveProgressWatcher(IProgress reporter) + { + if (_progressReporters.ContainsKey(reporter)) + { + _player.PositionChanged -= _progressReporters[reporter]; + _progressReporters.Remove(reporter); + } + } + + public void RegisterTrackEndHandler(EventHandler onEndReached) + { + _player.EndReached += onEndReached; + } +} \ No newline at end of file diff --git a/TechMedia.Backend.WinAudio/MediaPlayer.Backend.WinAudio.csproj b/TechMedia.Backend.WinAudio/MediaPlayer.Backend.WinAudio.csproj new file mode 100644 index 0000000..cd4580e --- /dev/null +++ b/TechMedia.Backend.WinAudio/MediaPlayer.Backend.WinAudio.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/TechMedia.Backend.WinAudio/WinAudioBackend.cs b/TechMedia.Backend.WinAudio/WinAudioBackend.cs new file mode 100644 index 0000000..239a689 --- /dev/null +++ b/TechMedia.Backend.WinAudio/WinAudioBackend.cs @@ -0,0 +1,11 @@ +using TechMedia.Core.Backend; + +namespace TechMedia.Backend.WinAudio; + +public class WinAudioBackend : IAudioBackend +{ + public void PlayFile(string filename) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/TechMedia.Core/Backend/IAudioBackend.cs b/TechMedia.Core/Backend/IAudioBackend.cs new file mode 100644 index 0000000..cb16029 --- /dev/null +++ b/TechMedia.Core/Backend/IAudioBackend.cs @@ -0,0 +1,14 @@ +using TechMedia.Core.Model; + +namespace TechMedia.Core.Backend; + +public interface IAudioBackend +{ + public void JustPlay(); + public void PlayFile(string filename); + public void StopPlayback(); + public Task GetFileMetadata(string filename); + public void RegisterTrackEndHandler(EventHandler onEndReached); + void RegisterProgressWatcher(IProgress reporter); + void RemoveProgressWatcher(IProgress reporter); +} \ No newline at end of file diff --git a/TechMedia.Core/Backend/ProgressListener.cs b/TechMedia.Core/Backend/ProgressListener.cs new file mode 100644 index 0000000..b2060f8 --- /dev/null +++ b/TechMedia.Core/Backend/ProgressListener.cs @@ -0,0 +1,10 @@ +namespace TechMedia.Core.Backend; + +public class ProgressListener +{ + private readonly IProgress _reporter; + public ProgressListener(IProgress reporter) + { + _reporter = reporter; + } +} \ No newline at end of file diff --git a/TechMedia.Core/ITechMediaCore.cs b/TechMedia.Core/ITechMediaCore.cs new file mode 100644 index 0000000..b97f95d --- /dev/null +++ b/TechMedia.Core/ITechMediaCore.cs @@ -0,0 +1,22 @@ +using TechMedia.Core.Model; + +namespace TechMedia.Core; + +public interface ITechMediaCore +{ + public void Play(); + public void StartPlaylistPlayback(IProgress? trackReporter = null, IProgress? progressReporter = null); + public void Stop(); + public void Pause(); + public void NextTrack(); + public void PreviousTrack(); + public void GetNextTrackInfo(); + public void GetCurrentTrackInfo(); + public void OpenMediaFile(string filename); + public void OpenPlaylistFile(); + public Task LoadFiles(List files, IProgress? progress = null); + public List ShuffleCurrentPlaylist(); + public List GetCurrentPlaylist(); + public void RegisterPlaylistChangeListener(IProgress> playlistWatcher); + public Track? SubmitRequest(string filename); +} \ No newline at end of file diff --git a/TechMedia.Core/Model/Track.cs b/TechMedia.Core/Model/Track.cs new file mode 100644 index 0000000..0d9d42c --- /dev/null +++ b/TechMedia.Core/Model/Track.cs @@ -0,0 +1,11 @@ +namespace TechMedia.Core.Model; + +public class Track +{ + public string? Title { get; set; } + public string? Album { get; set; } + public string? AlbumArt { get; set; } + public long Duration { get; set; } + public string Filename { get; set; } = ""; + public override string ToString() => $"{Title ?? "?"} - {Album ?? "?"}"; +} \ No newline at end of file diff --git a/TechMedia.Core/TechMedia.Core.csproj b/TechMedia.Core/TechMedia.Core.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/TechMedia.Core/TechMedia.Core.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/TechMedia.Core/TechMediaCore.cs b/TechMedia.Core/TechMediaCore.cs new file mode 100644 index 0000000..b453190 --- /dev/null +++ b/TechMedia.Core/TechMediaCore.cs @@ -0,0 +1,158 @@ +using TechMedia.Core.Backend; +using TechMedia.Core.Model; + +namespace TechMedia.Core +{ + public class TechMediaCore : ITechMediaCore + { + private readonly IAudioBackend _backend; + private List _currentPlaylist = new(); + private Queue _requestQueue = new(); + + private IProgress? _trackReporter; + private IProgress? _progressReporter; + private IProgress>? _playlistWatcher; + private int _playbackIndex = 0; + + public TechMediaCore(IAudioBackend backend) + { + _backend = backend; + _backend.RegisterTrackEndHandler(TrackEndHandler); + } + + public void StartPlaylistPlayback(IProgress? trackReporter = null, IProgress? progressReporter = null) + { + if (trackReporter != null) + _trackReporter = trackReporter; + + if (progressReporter != null) + { + if (_progressReporter != null) + { + _backend.RemoveProgressWatcher(_progressReporter); + } + _progressReporter = progressReporter; + _backend.RegisterProgressWatcher(progressReporter); + } + + var firstTrack = _currentPlaylist[_playbackIndex++]; + _backend.PlayFile(firstTrack.Filename); + _trackReporter?.Report(firstTrack); + } + + private void QueueFilePlayback(string filename) + { + // LibVLC has a famous bug when calling LibVLC from a LibVLC callback (which is what this method is) that results in a deadlock. + // Workaround is to queue the action on another thread. + ThreadPool.QueueUserWorkItem(_ => _backend.PlayFile(filename)); + } + + public void TrackEndHandler(object? sender, EventArgs args) + { + if (_requestQueue.Count > 0) + { + var requestTrack = _requestQueue.Dequeue(); + _trackReporter?.Report(requestTrack); + QueueFilePlayback(requestTrack.Filename); + } + else if (_playbackIndex < _currentPlaylist.Count) + { + var nextTrack = _currentPlaylist[_playbackIndex++]; + _trackReporter?.Report(nextTrack); + QueueFilePlayback(nextTrack.Filename); + } + else + { + ThreadPool.QueueUserWorkItem(state => + { + ShuffleCurrentPlaylist(); + StartPlaylistPlayback(); + }); + } + } + + public void Stop() + { + _backend.StopPlayback(); + _playbackIndex = 0; + } + + public void Play() + { + throw new NotImplementedException(); + } + + public void Pause() + { + throw new NotImplementedException(); + } + + public void NextTrack() + { + throw new NotImplementedException(); + } + + public void PreviousTrack() + { + throw new NotImplementedException(); + } + + public void GetNextTrackInfo() + { + throw new NotImplementedException(); + } + + public void GetCurrentTrackInfo() + { + throw new NotImplementedException(); + } + + public void OpenMediaFile(string filename) + { + _backend.PlayFile(filename); + } + + public void OpenPlaylistFile() + { + throw new NotImplementedException(); + } + + public async Task LoadFiles(List files, IProgress? progress = null) + { + _currentPlaylist = new List(); + foreach (var (file, index) in files.Select((filename, index) => (filename, index))) + { + var track = await _backend.GetFileMetadata(file); + progress?.Report(index); + if (track != null) + _currentPlaylist.Add(track); + } + return _currentPlaylist.Count; + } + + public List ShuffleCurrentPlaylist() + { + _backend.StopPlayback(); + _playbackIndex = 0; + var random = new Random(); + _currentPlaylist = _currentPlaylist.OrderBy(t => random.Next()).ToList(); + _playlistWatcher?.Report(_currentPlaylist); + return _currentPlaylist; + } + + public List GetCurrentPlaylist() => _currentPlaylist; + public void RegisterPlaylistChangeListener(IProgress> playlistWatcher) + { + _playlistWatcher = playlistWatcher; + } + + public Track? SubmitRequest(string filename) + { + var requestedTrack = _currentPlaylist.FirstOrDefault(t => t.Filename.Equals(filename, StringComparison.OrdinalIgnoreCase)); + if (requestedTrack != null) + _requestQueue.Enqueue(requestedTrack); + + return requestedTrack; + } + } +} \ No newline at end of file diff --git a/TechMedia.Interface.WindowsDesktop/App.xaml b/TechMedia.Interface.WindowsDesktop/App.xaml new file mode 100644 index 0000000..0d708c1 --- /dev/null +++ b/TechMedia.Interface.WindowsDesktop/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/TechMedia.Interface.WindowsDesktop/App.xaml.cs b/TechMedia.Interface.WindowsDesktop/App.xaml.cs new file mode 100644 index 0000000..2bd49e4 --- /dev/null +++ b/TechMedia.Interface.WindowsDesktop/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace TechMedia.Interface.WindowsDesktop +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} \ No newline at end of file diff --git a/TechMedia.Interface.WindowsDesktop/AssemblyInfo.cs b/TechMedia.Interface.WindowsDesktop/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/TechMedia.Interface.WindowsDesktop/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] \ No newline at end of file diff --git a/TechMedia.Interface.WindowsDesktop/MainWindow.xaml b/TechMedia.Interface.WindowsDesktop/MainWindow.xaml new file mode 100644 index 0000000..6e68f50 --- /dev/null +++ b/TechMedia.Interface.WindowsDesktop/MainWindow.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + diff --git a/TechMedia.Interface.WindowsDesktop/MainWindow.xaml.cs b/TechMedia.Interface.WindowsDesktop/MainWindow.xaml.cs new file mode 100644 index 0000000..9ae08e8 --- /dev/null +++ b/TechMedia.Interface.WindowsDesktop/MainWindow.xaml.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using TechMedia.Backend.Vlc; +using TechMedia.Core; + +namespace TechMedia.Interface.WindowsDesktop +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private ITechMediaCore _player = new TechMediaCore(new VlcAudioBackend()); + public MainWindow() + { + InitializeComponent(); + } + + private void PlayButtonClicked(object sender, EventArgs e) + { + var filename = FilenameTextBox.Text; + _player.OpenMediaFile(filename); + } + } +} \ No newline at end of file diff --git a/TechMedia.Interface.WindowsDesktop/TechMedia.Interface.WindowsDesktop.csproj b/TechMedia.Interface.WindowsDesktop/TechMedia.Interface.WindowsDesktop.csproj new file mode 100644 index 0000000..b185df3 --- /dev/null +++ b/TechMedia.Interface.WindowsDesktop/TechMedia.Interface.WindowsDesktop.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + + + + + + + + diff --git a/TechMedia.Interface.Wpf/App.xaml b/TechMedia.Interface.Wpf/App.xaml new file mode 100644 index 0000000..5737bea --- /dev/null +++ b/TechMedia.Interface.Wpf/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/TechMedia.Interface.Wpf/App.xaml.cs b/TechMedia.Interface.Wpf/App.xaml.cs new file mode 100644 index 0000000..73d7d3f --- /dev/null +++ b/TechMedia.Interface.Wpf/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace TechMedia.Interface.Wpf +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} \ No newline at end of file diff --git a/TechMedia.Interface.Wpf/AssemblyInfo.cs b/TechMedia.Interface.Wpf/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/TechMedia.Interface.Wpf/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] \ No newline at end of file diff --git a/TechMedia.Interface.Wpf/MainWindow.xaml b/TechMedia.Interface.Wpf/MainWindow.xaml new file mode 100644 index 0000000..95de70e --- /dev/null +++ b/TechMedia.Interface.Wpf/MainWindow.xaml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + D:\users\mikah\music + + + + + + + + + Waiting for tracks + + + + + + + + + + + + + diff --git a/TechMedia.Interface.Wpf/MainWindow.xaml.cs b/TechMedia.Interface.Wpf/MainWindow.xaml.cs new file mode 100644 index 0000000..35f60fe --- /dev/null +++ b/TechMedia.Interface.Wpf/MainWindow.xaml.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using TechMedia.Backend.Vlc; +using TechMedia.Core; +using TechMedia.Core.Model; + +namespace TechMedia.Interface.Wpf +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public Track CurrentTrack { get; set; } = new(); + private readonly ITechMediaCore _player = new TechMediaCore(new VlcAudioBackend()); + public MainWindow() + { + InitializeComponent(); + DataContext = CurrentTrack; + _player.RegisterPlaylistChangeListener(new Progress>(newPlaylist => TrackDataGrid.DataContext = newPlaylist)); + } + + private static string FormatMillis(int millis) + { + var seconds = millis / 1000; + return $"{seconds / 60}:{(seconds % 60).ToString().PadLeft(2, '0')}"; + } + + private void PlayButtonClicked(object sender, EventArgs e) + { + var trackUpdater = new Progress(track => + { + CurrentTrack = track; + TitleLabel.Content = track.Title ?? "No title available"; + AlbumLabel.Content = track.Album ?? "No album available"; + }); + var progressUpdater = new Progress(p => + { + PlaybackProgressBar.Value = p; + TimeLabel.Content = $"{FormatMillis((int)(CurrentTrack.Duration * p))}/{FormatMillis((int)(CurrentTrack.Duration))}"; + }); + PlaybackProgressBar.Maximum = 1.0f; + _player.StartPlaylistPlayback(trackUpdater, progressUpdater); + } + + private async void LoadButton_Click(object sender, RoutedEventArgs e) + { + var allFiles = Directory.EnumerateFiles(FilenameTextBox.Text, "*.*", SearchOption.AllDirectories).ToList(); + LoadProgressBar.Maximum = allFiles.Count; + IProgress progress = new Progress(state => + { + LoadProgressBar.Value = state; + LoadingTextBlock.Text = $"Loading... {state}/{allFiles.Count}"; + }); + var loadedCount = await _player.LoadFiles(allFiles, progress); + LoadingTextBlock.Text = $"Tracks loaded: {loadedCount}"; + LoadProgressBar.Value = LoadProgressBar.Maximum; + MessageBox.Show($"Loaded {loadedCount} tracks"); + TrackDataGrid.DataContext = _player.GetCurrentPlaylist(); + } + + private void ShuffleButton_Click(object sender, RoutedEventArgs e) + { + TrackDataGrid.DataContext = _player.ShuffleCurrentPlaylist(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + _player.Stop(); + } + + private void Button_Click_1(object sender, RoutedEventArgs e) + { + var requestedTrack = _player.SubmitRequest(RequestFilenameTextBox.Text); + if (requestedTrack != null) + { + RequestStatusLabel.Content = $"{requestedTrack.Title} added to queue"; + } + else + { + RequestStatusLabel.Content = "File not found in playlist"; + } + } + } +} \ No newline at end of file diff --git a/TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj b/TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj new file mode 100644 index 0000000..b185df3 --- /dev/null +++ b/TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + + + + + + + + diff --git a/TechMedia.sln b/TechMedia.sln new file mode 100644 index 0000000..7db9483 --- /dev/null +++ b/TechMedia.sln @@ -0,0 +1,59 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32210.238 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechMedia.Core", "TechMedia.Core\TechMedia.Core.csproj", "{6A96DD50-5AD0-471B-8E42-DED4880524B4}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interface", "Interface", "{1BC62E19-F845-4B07-B6C7-77FB76447F48}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Backend", "Backend", "{A0D7E6E6-BA14-412B-BEF6-2E9F47D1EB95}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechMedia.Backend.WinAudio", "TechMedia.Backend.WinAudio\TechMedia.Backend.WinAudio.csproj", "{CADCE703-C81F-481C-9CE6-ACB245AD5824}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechMedia.Interface.WindowsDesktop", "TechMedia.Interface.WindowsDesktop\TechMedia.Interface.WindowsDesktop.csproj", "{E5904ADA-A91D-4B6E-887C-C5CC6ADFB64D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechMedia.Backend.Vlc", "TechMedia.Backend.Vlc\TechMedia.Backend.Vlc.csproj", "{8410B599-D63C-4642-8C21-965E01D06C47}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechMedia.Interface.Wpf", "TechMedia.Interface.Wpf\TechMedia.Interface.Wpf.csproj", "{76E19714-561A-4E1A-B3C2-E07572A2ECC8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6A96DD50-5AD0-471B-8E42-DED4880524B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A96DD50-5AD0-471B-8E42-DED4880524B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A96DD50-5AD0-471B-8E42-DED4880524B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A96DD50-5AD0-471B-8E42-DED4880524B4}.Release|Any CPU.Build.0 = Release|Any CPU + {CADCE703-C81F-481C-9CE6-ACB245AD5824}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CADCE703-C81F-481C-9CE6-ACB245AD5824}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CADCE703-C81F-481C-9CE6-ACB245AD5824}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CADCE703-C81F-481C-9CE6-ACB245AD5824}.Release|Any CPU.Build.0 = Release|Any CPU + {E5904ADA-A91D-4B6E-887C-C5CC6ADFB64D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5904ADA-A91D-4B6E-887C-C5CC6ADFB64D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5904ADA-A91D-4B6E-887C-C5CC6ADFB64D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5904ADA-A91D-4B6E-887C-C5CC6ADFB64D}.Release|Any CPU.Build.0 = Release|Any CPU + {8410B599-D63C-4642-8C21-965E01D06C47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8410B599-D63C-4642-8C21-965E01D06C47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8410B599-D63C-4642-8C21-965E01D06C47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8410B599-D63C-4642-8C21-965E01D06C47}.Release|Any CPU.Build.0 = Release|Any CPU + {76E19714-561A-4E1A-B3C2-E07572A2ECC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76E19714-561A-4E1A-B3C2-E07572A2ECC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76E19714-561A-4E1A-B3C2-E07572A2ECC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76E19714-561A-4E1A-B3C2-E07572A2ECC8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5E7B7F46-0387-4E54-8739-F44888457444} + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {CADCE703-C81F-481C-9CE6-ACB245AD5824} = {A0D7E6E6-BA14-412B-BEF6-2E9F47D1EB95} + {E5904ADA-A91D-4B6E-887C-C5CC6ADFB64D} = {1BC62E19-F845-4B07-B6C7-77FB76447F48} + {8410B599-D63C-4642-8C21-965E01D06C47} = {A0D7E6E6-BA14-412B-BEF6-2E9F47D1EB95} + {76E19714-561A-4E1A-B3C2-E07572A2ECC8} = {1BC62E19-F845-4B07-B6C7-77FB76447F48} + EndGlobalSection +EndGlobal