Skip to content

Commit

Permalink
Swap to NAudio for much smaller distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmagee committed Nov 24, 2024
1 parent 2694457 commit 846e82d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/Dota2Helper.Desktop/Dota2Helper.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Dota2Helper/Dota2Helper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<PackageReference Include="Avalonia.Xaml.Interactions.Events" Version="11.2.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="FluentIcons.Avalonia" Version="1.1.265" />
<PackageReference Include="LibVLCSharp" Version="3.9.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="ValveKeyValue" Version="0.12.0.391" />
</ItemGroup>

Expand Down
30 changes: 12 additions & 18 deletions src/Dota2Helper/Features/Audio/AudioService.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Dota2Helper.Features.Settings;
using LibVLCSharp.Shared;
using NAudio.Wave;

namespace Dota2Helper.Features.Audio;

public interface IAudioService
{
void Play(string audioFile);
}

public class AudioService : BackgroundWorker, IAudioService
public class AudioService : BackgroundWorker, IAudioService, IDisposable
{
readonly SettingsService _settingsService;
LibVLC LibVlc { get; } = new();
readonly MediaPlayer _mediaPlayer;
readonly WaveOutEvent _mediaPlayer;

Queue<string> AudioQueue { get; } = new();
ConcurrentQueue<string> AudioQueue { get; } = new();

public AudioService(SettingsService settingsService)
{
_settingsService = settingsService;
_mediaPlayer = new MediaPlayer(LibVlc);
_mediaPlayer = new WaveOutEvent();
RunWorkerAsync();
}

Expand All @@ -43,16 +39,14 @@ protected override async void OnDoWork(DoWorkEventArgs e)
{
try
{
var uri = new Uri(audioFile, UriKind.RelativeOrAbsolute);
var fromType = uri.IsAbsoluteUri ? FromType.FromLocation : FromType.FromPath;

using(var media = new Media(LibVlc, audioFile, fromType))
using (var audioFileReader = new AudioFileReader(audioFile))
{
_mediaPlayer.Volume = (int) _settingsService.Settings.Volume;
_mediaPlayer.Play(media);
_mediaPlayer.Init(audioFileReader);
_mediaPlayer.Volume = (float)(_settingsService.Settings.Volume / 100.0);
_mediaPlayer.Play();
}
}
catch(Exception)
catch (Exception)
{

}
Expand Down
6 changes: 6 additions & 0 deletions src/Dota2Helper/Features/Audio/IAudioService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Dota2Helper.Features.Audio;

public interface IAudioService
{
void Play(string audioFile);
}

0 comments on commit 846e82d

Please sign in to comment.