Skip to content

Commit

Permalink
fix(Notification::CustomSound): Fix issue loading MP3 file for custom…
Browse files Browse the repository at this point in the history
… sound.

Fixes SOUNDSWITCH-8R
  • Loading branch information
Belphemur committed Oct 3, 2021
1 parent 3f55b39 commit a46acb4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion SoundSwitch/Framework/Audio/CachedSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NAudio;
using NAudio.Wave;

namespace SoundSwitch.Framework.Audio
Expand All @@ -39,7 +40,7 @@ public CachedSound(string audioFileName)
}

FilePath = audioFileName;
using var audioFileReader = new AudioFileReader(audioFileName);
using var audioFileReader = GetReader(audioFileName);
// TODO: could add resampling in here if required
WaveFormat = audioFileReader.WaveFormat;
var wholeFile = new List<byte>((int)(audioFileReader.Length));
Expand All @@ -58,5 +59,17 @@ public CachedSound(MemoryStream stream, WaveFormat waveFormat)
WaveFormat = waveFormat;
AudioData = stream.ToArray();
}

private static WaveStream GetReader(string filename)
{
try
{
return new AudioFileReader(filename);
}
catch (MmException e)
{
return new MediaFoundationReader(filename);
}
}
}
}

0 comments on commit a46acb4

Please sign in to comment.