From 3414d31b6221fd496fc9166ae12ec15027e88302 Mon Sep 17 00:00:00 2001 From: JappaWakka Date: Thu, 9 Feb 2023 13:44:35 +0100 Subject: [PATCH] Failsafe for no usable audio devices --- P3D/Resources/Sound/MusicManager.vb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/P3D/Resources/Sound/MusicManager.vb b/P3D/Resources/Sound/MusicManager.vb index be93737f4..76c048496 100644 --- a/P3D/Resources/Sound/MusicManager.vb +++ b/P3D/Resources/Sound/MusicManager.vb @@ -346,7 +346,7 @@ Public Class MusicManager If Not song Is Nothing Then Logger.Debug($"Play song [{song.Name}]") - If Not outputDevice Is Nothing Then + If outputDevice IsNot Nothing Then outputDevice.Dispose() End If outputDevice = New WaveOutEvent() @@ -363,9 +363,16 @@ Public Class MusicManager audioFileWMA = New MediaFoundationReader(song.Song) _stream = New NAudio.Wave.WaveChannel32(New LoopStream(audioFileWMA, song.IsLoop)) End If - outputDevice.Init(_stream) - If Paused = False Then - outputDevice.Play() + Try + outputDevice.Init(_stream) + Catch ex As Exception + Logger.Log(Logger.LogTypes.ErrorMessage, "No usable audio device") + outputDevice = Nothing + End Try + If outputDevice IsNot Nothing Then + If Paused = False Then + outputDevice.Play() + End If End If _stream.Volume = Volume * MasterVolume _currentSongName = song.Name