Skip to content

Commit

Permalink
Use NAdio for playing sounds (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
i2van authored Sep 23, 2024
1 parent 0cc4799 commit 51ced0d
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 28 deletions.
34 changes: 27 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ on: [push, pull_request]

env:
PROJECT: Hourglass
NAUDIO: Hourglass.NAudio
NAUDIO_ARTIFACT: NAudioHourglassPack
CONFIGURATION_RELEASE: Release
CONFIGURATION_RELEASE_PORTABLE: Release Portable
FW: net48
COMPRESSION_LEVEL: 9
RETENTION_DAYS: 30

jobs:
Expand All @@ -26,8 +30,8 @@ jobs:

# Restore

- name: Restore ${{env.PROJECT}}.Test
run: dotnet restore ${{env.PROJECT}}.Test\${{env.PROJECT}}.Test.csproj
- name: Restore ${{env.PROJECT}}.sln
run: dotnet restore ${{env.PROJECT}}.sln

# Build

Expand All @@ -53,19 +57,35 @@ jobs:
# Upload artifacts

- name: Publish ${{env.PROJECT}} ${{env.CONFIGURATION_RELEASE}} Installer
uses: actions/upload-artifact@v4.3.0
uses: actions/upload-artifact@v4.4.0
with:
name: ${{env.PROJECT}}Installer
path: |
${{env.PROJECT}}.Bundle/bin/${{env.CONFIGURATION_RELEASE}}/${{env.PROJECT}}Installer.exe
compression-level: ${{env.COMPRESSION_LEVEL}}
retention-days: ${{env.RETENTION_DAYS}}

- name: Publish ${{env.PROJECT}} ${{env.CONFIGURATION_RELEASE_PORTABLE}}
uses: actions/upload-artifact@v4.3.0
uses: actions/upload-artifact@v4.4.0
with:
name: ${{env.PROJECT}}Portable
path: |
${{env.PROJECT}}/bin/${{env.CONFIGURATION_RELEASE_PORTABLE}}/net48/${{env.PROJECT}}.exe
${{env.PROJECT}}/bin/${{env.CONFIGURATION_RELEASE_PORTABLE}}/net48/${{env.PROJECT}}.exe.config
${{env.PROJECT}}/bin/${{env.CONFIGURATION_RELEASE_PORTABLE}}/net48/ngen-${{env.PROJECT}}.bat
${{env.PROJECT}}/bin/${{env.CONFIGURATION_RELEASE_PORTABLE}}/${{env.FW}}/${{env.PROJECT}}.exe
${{env.PROJECT}}/bin/${{env.CONFIGURATION_RELEASE_PORTABLE}}/${{env.FW}}/${{env.PROJECT}}.exe.config
${{env.PROJECT}}/bin/${{env.CONFIGURATION_RELEASE_PORTABLE}}/${{env.FW}}/ngen-${{env.PROJECT}}.bat
compression-level: ${{env.COMPRESSION_LEVEL}}
retention-days: ${{env.RETENTION_DAYS}}

- name: Publish ${{env.NAUDIO}}
uses: actions/upload-artifact@v4.4.0
with:
name: ${{env.NAUDIO_ARTIFACT}}
path: |
${{env.NAUDIO}}/bin/${{env.CONFIGURATION_RELEASE}}/${{env.FW}}/Hourglass.NAudio.dll
${{env.NAUDIO}}/bin/${{env.CONFIGURATION_RELEASE}}/${{env.FW}}/Microsoft.Win32.Registry.dll
${{env.NAUDIO}}/bin/${{env.CONFIGURATION_RELEASE}}/${{env.FW}}/NAudio.dll
${{env.NAUDIO}}/bin/${{env.CONFIGURATION_RELEASE}}/${{env.FW}}/NAudio.Core.dll
${{env.NAUDIO}}/bin/${{env.CONFIGURATION_RELEASE}}/${{env.FW}}/NAudio.Wasapi.dll
${{env.NAUDIO}}/bin/${{env.CONFIGURATION_RELEASE}}/${{env.FW}}/NAudio.WinMM.dll
compression-level: ${{env.COMPRESSION_LEVEL}}
retention-days: ${{env.RETENTION_DAYS}}
12 changes: 12 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The original **Hourglass** FAQ can be found [here](https://chris.dziemborowicz.c
- [What command-line arguments does the Hourglass accept?](#what-command-line-arguments-does-the-hourglass-accept)
- [How to speed up the Portable Hourglass startup?](#how-to-speed-up-the-portable-hourglass-startup)
- [What should I do if the Hourglass does not start?](#what-should-i-do-if-the-hourglass-does-not-start)
- [What should I do if there is no notification sound?](#what-should-i-do-if-there-is-no-notification-sound)

## How do I start, stop, pause or resume a timer?

Expand Down Expand Up @@ -371,3 +372,14 @@ cmd /k dir "C:\Users\%USERNAME%\AppData\Local\Chris_Dziemborowicz*"
The settings are stored into the corresponding `hourglass.EXE` subdirectories.

The **Hourglass Portable** keeps settings next to the executable.

## What should I do if there is no notification sound?

Some audio files could not be played for Windows with no [Windows Media Player](https://en.wikipedia.org/wiki/Windows_Media_Player) installed.
To fix this, download the [NAudioHourglassPack](https://github.com/i2van/hourglass/releases/latest) and upzip its content to the **Hourglass** folder.

Audio files supported:

- `.aiff`
- `.mp3`
- `.wav`
47 changes: 47 additions & 0 deletions Hourglass.NAudio/AudioPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;

using NAudio.Wave;

using Hourglass.Windows.Audio;

namespace Hourglass.NAudio;

public class AudioPlayer: IAudioPlayer
{
private readonly WaveOutEvent _waveOutEvent = new();

private AudioFileReader? _audioFile;

public AudioPlayer(EventHandler stoppedEventHandler) =>
_waveOutEvent.PlaybackStopped += (s, e) => stoppedEventHandler(s, e);

public void Open(string uri)
{
_audioFile?.Dispose();
_audioFile = null;
_audioFile = new AudioFileReader(uri);

_waveOutEvent.Init(_audioFile);
}

public void Play()
{
_audioFile!.Position = 0;
_waveOutEvent.Play();
}

public void Stop()
{
_waveOutEvent.Stop();

_audioFile?.Dispose();
_audioFile = null;
}

public void Dispose()
{
Stop();

_waveOutEvent.Dispose();
}
}
28 changes: 28 additions & 0 deletions Hourglass.NAudio/Hourglass.NAudio.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<AssemblyTitle>Hourglass NAudio</AssemblyTitle>
<Product>Hourglass NAudio</Product>
<Company>Ivan Ivon</Company>
<NeutralLanguage>en-US</NeutralLanguage>
<Copyright>Copyright © $([System.DateTime]::Now.Year) Ivan Ivon</Copyright>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DisableDiagnosticTracing>true</DisableDiagnosticTracing>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Hourglass\Hourglass.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NAudio">
<Version>2.2.1</Version>
</PackageReference>
</ItemGroup>
</Project>
62 changes: 62 additions & 0 deletions Hourglass.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,136 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "Hourglass.Bundle", "Hourgla
{45E7F177-CA65-468A-B528-330A13D931D4} = {45E7F177-CA65-468A-B528-330A13D931D4}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hourglass.NAudio", "Hourglass.NAudio\Hourglass.NAudio.csproj", "{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Portable|Any CPU = Debug Portable|Any CPU
Debug Portable|Mixed Platforms = Debug Portable|Mixed Platforms
Debug Portable|x86 = Debug Portable|x86
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release Portable|Any CPU = Release Portable|Any CPU
Release Portable|Mixed Platforms = Release Portable|Mixed Platforms
Release Portable|x86 = Release Portable|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug Portable|Any CPU.ActiveCfg = Debug Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug Portable|Any CPU.Build.0 = Debug Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug Portable|Mixed Platforms.ActiveCfg = Debug Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug Portable|Mixed Platforms.Build.0 = Debug Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug Portable|x86.ActiveCfg = Debug Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug Portable|x86.Build.0 = Debug Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Debug|x86.ActiveCfg = Debug|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release Portable|Any CPU.ActiveCfg = Release Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release Portable|Any CPU.Build.0 = Release Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release Portable|Mixed Platforms.ActiveCfg = Release Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release Portable|Mixed Platforms.Build.0 = Release Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release Portable|x86.ActiveCfg = Release Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release Portable|x86.Build.0 = Release Portable|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release|Any CPU.Build.0 = Release|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{4E327D2C-9171-4596-82C5-A9C3CF5028E4}.Release|x86.ActiveCfg = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug Portable|Any CPU.ActiveCfg = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug Portable|Any CPU.Build.0 = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug Portable|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug Portable|Mixed Platforms.Build.0 = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug Portable|x86.ActiveCfg = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug Portable|x86.Build.0 = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Debug|x86.ActiveCfg = Debug|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release Portable|Any CPU.ActiveCfg = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release Portable|Any CPU.Build.0 = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release Portable|Mixed Platforms.ActiveCfg = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release Portable|Mixed Platforms.Build.0 = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release Portable|x86.ActiveCfg = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release Portable|x86.Build.0 = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release|Any CPU.Build.0 = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CBE74854-0344-4606-A854-BFA719896A98}.Release|x86.ActiveCfg = Release|Any CPU
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug Portable|Any CPU.ActiveCfg = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug Portable|Any CPU.Build.0 = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug Portable|Mixed Platforms.ActiveCfg = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug Portable|x86.ActiveCfg = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug Portable|x86.Build.0 = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug|Any CPU.ActiveCfg = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug|Any CPU.Build.0 = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug|Mixed Platforms.Build.0 = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug|x86.ActiveCfg = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Debug|x86.Build.0 = Debug|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release Portable|Any CPU.ActiveCfg = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release Portable|Any CPU.Build.0 = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release Portable|Mixed Platforms.ActiveCfg = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release Portable|x86.ActiveCfg = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release Portable|x86.Build.0 = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release|Any CPU.ActiveCfg = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release|Any CPU.Build.0 = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release|Mixed Platforms.ActiveCfg = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release|Mixed Platforms.Build.0 = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release|x86.ActiveCfg = Release|x86
{45E7F177-CA65-468A-B528-330A13D931D4}.Release|x86.Build.0 = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug Portable|Any CPU.ActiveCfg = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug Portable|Any CPU.Build.0 = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug Portable|Mixed Platforms.ActiveCfg = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug Portable|x86.ActiveCfg = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug Portable|x86.Build.0 = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug|Any CPU.ActiveCfg = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug|Any CPU.Build.0 = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug|Mixed Platforms.Build.0 = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug|x86.ActiveCfg = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Debug|x86.Build.0 = Debug|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release Portable|Any CPU.ActiveCfg = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release Portable|Any CPU.Build.0 = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release Portable|Mixed Platforms.ActiveCfg = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release Portable|x86.ActiveCfg = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release Portable|x86.Build.0 = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release|Any CPU.ActiveCfg = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release|Any CPU.Build.0 = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release|Mixed Platforms.ActiveCfg = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release|Mixed Platforms.Build.0 = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release|x86.ActiveCfg = Release|x86
{F1D002C9-CFC9-40FB-84AF-96E7AEC26E0B}.Release|x86.Build.0 = Release|x86
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug Portable|Any CPU.ActiveCfg = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug Portable|Any CPU.Build.0 = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug Portable|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug Portable|Mixed Platforms.Build.0 = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug Portable|x86.ActiveCfg = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug Portable|x86.Build.0 = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug|x86.ActiveCfg = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Debug|x86.Build.0 = Debug|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release Portable|Any CPU.ActiveCfg = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release Portable|Any CPU.Build.0 = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release Portable|Mixed Platforms.ActiveCfg = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release Portable|Mixed Platforms.Build.0 = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release Portable|x86.ActiveCfg = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release Portable|x86.Build.0 = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release|Any CPU.Build.0 = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release|x86.ActiveCfg = Release|Any CPU
{F125E1F8-BC1A-4525-9A49-A0189AC91C2C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 3 additions & 3 deletions Hourglass/Properties/PortableSettingsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// --------------------------------------------------------------------------------------------------------------------
#if PORTABLE

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PortableSettingsProvider.cs" company="Chris Dziemborowicz">
// Copyright (c) Chris Dziemborowicz. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

#if PORTABLE

namespace Hourglass.Properties
{
using System;
Expand Down
7 changes: 7 additions & 0 deletions Hourglass/Resources/Usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ Options:
.wav
.wma

If NAudioHourglassPack is used for playing a sound (see FAQ), the sound
file supported extensions are:

.aiff
.mp3
.wav

--loop-sound on|off|last
Loops the sound that plays when the timer expires.

Expand Down
30 changes: 30 additions & 0 deletions Hourglass/Windows/Audio/AudioPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Windows.Media;

namespace Hourglass.Windows.Audio;

internal class AudioPlayer: IAudioPlayer
{
private readonly MediaPlayer _mediaPlayer = new();

public AudioPlayer(EventHandler stoppedEventHandler) =>
_mediaPlayer.MediaEnded += stoppedEventHandler;

public void Open(string uri) =>
_mediaPlayer.Open(new(uri));

public void Play()
{
_mediaPlayer.Position = TimeSpan.Zero;
_mediaPlayer.Play();
}

public void Stop()
{
_mediaPlayer.Stop();
_mediaPlayer.Close();
}

public void Dispose() =>
Stop();
}
Loading

0 comments on commit 51ced0d

Please sign in to comment.