├── .gitignore ├── LICENSE ├── LyricEase.PlaybackEngine.sln ├── LyricEase.PlaybackEngine ├── ApplicationSettingsExtension.cs ├── DoxPlayer.cs ├── IPlayer.cs ├── LyricEase.PlaybackEngine.csproj ├── Methods.cs ├── Models.cs ├── PlaybackEngine.cs └── Properties │ ├── AssemblyInfo.cs │ └── LyricEase.PlaybackEngine.rd.xml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31702.278 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LyricEase.PlaybackEngine", "LyricEase.PlaybackEngine\LyricEase.PlaybackEngine.csproj", "{781CEC53-888E-40C3-BB88-A4F8488ABFE6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|ARM = Debug|ARM 12 | Debug|ARM64 = Debug|ARM64 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|ARM = Release|ARM 17 | Release|ARM64 = Release|ARM64 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|ARM.ActiveCfg = Debug|ARM 25 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|ARM.Build.0 = Debug|ARM 26 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|ARM64.ActiveCfg = Debug|ARM64 27 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|ARM64.Build.0 = Debug|ARM64 28 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|x64.ActiveCfg = Debug|x64 29 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|x64.Build.0 = Debug|x64 30 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|x86.ActiveCfg = Debug|x86 31 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Debug|x86.Build.0 = Debug|x86 32 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|ARM.ActiveCfg = Release|ARM 35 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|ARM.Build.0 = Release|ARM 36 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|ARM64.ActiveCfg = Release|ARM64 37 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|ARM64.Build.0 = Release|ARM64 38 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|x64.ActiveCfg = Release|x64 39 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|x64.Build.0 = Release|x64 40 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|x86.ActiveCfg = Release|x86 41 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6}.Release|x86.Build.0 = Release|x86 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {3230C156-8FDA-4A12-AE34-172FD548922B} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/ApplicationSettingsExtension.cs: -------------------------------------------------------------------------------- 1 | using LyricEase.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Windows.Storage; 8 | 9 | namespace LyricEase 10 | { 11 | internal static class ApplicationSettingsExtension 12 | { 13 | private static ApplicationDataContainer RootContainer => ApplicationData.Current.LocalSettings.CreateContainer("DoxPlayerSettings", ApplicationDataCreateDisposition.Always); 14 | 15 | #region Settings Items 16 | 17 | public static PlaybackMode PlaybackMode 18 | { 19 | get => (PlaybackMode)PlaybackModeProperty.GetValue(); 20 | set => PlaybackModeProperty.SetValue((int)value); 21 | } 22 | private static readonly SettingProperty PlaybackModeProperty = new(nameof(PlaybackMode), 0); 23 | 24 | public static double Volume 25 | { 26 | get => VolumeProperty.GetValue(); 27 | set => VolumeProperty.SetValue(value); 28 | } 29 | private static readonly SettingProperty VolumeProperty = new(nameof(Volume), 1.0d); 30 | 31 | public static SoundQuality SoundQuality 32 | { 33 | get => (SoundQuality)SoundQualityProperty.GetValue(); 34 | set => SoundQualityProperty.SetValue((int)value); 35 | } 36 | private static readonly SettingProperty SoundQualityProperty = new(nameof(SoundQuality), 2); 37 | 38 | public static bool IsDirectSwitchEnabled 39 | { 40 | get => IsDirectSwitchEnabledProperty.GetValue(); 41 | set => IsDirectSwitchEnabledProperty.SetValue(value); 42 | } 43 | private static readonly SettingProperty IsDirectSwitchEnabledProperty = new(nameof(IsDirectSwitchEnabled), false); 44 | 45 | public static bool IsAudioCrossfadingEnabled 46 | { 47 | get => IsAudioCrossfadingEnabledProperty.GetValue(); 48 | set => IsAudioCrossfadingEnabledProperty.SetValue(value); 49 | } 50 | private static readonly SettingProperty IsAudioCrossfadingEnabledProperty = new(nameof(IsAudioCrossfadingEnabled), true); 51 | 52 | public static int AudioCrossfadingLength 53 | { 54 | get => AudioCrossfadingLengthProperty.GetValue(); 55 | set => AudioCrossfadingLengthProperty.SetValue(value); 56 | } 57 | private static readonly SettingProperty AudioCrossfadingLengthProperty = new(nameof(AudioCrossfadingLength), 6); 58 | #endregion 59 | 60 | private sealed class SettingProperty 61 | { 62 | private readonly string propertyName; 63 | private readonly T defaultValue; 64 | 65 | public SettingProperty(string PropertyName, T DefaultValue) 66 | { 67 | propertyName = PropertyName; 68 | defaultValue = DefaultValue; 69 | } 70 | 71 | public T GetValue() 72 | { 73 | if (!RootContainer.Values.ContainsKey(propertyName)) return defaultValue; 74 | return (T)RootContainer.Values[propertyName]; 75 | } 76 | 77 | public void SetValue(T value) => RootContainer.Values[propertyName] = value; 78 | 79 | public void RemoveValue() => RootContainer.Values.Remove(propertyName); 80 | 81 | public T DefaultValue => defaultValue; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/DoxPlayer.cs: -------------------------------------------------------------------------------- 1 | using LyricEase.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Windows.Media; 8 | using Windows.Media.Audio; 9 | using Windows.Media.Core; 10 | 11 | namespace LyricEase 12 | { 13 | internal sealed class DoxPlayer : IPlayer 14 | { 15 | private AudioGraph audioGraph; 16 | private AudioDeviceOutputNode outputNode; 17 | private System.Timers.Timer graphMonitor; 18 | private const double graphMonitorInterval = 50.0d; 19 | 20 | private System.Timers.Timer resourceReloadTimer; 21 | 22 | private TrackNode previousTrackNode; 23 | private TrackNode currentTrackNode; 24 | private TrackNode nextTrackNode; 25 | private NodeStatus nextTrackNodeStatus = NodeStatus.Unavailable; 26 | 27 | private System.Timers.Timer crossfadingTimer; 28 | private bool isInCrossfasingPhase = false; 29 | private double actualAudioCrossfadingLength; 30 | 31 | private int previousItemIndex = -1; 32 | private int currentItemIndex = -1; 33 | private int preparedItemIndex = -1; 34 | 35 | private readonly SystemMediaTransportControls SMTC; 36 | 37 | #region Settings properties 38 | 39 | public double Volume 40 | { 41 | get => ApplicationSettingsExtension.Volume; 42 | set 43 | { 44 | ApplicationSettingsExtension.Volume = value; 45 | } 46 | } 47 | public bool IsDirectSwitchEnabled 48 | { 49 | get => ApplicationSettingsExtension.IsDirectSwitchEnabled; 50 | set 51 | { 52 | ApplicationSettingsExtension.IsDirectSwitchEnabled = value; 53 | } 54 | } 55 | public SoundQuality SoundQuality 56 | { 57 | get => ApplicationSettingsExtension.SoundQuality; 58 | set 59 | { 60 | ApplicationSettingsExtension.SoundQuality = value; 61 | } 62 | } 63 | 64 | public PlaybackMode PlaybackMode 65 | { 66 | get => ApplicationSettingsExtension.PlaybackMode; 67 | set 68 | { 69 | PlaybackMode oldValue = ApplicationSettingsExtension.PlaybackMode; 70 | OnPlaybackModeChanged(oldValue, value); 71 | ApplicationSettingsExtension.PlaybackMode = value; 72 | } 73 | } 74 | public bool IsAudioCrossfadingEnabled 75 | { 76 | get => ApplicationSettingsExtension.IsAudioCrossfadingEnabled; 77 | set 78 | { 79 | ApplicationSettingsExtension.IsAudioCrossfadingEnabled = value; 80 | } 81 | } 82 | public int AudioCrossfadingLength 83 | { 84 | get => ApplicationSettingsExtension.AudioCrossfadingLength; 85 | set 86 | { 87 | ApplicationSettingsExtension.AudioCrossfadingLength = value; 88 | } 89 | } 90 | 91 | #endregion 92 | 93 | public bool? IsPlaying { get; set; } 94 | 95 | public object PlaybackSource { get; private set; } 96 | 97 | public ITrack CurrentItem { get => currentTrackNode?.Track; } 98 | 99 | public List OriginalPlaybackList { get; set; } = new(); 100 | 101 | public List UpNextPlaybackList { get; set; } = new(); 102 | 103 | public List PlaybackOrder { get; private set; } = new(); 104 | 105 | public List OrderedPlaybackList 106 | { 107 | get 108 | { 109 | int startIndex = Methods.GetNextIndex(currentItemIndex == -1 ? previousItemIndex : currentItemIndex, PlaybackOrder.Count); 110 | List extendedIndices = new(PlaybackOrder.TakeLast(PlaybackOrder.Count - startIndex)); 111 | if (startIndex > 0) extendedIndices.AddRange(PlaybackOrder.Take(startIndex)); 112 | if (extendedIndices.Count > 100) extendedIndices = extendedIndices.GetRange(0, 100); 113 | return extendedIndices.Select(i => OriginalPlaybackList[i]).ToList(); 114 | } 115 | } 116 | 117 | public event EventHandler PlaybackStatusChanged; 118 | public event EventHandler PlaybackModeChanged; 119 | public event EventHandler PlaybackPositionChanged; 120 | public event EventHandler CurrentlyPlayingItemChanged; 121 | public event EventHandler PlaybackQueueUpdated; 122 | public event EventHandler PlaybackEnded; 123 | public event EventHandler PlaybackError; 124 | 125 | public DoxPlayer() 126 | { 127 | InitializeAudioGraph().Wait(); 128 | 129 | SMTC = SystemMediaTransportControls.GetForCurrentView(); 130 | SMTC.IsEnabled = false; 131 | SMTC.IsPauseEnabled = true; 132 | SMTC.ButtonPressed += SMTC_ButtonPressed; 133 | SMTC.PlaybackPositionChangeRequested += (_, args) => Seek(args.RequestedPlaybackPosition); 134 | 135 | PlaybackPositionChanged += DoxPlayer_PlaybackPositionChanged; 136 | PlaybackStatusChanged += DoxPlayer_PlaybackStatusChanged; 137 | PlaybackQueueUpdated += DoxPlayer_PlaybackQueueUpdated; 138 | } 139 | 140 | #region AudioGraph and TrackNode Manipulations 141 | 142 | private async Task InitializeAudioGraph() 143 | { 144 | AudioGraphSettings settings = new AudioGraphSettings(Windows.Media.Render.AudioRenderCategory.Media); 145 | 146 | var createAudioGraphResult = await AudioGraph.CreateAsync(settings); 147 | if (createAudioGraphResult.Status != AudioGraphCreationStatus.Success) 148 | { 149 | throw new Exception("AudioGraph creation error: " + createAudioGraphResult.Status.ToString()); 150 | } 151 | audioGraph = createAudioGraphResult.Graph; 152 | 153 | var createAudioDeviceOutputNodeResult = await audioGraph.CreateDeviceOutputNodeAsync(); 154 | if (createAudioDeviceOutputNodeResult.Status != AudioDeviceNodeCreationStatus.Success) 155 | { 156 | throw new Exception("AudioGraph configuration error: " + createAudioDeviceOutputNodeResult.Status.ToString()); 157 | } 158 | outputNode = createAudioDeviceOutputNodeResult.DeviceOutputNode; 159 | 160 | audioGraph.Start(); 161 | 162 | graphMonitor = new() { AutoReset = true, Interval = graphMonitorInterval }; 163 | graphMonitor.Elapsed += (_1, _2) => OnGraphTimelineUpdated(); 164 | } 165 | 166 | private async Task CreateTrackNode(ITrack track) 167 | { 168 | if (audioGraph == null) throw new Exception("Audio graph not available."); 169 | 170 | var mediaSource = await track.GetAudioMediaSource(SoundQuality); 171 | 172 | var createNodeResult = await audioGraph.CreateMediaSourceAudioInputNodeAsync(mediaSource); 173 | 174 | if (createNodeResult.Status != MediaSourceAudioInputNodeCreationStatus.Success) 175 | { 176 | throw new Exception("Audio node creation error: " + createNodeResult.Status.ToString()); 177 | } 178 | 179 | TrackNode node = new() { Node = createNodeResult.Node, Track = track }; 180 | // make sure the node does not start automatically 181 | node.Node.Stop(); 182 | node.Node.Reset(); 183 | node.Node.AddOutgoingConnection(outputNode); 184 | 185 | return node; 186 | } 187 | 188 | private void DisposeTrackNode(TrackNode trackNode) 189 | { 190 | trackNode.Node.Stop(); 191 | trackNode.Node.RemoveOutgoingConnection(outputNode); 192 | trackNode.Node.Dispose(); 193 | } 194 | 195 | #endregion 196 | 197 | private void OnGraphTimelineUpdated() 198 | { 199 | if (currentTrackNode is null) return; 200 | TimeSpan currentPosition = currentTrackNode.Node.Position; 201 | TimeSpan duration = currentTrackNode.Node.Duration; 202 | 203 | PlaybackPositionChanged?.Invoke(this, new() { Current = currentPosition, Total = duration }); 204 | 205 | if ((duration - currentPosition).TotalSeconds < 60.0d) 206 | { 207 | if (nextTrackNodeStatus == NodeStatus.Unavailable) 208 | { 209 | PrepareNextNode(); 210 | } 211 | } 212 | if (!isInCrossfasingPhase && 213 | IsAudioCrossfadingEnabled && 214 | nextTrackNodeStatus == NodeStatus.Available && 215 | currentTrackNode.IsNodeAvailableForCrossfading && 216 | nextTrackNode.IsNodeAvailableForCrossfading && 217 | !currentTrackNode.IsUserInterruptingCrossfading && 218 | (duration - currentPosition).TotalSeconds <= AudioCrossfadingLength && 219 | (duration - currentPosition).TotalSeconds > 3.0d) 220 | { 221 | EnterCrossfadingPhase(); 222 | } 223 | if (isInCrossfasingPhase && 224 | currentPosition.TotalSeconds >= AudioCrossfadingLength) 225 | { 226 | LeaveCrossfadingPhase(); 227 | } 228 | } 229 | 230 | private void EnterCrossfadingPhase() 231 | { 232 | isInCrossfasingPhase = true; 233 | if (currentTrackNode is null) return; 234 | TimeSpan currentPosition = currentTrackNode.Node.Position; 235 | TimeSpan duration = currentTrackNode.Node.Duration; 236 | 237 | actualAudioCrossfadingLength = (duration - currentPosition).TotalSeconds; 238 | 239 | if (crossfadingTimer is not null) crossfadingTimer.Dispose(); 240 | crossfadingTimer = new() { Interval = graphMonitorInterval, AutoReset = true }; 241 | crossfadingTimer.Elapsed += (_1, _2) => UpdateCrossfadingProgress(); 242 | 243 | if (previousTrackNode is not null) 244 | { 245 | DisposeTrackNode(previousTrackNode); 246 | previousTrackNode = null; 247 | } 248 | previousTrackNode = currentTrackNode; 249 | currentTrackNode = nextTrackNode; 250 | nextTrackNode = null; 251 | 252 | if (currentItemIndex != -1) previousItemIndex = currentItemIndex; 253 | currentItemIndex = preparedItemIndex; 254 | 255 | currentTrackNode.Node.OutgoingGain = 0.0d; 256 | currentTrackNode.Node.Start(); 257 | 258 | crossfadingTimer.Start(); 259 | } 260 | 261 | private void LeaveCrossfadingPhase() 262 | { 263 | isInCrossfasingPhase = false; 264 | 265 | if (crossfadingTimer.Enabled) crossfadingTimer.Stop(); 266 | crossfadingTimer.Dispose(); 267 | 268 | currentTrackNode.Node.OutgoingGain = 1.0d; 269 | 270 | previousTrackNode.Node.Stop(); 271 | } 272 | 273 | private void UpdateCrossfadingProgress() 274 | { 275 | if (currentTrackNode is null || previousTrackNode is null) return; 276 | TimeSpan currentPosition = currentTrackNode.Node.Position; 277 | 278 | double x = currentPosition.TotalSeconds / actualAudioCrossfadingLength; 279 | if (x < 0.0d) x = 0.0d; 280 | if (x > 1.0d) x = 1.0d; 281 | 282 | double quad = x < 0.5d ? 2 * x * x : -2 * x * x + 4 * x - 1; 283 | 284 | currentTrackNode.Node.OutgoingGain = quad; 285 | previousTrackNode.Node.OutgoingGain = 1 - quad; 286 | } 287 | 288 | private async void PrepareNextNode(int retryTime = 0) 289 | { 290 | if (retryTime >= 3) 291 | { 292 | nextTrackNodeStatus = NodeStatus.Failed; 293 | return; 294 | } 295 | try 296 | { 297 | nextTrackNodeStatus = NodeStatus.Preparing; 298 | ITrack nextTrack; 299 | if (UpNextPlaybackList?.Count > 0) 300 | { 301 | preparedItemIndex = -1; 302 | nextTrack = UpNextPlaybackList[0]; 303 | UpNextPlaybackList.RemoveAt(0); 304 | } 305 | else 306 | { 307 | int nextIndex = Methods.GetNextIndex( 308 | currentItemIndex == -1 ? previousItemIndex : currentItemIndex, 309 | OriginalPlaybackList.Count); 310 | preparedItemIndex = nextIndex; 311 | nextTrack = OriginalPlaybackList[PlaybackOrder[nextIndex]]; 312 | } 313 | nextTrackNode = await CreateTrackNode(nextTrack); 314 | } 315 | catch 316 | { 317 | if (resourceReloadTimer is not null) resourceReloadTimer.Dispose(); 318 | resourceReloadTimer = new() { AutoReset = false, Interval = 3000 }; 319 | resourceReloadTimer.Elapsed += (_1, _2) => PrepareNextNode(retryTime + 1); 320 | } 321 | } 322 | 323 | private void OnPlaybackModeChanged(PlaybackMode oldValue, PlaybackMode newValue) 324 | { 325 | if (oldValue == newValue) return; 326 | if (OriginalPlaybackList?.Count > 0 || UpNextPlaybackList?.Count > 0) 327 | { 328 | // Only when Shuffle is involved we need to make changes to playback order and indices 329 | if (oldValue == PlaybackMode.Shuffle || newValue == PlaybackMode.Shuffle) 330 | { 331 | int currentTrack = PlaybackOrder[currentItemIndex]; 332 | 333 | PlaybackOrder = newValue == PlaybackMode.Shuffle ? 334 | Methods.GenerateShuffledSequence(OriginalPlaybackList.Count) : 335 | Methods.GenerateAscendingSequence(OriginalPlaybackList.Count); 336 | 337 | if (currentItemIndex == -1) 338 | { 339 | previousItemIndex = (OriginalPlaybackList?.Count ?? 0) - 1; 340 | } 341 | else 342 | { 343 | currentItemIndex = oldValue == PlaybackMode.Shuffle ? 344 | currentTrack : 345 | PlaybackOrder.IndexOf(currentTrack); 346 | if (OriginalPlaybackList?.Count <= 0) previousItemIndex = -1; 347 | else previousItemIndex = Methods.GetPreviousIndex(currentItemIndex, OriginalPlaybackList.Count); 348 | } 349 | PlaybackQueueUpdated?.Invoke(this, EventArgs.Empty); 350 | } 351 | PlaybackModeChanged?.Invoke(this, EventArgs.Empty); 352 | } 353 | } 354 | 355 | private void SMTC_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args) 356 | { 357 | switch (args.Button) 358 | { 359 | case SystemMediaTransportControlsButton.Next: Next(); break; 360 | case SystemMediaTransportControlsButton.Previous: Previous(); break; 361 | case SystemMediaTransportControlsButton.Play: Play(); break; 362 | case SystemMediaTransportControlsButton.Pause: Pause(); break; 363 | default: break; 364 | } 365 | } 366 | 367 | private void DoxPlayer_PlaybackPositionChanged(object sender, PlaybackPositionChangedEventArgs e) 368 | { 369 | SystemMediaTransportControlsTimelineProperties timelineProperties = new() 370 | { 371 | MinSeekTime = TimeSpan.Zero, 372 | MaxSeekTime = e.Total, 373 | StartTime = TimeSpan.Zero, 374 | Position = e.Current, 375 | EndTime = e.Total 376 | }; 377 | SMTC?.UpdateTimelineProperties(timelineProperties); 378 | } 379 | 380 | private void DoxPlayer_PlaybackStatusChanged(object sender, PlaybackStatusChangedEventArgs e) 381 | { 382 | SMTC.PlaybackStatus = e.IsPlaying ? MediaPlaybackStatus.Playing : MediaPlaybackStatus.Paused; 383 | } 384 | 385 | private void DoxPlayer_PlaybackQueueUpdated(object sender, EventArgs e) 386 | { 387 | ITrack nextTrack = UpNextPlaybackList?.Count > 0 ? UpNextPlaybackList[0] : 388 | OriginalPlaybackList[PlaybackOrder[ 389 | Methods.GetNextIndex(currentItemIndex == -1 ? previousItemIndex : currentItemIndex, 390 | OriginalPlaybackList.Count) 391 | ]]; 392 | if (nextTrackNodeStatus != NodeStatus.Unavailable) 393 | { 394 | if (nextTrackNodeStatus == NodeStatus.Available && nextTrackNode.Track != nextTrack) 395 | { 396 | DisposeTrackNode(nextTrackNode); 397 | nextTrackNode = null; 398 | } 399 | nextTrackNodeStatus = NodeStatus.Unavailable; 400 | } 401 | } 402 | 403 | public void AddToUpNext(IEnumerable Items) 404 | { 405 | if (Items?.Count() <= 0) return; 406 | foreach (ITrack track in Items.Reverse()) 407 | { 408 | if (UpNextPlaybackList.Contains(track)) 409 | UpNextPlaybackList.Remove(track); 410 | UpNextPlaybackList.Insert(0, track); 411 | } 412 | PlaybackQueueUpdated?.Invoke(this, EventArgs.Empty); 413 | } 414 | 415 | public async void Next() 416 | { 417 | if (graphMonitor.Enabled) graphMonitor.Stop(); 418 | if (isInCrossfasingPhase == true) LeaveCrossfadingPhase(); 419 | int nextIndex = 0; 420 | if (nextTrackNodeStatus == NodeStatus.Available) nextIndex = preparedItemIndex; 421 | else 422 | { 423 | nextIndex = UpNextPlaybackList?.Count > 0 ? -1 : 424 | Methods.GetNextIndex(currentItemIndex == -1 ? previousItemIndex : currentItemIndex, 425 | OriginalPlaybackList.Count); 426 | ITrack nextTrack = nextIndex == -1 ? UpNextPlaybackList[0] : 427 | OriginalPlaybackList[PlaybackOrder[nextIndex]]; 428 | if (nextTrackNode is not null) DisposeTrackNode(nextTrackNode); 429 | nextTrackNode = await CreateTrackNode(nextTrack); 430 | if (nextIndex == -1) UpNextPlaybackList.RemoveAt(0); 431 | } 432 | 433 | if (previousTrackNode?.Track != OriginalPlaybackList[PlaybackOrder[previousItemIndex]]) 434 | { 435 | DisposeTrackNode(previousTrackNode); 436 | previousTrackNode = null; 437 | } 438 | 439 | if (currentItemIndex == -1) 440 | { 441 | DisposeTrackNode(currentTrackNode); 442 | currentTrackNode = null; 443 | } 444 | else 445 | { 446 | DisposeTrackNode(previousTrackNode); 447 | previousTrackNode = currentTrackNode; 448 | previousItemIndex = currentItemIndex; 449 | } 450 | 451 | currentItemIndex = nextIndex; 452 | currentTrackNode = nextTrackNode; 453 | currentTrackNode.Node.OutgoingGain = 1; 454 | nextTrackNode = null; 455 | 456 | if (IsPlaying == true) 457 | { 458 | currentTrackNode.Node.Start(); 459 | graphMonitor.Start(); 460 | } 461 | 462 | CurrentlyPlayingItemChanged?.Invoke(this, new() { CurrentTrack = currentTrackNode.Track }); 463 | PlaybackQueueUpdated?.Invoke(this, EventArgs.Empty); 464 | } 465 | 466 | public void Pause() 467 | { 468 | graphMonitor.Stop(); 469 | if (isInCrossfasingPhase) LeaveCrossfadingPhase(); 470 | currentTrackNode.Node.Stop(); 471 | PlaybackStatusChanged?.Invoke(this, new() { IsPlaying = false }); 472 | } 473 | 474 | public void Play() 475 | { 476 | currentTrackNode.Node.Start(); 477 | PlaybackStatusChanged?.Invoke(this, new() { IsPlaying = true }); 478 | graphMonitor.Start(); 479 | } 480 | 481 | public async void PlayCollection(IEnumerable Items, ITrack StartingItem, object PlaybackSource) 482 | { 483 | //Release previousTrackNode,currentTrackNode,nextTrackNode; 484 | if (previousTrackNode is not null) DisposeTrackNode(previousTrackNode); 485 | if (currentTrackNode is not null) DisposeTrackNode(currentTrackNode); 486 | if (nextTrackNode is not null) DisposeTrackNode(nextTrackNode); 487 | 488 | if (Items?.Count() <= 0) return; 489 | Stop(); 490 | this.PlaybackSource = PlaybackSource; 491 | 492 | UpNextPlaybackList = new(); 493 | OriginalPlaybackList = Items.ToList(); 494 | 495 | PlaybackOrder = PlaybackMode == PlaybackMode.Shuffle ? 496 | Methods.GenerateShuffledSequence(Items.Count()) : 497 | Methods.GenerateAscendingSequence(Items.Count()); 498 | 499 | int FirstItemIndex; 500 | if (StartingItem == null) FirstItemIndex = 0; 501 | else 502 | { 503 | int OriginalItemIndex = OriginalPlaybackList.IndexOf(StartingItem); 504 | if (PlaybackMode == PlaybackMode.Shuffle) FirstItemIndex = PlaybackOrder.IndexOf(OriginalItemIndex); 505 | else FirstItemIndex = OriginalItemIndex; 506 | } 507 | 508 | currentTrackNode = await CreateTrackNode(OriginalPlaybackList[PlaybackOrder[FirstItemIndex]]); 509 | currentTrackNode.Node.Start(); 510 | IsPlaying = true; 511 | graphMonitor.Start(); 512 | 513 | PlaybackQueueUpdated?.Invoke(this, null); 514 | CurrentlyPlayingItemChanged?.Invoke(this, new CurrentlyPlayingItemChangedEventArgs { CurrentTrack = CurrentItem}); 515 | } 516 | 517 | public void PlayPause() 518 | { 519 | if (IsPlaying ==false) 520 | Play(); 521 | else if (IsPlaying == true) 522 | Pause(); 523 | } 524 | 525 | public async void Previous() 526 | { 527 | if (graphMonitor.Enabled) graphMonitor.Stop(); 528 | if (isInCrossfasingPhase) LeaveCrossfadingPhase(); 529 | 530 | if (!IsDirectSwitchEnabled && currentTrackNode?.Node.Position.TotalSeconds > 3.0d) 531 | { 532 | currentTrackNode.Node.Seek(TimeSpan.Zero); 533 | return; 534 | } 535 | 536 | if (nextTrackNode is not null) 537 | { 538 | DisposeTrackNode(nextTrackNode); 539 | nextTrackNode = null; 540 | } 541 | 542 | if (currentItemIndex == -1) 543 | { 544 | DisposeTrackNode(currentTrackNode); 545 | currentTrackNode = null; 546 | } 547 | else 548 | { 549 | currentTrackNode.Node.Stop(); 550 | currentTrackNode.Node.Reset(); 551 | nextTrackNode = currentTrackNode; 552 | } 553 | 554 | ITrack previousTrack = OriginalPlaybackList[PlaybackOrder[previousItemIndex]]; 555 | if (previousTrackNode?.Track != previousTrack) 556 | { 557 | if (previousTrackNode is not null) DisposeTrackNode(previousTrackNode); 558 | previousTrackNode = await CreateTrackNode(previousTrack); 559 | } 560 | previousTrackNode.Node.OutgoingGain = 1.0d; 561 | currentTrackNode = previousTrackNode; 562 | 563 | currentItemIndex = previousItemIndex; 564 | previousItemIndex = Methods.GetPreviousIndex(currentItemIndex, OriginalPlaybackList.Count); 565 | 566 | previousTrackNode = null; 567 | if (IsPlaying == true) 568 | { 569 | currentTrackNode.Node.Start(); 570 | graphMonitor.Start(); 571 | } 572 | 573 | CurrentlyPlayingItemChanged?.Invoke(this, new() { CurrentTrack = currentTrackNode.Track }); 574 | PlaybackQueueUpdated?.Invoke(this, EventArgs.Empty); 575 | } 576 | 577 | public void RemoveTrack(ITrack targetTrack) 578 | { 579 | bool changed = false; 580 | if (UpNextPlaybackList.Contains(targetTrack)) 581 | { 582 | UpNextPlaybackList.Remove(targetTrack); 583 | changed = true; 584 | } 585 | else if (OriginalPlaybackList.Contains(targetTrack)) 586 | { 587 | int index = OriginalPlaybackList.IndexOf(targetTrack); 588 | int order = PlaybackOrder.IndexOf(index); 589 | PlaybackOrder.RemoveAt(order); 590 | for (int i = 0; i < PlaybackOrder.Count; i++) 591 | if (PlaybackOrder[i] > order) PlaybackOrder[i]--; 592 | changed = true; 593 | } 594 | if (changed) PlaybackQueueUpdated?.Invoke(this, EventArgs.Empty); 595 | } 596 | 597 | public void Seek(TimeSpan TargetPosition) 598 | { 599 | if (isInCrossfasingPhase) LeaveCrossfadingPhase(); 600 | currentTrackNode.Node.Seek(TargetPosition); 601 | 602 | TimeSpan duration = currentTrackNode.Node.Duration; 603 | if ((duration - TargetPosition).TotalSeconds < 20.0d) currentTrackNode.IsUserInterruptingCrossfading = true; 604 | } 605 | 606 | public async void SkipTo(ITrack targetTrack) 607 | { 608 | if (UpNextPlaybackList.Contains(targetTrack)) 609 | { 610 | int index = UpNextPlaybackList.IndexOf(targetTrack); 611 | if (index > 0) UpNextPlaybackList.RemoveRange(0, index); 612 | PlaybackQueueUpdated?.Invoke(this, EventArgs.Empty); // Remove? 613 | Next(); 614 | } 615 | else if (OriginalPlaybackList.Contains(targetTrack)) 616 | { 617 | UpNextPlaybackList.Clear(); 618 | int index = OriginalPlaybackList.IndexOf(targetTrack); 619 | int order = PlaybackOrder.IndexOf(index); 620 | graphMonitor.Stop(); 621 | 622 | if (previousTrackNode is not null) 623 | { 624 | DisposeTrackNode(previousTrackNode); 625 | previousTrackNode = null; 626 | } 627 | if (currentTrackNode is not null) 628 | { 629 | DisposeTrackNode(currentTrackNode); 630 | currentTrackNode = null; 631 | } 632 | if (nextTrackNode is not null) 633 | { 634 | DisposeTrackNode(nextTrackNode); 635 | nextTrackNode = null; 636 | } 637 | 638 | currentTrackNode = await CreateTrackNode(targetTrack); 639 | currentTrackNode.Node.Start(); 640 | IsPlaying = true; 641 | graphMonitor.Start(); 642 | 643 | PlaybackQueueUpdated?.Invoke(this, null); 644 | CurrentlyPlayingItemChanged?.Invoke(this, new CurrentlyPlayingItemChangedEventArgs { CurrentTrack = CurrentItem }); 645 | } 646 | } 647 | 648 | public void Stop() 649 | { 650 | DisposeTrackNode(currentTrackNode); currentTrackNode = null; 651 | DisposeTrackNode(previousTrackNode); previousTrackNode = null; 652 | DisposeTrackNode(nextTrackNode); nextTrackNode = null; 653 | 654 | OriginalPlaybackList?.Clear(); 655 | PlaybackOrder?.Clear(); 656 | UpNextPlaybackList?.Clear(); 657 | 658 | PlaybackEnded?.Invoke(this, EventArgs.Empty); 659 | } 660 | 661 | private sealed class TrackNode 662 | { 663 | public ITrack Track { get; set; } 664 | public MediaSourceAudioInputNode Node; 665 | 666 | // Judge if the track is longer than 60sec. 667 | public bool IsNodeAvailableForCrossfading => Track?.Duration.TotalSeconds > 60.0d; 668 | /// 669 | /// If user use methods like Seek in some scenarios we disable the crossfading 670 | /// 671 | public bool IsUserInterruptingCrossfading { get; set; } = false; 672 | } 673 | } 674 | } 675 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/IPlayer.cs: -------------------------------------------------------------------------------- 1 | using LyricEase.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace LyricEase 9 | { 10 | public interface IPlayer 11 | { 12 | double Volume { get; set; } 13 | bool IsDirectSwitchEnabled { get; set; } 14 | bool IsAudioCrossfadingEnabled { get; set; } 15 | int AudioCrossfadingLength { get; set; } 16 | SoundQuality SoundQuality { get; set; } 17 | PlaybackMode PlaybackMode { get; set; } 18 | 19 | bool? IsPlaying { get; } 20 | object PlaybackSource { get; } 21 | ITrack CurrentItem { get; } 22 | 23 | List OriginalPlaybackList { get; } 24 | List UpNextPlaybackList { get; } 25 | List PlaybackOrder { get; } 26 | List OrderedPlaybackList { get; } 27 | 28 | void PlayCollection(IEnumerable Items, ITrack StartingItem, object PlaybackSource); 29 | void AddToUpNext(IEnumerable Items); 30 | void Previous(); 31 | void Next(); 32 | void Play(); 33 | void Pause(); 34 | void PlayPause(); 35 | void Stop(); 36 | void Seek(TimeSpan TargetPosition); 37 | void SkipTo(ITrack targetTrack); 38 | void RemoveTrack(ITrack targetTrack); 39 | 40 | event EventHandler PlaybackStatusChanged; 41 | event EventHandler PlaybackModeChanged; 42 | event EventHandler PlaybackPositionChanged; 43 | event EventHandler CurrentlyPlayingItemChanged; 44 | event EventHandler PlaybackQueueUpdated; 45 | event EventHandler PlaybackEnded; 46 | event EventHandler PlaybackError; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/LyricEase.PlaybackEngine.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 9.0 6 | 7 | 8 | Debug 9 | AnyCPU 10 | {781CEC53-888E-40C3-BB88-A4F8488ABFE6} 11 | Library 12 | Properties 13 | LyricEase.PlaybackEngine 14 | LyricEase.PlaybackEngine 15 | en-US 16 | UAP 17 | 10.0.19041.0 18 | 10.0.17763.0 19 | 14 20 | 512 21 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 22 | 23 | 24 | AnyCPU 25 | true 26 | full 27 | false 28 | bin\Debug\ 29 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 30 | prompt 31 | 4 32 | 33 | 34 | AnyCPU 35 | pdbonly 36 | true 37 | bin\Release\ 38 | TRACE;NETFX_CORE;WINDOWS_UWP 39 | prompt 40 | 4 41 | 42 | 43 | x86 44 | true 45 | bin\x86\Debug\ 46 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 47 | ;2008 48 | full 49 | false 50 | prompt 51 | 52 | 53 | x86 54 | bin\x86\Release\ 55 | TRACE;NETFX_CORE;WINDOWS_UWP 56 | true 57 | ;2008 58 | pdbonly 59 | false 60 | prompt 61 | 62 | 63 | ARM 64 | true 65 | bin\ARM\Debug\ 66 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 67 | ;2008 68 | full 69 | false 70 | prompt 71 | 72 | 73 | ARM 74 | bin\ARM\Release\ 75 | TRACE;NETFX_CORE;WINDOWS_UWP 76 | true 77 | ;2008 78 | pdbonly 79 | false 80 | prompt 81 | 82 | 83 | ARM64 84 | true 85 | bin\ARM64\Debug\ 86 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 87 | ;2008 88 | full 89 | false 90 | prompt 91 | 92 | 93 | ARM64 94 | bin\ARM64\Release\ 95 | TRACE;NETFX_CORE;WINDOWS_UWP 96 | true 97 | ;2008 98 | pdbonly 99 | false 100 | prompt 101 | 102 | 103 | x64 104 | true 105 | bin\x64\Debug\ 106 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 107 | ;2008 108 | full 109 | false 110 | prompt 111 | 112 | 113 | x64 114 | bin\x64\Release\ 115 | TRACE;NETFX_CORE;WINDOWS_UWP 116 | true 117 | ;2008 118 | pdbonly 119 | false 120 | prompt 121 | 122 | 123 | PackageReference 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 6.2.12 138 | 139 | 140 | 141 | 14.0 142 | 143 | 144 | 151 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/Methods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LyricEase 8 | { 9 | internal static class Methods 10 | { 11 | private static Random _random = new Random(Guid.NewGuid().GetHashCode()); 12 | 13 | internal static List GenerateAscendingSequence(int Count) 14 | { 15 | List seq = new(); 16 | for (int i = 0; i < Count; i++) seq.Add(i); 17 | return seq; 18 | } 19 | 20 | internal static List GenerateShuffledSequence(int Count) 21 | { 22 | List seq = GenerateAscendingSequence(Count); 23 | seq.Sort((_1, _2) => (_random.NextDouble() - 0.5d).CompareTo(0d)); 24 | return seq; 25 | } 26 | 27 | internal static int GetPreviousIndex(int CurrentIndex, int CollectionLength) => (CurrentIndex - 1 + CollectionLength) % CollectionLength; 28 | 29 | internal static int GetNextIndex(int CurrentIndex, int CollectionLength) => (CurrentIndex + 1) % CollectionLength; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/Models.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Windows.Media.Core; 7 | 8 | namespace LyricEase.Models 9 | { 10 | public enum SoundQuality { Normal, High, VeryHigh, Lossless } 11 | 12 | public enum PlaybackMode { RepeatAll, RepeatOne, Shuffle } 13 | 14 | public enum NodeStatus { Unavailable, Preparing, Available, Failed } 15 | 16 | public interface ITrack 17 | { 18 | ulong TrackID { get; } 19 | string TitleString { get; } 20 | string ArtistString { get; } 21 | string AlbumString { get; } 22 | TimeSpan Duration { get; } 23 | string AlbumCoverImageUrl { get; } 24 | Task GetAudioMediaSource(SoundQuality soundQuality); 25 | } 26 | 27 | public sealed class PlaybackStatusChangedEventArgs 28 | { 29 | public bool IsPlaying { get; set; } 30 | } 31 | 32 | public sealed class PlaybackPositionChangedEventArgs 33 | { 34 | public TimeSpan Current { get; set; } 35 | public TimeSpan Total { get; set; } 36 | } 37 | 38 | public sealed class CurrentlyPlayingItemChangedEventArgs 39 | { 40 | public ITrack CurrentTrack { get; set; } 41 | } 42 | 43 | public sealed class PlaybackErrorEventArgs 44 | { 45 | public string Message { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/PlaybackEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LyricEase.PlaybackEngine 8 | { 9 | public class PlaybackEngine 10 | { 11 | private IPlayer _current; 12 | public IPlayer Current 13 | { 14 | get 15 | { 16 | if (_current == null) 17 | { 18 | _current = new DoxPlayer(); 19 | } 20 | return _current; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("LyricEase.PlaybackEngine")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("LyricEase.PlaybackEngine")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /LyricEase.PlaybackEngine/Properties/LyricEase.PlaybackEngine.rd.xml: -------------------------------------------------------------------------------- 1 | 2 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LyricEase.PlaybackEngine 2 | The open-source playback engine for UWP application LyricEase. Also available for other UWP projects. --------------------------------------------------------------------------------