Skip to content

Commit

Permalink
Fixes Cycling audio device
Browse files Browse the repository at this point in the history
Wrong device was used. Fixes #93
  • Loading branch information
Antoine Aflalo committed May 1, 2016
1 parent 978b1f4 commit 4f6e67b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
6 changes: 3 additions & 3 deletions SoundSwitch.Tests/PlaybackDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ public void TestCycleConsoleAudioDevice()
audioMoqI.VerifyGet(a => a.Id);
audioMoqII.VerifyGet(a => a.Id);
listerMoq.Verify(l => l.GetPlaybackDevices());
audioMoqII.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Console)));
audioMoqII.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Multimedia)));
audioMoqI.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Console)));
audioMoqI.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Multimedia)));
}

[Test]
Expand Down Expand Up @@ -234,7 +234,7 @@ public void TestCycleCommunicationsAudioDevice()
audioMoqI.VerifyGet(a => a.Id);
audioMoqII.VerifyGet(a => a.Id);
listerMoq.Verify(l => l.GetPlaybackDevices());
audioMoqI.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.All)));
audioMoqII.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.All)));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion SoundSwitch.Tests/RecordingDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void TestCycleCommunicationsAudioDevice()
audioMoqI.VerifyGet(a => a.Id);
audioMoqII.VerifyGet(a => a.Id);
listerMoq.Verify(l => l.GetRecordingDevices());
audioMoqII.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.All)));
audioMoqI.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.All)));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ public abstract class ADeviceCycler : IDeviceCycler
/// </summary>
/// <param name="audioDevices"></param>
/// <param name="type"></param>
/// <param name="lastDevice"></param>
/// <returns></returns>
protected IAudioDevice GetNextDevice(ICollection<IAudioDevice> audioDevices, AudioDeviceType type)
{
IAudioDevice lastDevice;
if (!_lastDevices.TryGetValue(type, out lastDevice))
{
return audioDevices.First();
}
_lastDevices.TryGetValue(type, out lastDevice);

var defaultDev = audioDevices.FirstOrDefault(device => device.Id == lastDevice.Id) ??
var defaultDev = lastDevice ??
audioDevices.FirstOrDefault(device => device.IsDefault(Role.Console)) ??
audioDevices.Last();
var next = audioDevices.SkipWhile((device, i) => !Equals(device, defaultDev)).Skip(1).FirstOrDefault() ??
Expand Down

0 comments on commit 4f6e67b

Please sign in to comment.