Initial commit
This commit is contained in:
398
.gitignore
vendored
Normal file
398
.gitignore
vendored
Normal file
@@ -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
|
||||||
13
.idea/.idea.MediaPlayer/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.MediaPlayer/.idea/.gitignore
generated
vendored
Normal file
@@ -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
|
||||||
1
.idea/.idea.MediaPlayer/.idea/.name
generated
Normal file
1
.idea/.idea.MediaPlayer/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
|||||||
|
MediaPlayer
|
||||||
4
.idea/.idea.MediaPlayer/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.MediaPlayer/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
||||||
8
.idea/.idea.MediaPlayer/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.MediaPlayer/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
13
README.md
Normal file
13
README.md
Normal file
@@ -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
|
||||||
18
TechMedia.Backend.Vlc/TechMedia.Backend.Vlc.csproj
Normal file
18
TechMedia.Backend.Vlc/TechMedia.Backend.Vlc.csproj
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TechMedia.Core\TechMedia.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="LibVLCSharp" Version="3.6.5" />
|
||||||
|
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.16" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
85
TechMedia.Backend.Vlc/VlcAudioBackend.cs
Normal file
85
TechMedia.Backend.Vlc/VlcAudioBackend.cs
Normal file
@@ -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<IProgress<float>, EventHandler<MediaPlayerPositionChangedEventArgs>> _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<Track?> 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<float> reporter)
|
||||||
|
{
|
||||||
|
void Handler(object? _, MediaPlayerPositionChangedEventArgs args)
|
||||||
|
{
|
||||||
|
reporter.Report(args.Position);
|
||||||
|
}
|
||||||
|
|
||||||
|
_player.PositionChanged += Handler;
|
||||||
|
_progressReporters.Add(reporter, Handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveProgressWatcher(IProgress<float> reporter)
|
||||||
|
{
|
||||||
|
if (_progressReporters.ContainsKey(reporter))
|
||||||
|
{
|
||||||
|
_player.PositionChanged -= _progressReporters[reporter];
|
||||||
|
_progressReporters.Remove(reporter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegisterTrackEndHandler(EventHandler<EventArgs> onEndReached)
|
||||||
|
{
|
||||||
|
_player.EndReached += onEndReached;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TechMedia.Core\TechMedia.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
11
TechMedia.Backend.WinAudio/WinAudioBackend.cs
Normal file
11
TechMedia.Backend.WinAudio/WinAudioBackend.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using TechMedia.Core.Backend;
|
||||||
|
|
||||||
|
namespace TechMedia.Backend.WinAudio;
|
||||||
|
|
||||||
|
public class WinAudioBackend : IAudioBackend
|
||||||
|
{
|
||||||
|
public void PlayFile(string filename)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
TechMedia.Core/Backend/IAudioBackend.cs
Normal file
14
TechMedia.Core/Backend/IAudioBackend.cs
Normal file
@@ -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<Track?> GetFileMetadata(string filename);
|
||||||
|
public void RegisterTrackEndHandler(EventHandler<EventArgs> onEndReached);
|
||||||
|
void RegisterProgressWatcher(IProgress<float> reporter);
|
||||||
|
void RemoveProgressWatcher(IProgress<float> reporter);
|
||||||
|
}
|
||||||
10
TechMedia.Core/Backend/ProgressListener.cs
Normal file
10
TechMedia.Core/Backend/ProgressListener.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace TechMedia.Core.Backend;
|
||||||
|
|
||||||
|
public class ProgressListener
|
||||||
|
{
|
||||||
|
private readonly IProgress<float> _reporter;
|
||||||
|
public ProgressListener(IProgress<float> reporter)
|
||||||
|
{
|
||||||
|
_reporter = reporter;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
TechMedia.Core/ITechMediaCore.cs
Normal file
22
TechMedia.Core/ITechMediaCore.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using TechMedia.Core.Model;
|
||||||
|
|
||||||
|
namespace TechMedia.Core;
|
||||||
|
|
||||||
|
public interface ITechMediaCore
|
||||||
|
{
|
||||||
|
public void Play();
|
||||||
|
public void StartPlaylistPlayback(IProgress<Track>? trackReporter = null, IProgress<float>? 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<int> LoadFiles(List<string> files, IProgress<int>? progress = null);
|
||||||
|
public List<Track> ShuffleCurrentPlaylist();
|
||||||
|
public List<Track> GetCurrentPlaylist();
|
||||||
|
public void RegisterPlaylistChangeListener(IProgress<List<Track>> playlistWatcher);
|
||||||
|
public Track? SubmitRequest(string filename);
|
||||||
|
}
|
||||||
11
TechMedia.Core/Model/Track.cs
Normal file
11
TechMedia.Core/Model/Track.cs
Normal file
@@ -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 ?? "?"}";
|
||||||
|
}
|
||||||
9
TechMedia.Core/TechMedia.Core.csproj
Normal file
9
TechMedia.Core/TechMedia.Core.csproj
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
158
TechMedia.Core/TechMediaCore.cs
Normal file
158
TechMedia.Core/TechMediaCore.cs
Normal file
@@ -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<Track> _currentPlaylist = new();
|
||||||
|
private Queue<Track> _requestQueue = new();
|
||||||
|
|
||||||
|
private IProgress<Track>? _trackReporter;
|
||||||
|
private IProgress<float>? _progressReporter;
|
||||||
|
private IProgress<List<Track>>? _playlistWatcher;
|
||||||
|
private int _playbackIndex = 0;
|
||||||
|
|
||||||
|
public TechMediaCore(IAudioBackend backend)
|
||||||
|
{
|
||||||
|
_backend = backend;
|
||||||
|
_backend.RegisterTrackEndHandler(TrackEndHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartPlaylistPlayback(IProgress<Track>? trackReporter = null, IProgress<float>? 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<int> LoadFiles(List<string> files, IProgress<int>? progress = null)
|
||||||
|
{
|
||||||
|
_currentPlaylist = new List<Track>();
|
||||||
|
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<Track> ShuffleCurrentPlaylist()
|
||||||
|
{
|
||||||
|
_backend.StopPlayback();
|
||||||
|
_playbackIndex = 0;
|
||||||
|
var random = new Random();
|
||||||
|
_currentPlaylist = _currentPlaylist.OrderBy(t => random.Next()).ToList();
|
||||||
|
_playlistWatcher?.Report(_currentPlaylist);
|
||||||
|
return _currentPlaylist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Track> GetCurrentPlaylist() => _currentPlaylist;
|
||||||
|
public void RegisterPlaylistChangeListener(IProgress<List<Track>> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
TechMedia.Interface.WindowsDesktop/App.xaml
Normal file
9
TechMedia.Interface.WindowsDesktop/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="TechMedia.Interface.WindowsDesktop.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:TechMedia.Interface.WindowsDesktop"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
17
TechMedia.Interface.WindowsDesktop/App.xaml.cs
Normal file
17
TechMedia.Interface.WindowsDesktop/App.xaml.cs
Normal file
@@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
10
TechMedia.Interface.WindowsDesktop/AssemblyInfo.cs
Normal file
10
TechMedia.Interface.WindowsDesktop/AssemblyInfo.cs
Normal file
@@ -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)
|
||||||
|
)]
|
||||||
29
TechMedia.Interface.WindowsDesktop/MainWindow.xaml
Normal file
29
TechMedia.Interface.WindowsDesktop/MainWindow.xaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<Window x:Class="TechMedia.Interface.WindowsDesktop.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:TechMedia.Interface.WindowsDesktop"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="MainWindow" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Label>Filename:</Label>
|
||||||
|
<TextBox Name="FilenameTextBox" Grid.Row="0" Grid.Column="1" Margin="6"></TextBox>
|
||||||
|
<Button Name="PlayButton"
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.ColumnSpan="2"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="6"
|
||||||
|
Click="PlayButtonClicked">
|
||||||
|
Play
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
37
TechMedia.Interface.WindowsDesktop/MainWindow.xaml.cs
Normal file
37
TechMedia.Interface.WindowsDesktop/MainWindow.xaml.cs
Normal file
@@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TechMedia.Backend.Vlc\TechMedia.Backend.Vlc.csproj" />
|
||||||
|
<ProjectReference Include="..\TechMedia.Core\TechMedia.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
9
TechMedia.Interface.Wpf/App.xaml
Normal file
9
TechMedia.Interface.Wpf/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="TechMedia.Interface.Wpf.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:TechMedia.Interface.Wpf"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
17
TechMedia.Interface.Wpf/App.xaml.cs
Normal file
17
TechMedia.Interface.Wpf/App.xaml.cs
Normal file
@@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
10
TechMedia.Interface.Wpf/AssemblyInfo.cs
Normal file
10
TechMedia.Interface.Wpf/AssemblyInfo.cs
Normal file
@@ -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)
|
||||||
|
)]
|
||||||
58
TechMedia.Interface.Wpf/MainWindow.xaml
Normal file
58
TechMedia.Interface.Wpf/MainWindow.xaml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<Window x:Class="TechMedia.Interface.Wpf.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:TechMedia.Interface.Wpf"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="TechMedia" Height="450" Width="800"
|
||||||
|
Padding="3">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Label>Folder:</Label>
|
||||||
|
<TextBox Name="FilenameTextBox" Grid.Row="0" Grid.Column="1" Margin="6">D:\users\mikah\music</TextBox>
|
||||||
|
<Button Name="LoadButton" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="6" Click="LoadButton_Click">Load Folder</Button>
|
||||||
|
<Button Name="PlayButton"
|
||||||
|
Grid.Row="2"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="6"
|
||||||
|
Click="PlayButtonClicked">
|
||||||
|
Play
|
||||||
|
</Button>
|
||||||
|
<Button Grid.Row="2" Grid.Column="1" Margin="6" Click="Button_Click">Stop</Button>
|
||||||
|
<Button Name="ShuffleButton" Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="0" Margin="6" Click="ShuffleButton_Click">Shuffle</Button>
|
||||||
|
<DataGrid Name="TrackDataGrid" Grid.Row="5" Grid.ColumnSpan="2" Grid.Column="0" ItemsSource="{Binding}">
|
||||||
|
</DataGrid>
|
||||||
|
<ProgressBar Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Height="20" Name="LoadProgressBar">
|
||||||
|
</ProgressBar>
|
||||||
|
<TextBlock Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Name="LoadingTextBlock">Waiting for tracks</TextBlock>
|
||||||
|
<Image Grid.Row="7" Grid.RowSpan="2" Grid.Column="0"></Image>
|
||||||
|
<Label Grid.Row="7" Grid.Column="1" Name="TitleLabel">Track Name</Label>
|
||||||
|
<Label Grid.Row="8" Grid.Column="1" Name="AlbumLabel">Track Album</Label>
|
||||||
|
<Label Grid.Row="9" Grid.Column="1" Name="TimeLabel">0:00/0:00</Label>
|
||||||
|
<ProgressBar Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="2" Height="10" Name="PlaybackProgressBar" Foreground="#FF066EB0">
|
||||||
|
</ProgressBar>
|
||||||
|
|
||||||
|
<Label Grid.Row="0" Grid.Column="2">Request filename:</Label>
|
||||||
|
<TextBox Grid.Row="1" Grid.Column="2" Margin="6" Name="RequestFilenameTextBox"></TextBox>
|
||||||
|
<Button Grid.Row="2" Grid.Column="2" Margin="6" Click="Button_Click_1">Submit Request</Button>
|
||||||
|
<Label Grid.Row="3" Grid.Column="2" Name="RequestStatusLabel">No requests submitted</Label>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
98
TechMedia.Interface.Wpf/MainWindow.xaml.cs
Normal file
98
TechMedia.Interface.Wpf/MainWindow.xaml.cs
Normal file
@@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
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<List<Track>>(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>(track =>
|
||||||
|
{
|
||||||
|
CurrentTrack = track;
|
||||||
|
TitleLabel.Content = track.Title ?? "No title available";
|
||||||
|
AlbumLabel.Content = track.Album ?? "No album available";
|
||||||
|
});
|
||||||
|
var progressUpdater = new Progress<float>(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<int> progress = new Progress<int>(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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj
Normal file
15
TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TechMedia.Backend.Vlc\TechMedia.Backend.Vlc.csproj" />
|
||||||
|
<ProjectReference Include="..\TechMedia.Core\TechMedia.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
59
TechMedia.sln
Normal file
59
TechMedia.sln
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user