Failsafe for no usable audio devices

This commit is contained in:
JappaWakka 2023-02-09 13:44:35 +01:00
parent 96f6bc2a42
commit 3414d31b62
1 changed files with 11 additions and 4 deletions

View File

@ -346,7 +346,7 @@ Public Class MusicManager
If Not song Is Nothing Then If Not song Is Nothing Then
Logger.Debug($"Play song [{song.Name}]") Logger.Debug($"Play song [{song.Name}]")
If Not outputDevice Is Nothing Then If outputDevice IsNot Nothing Then
outputDevice.Dispose() outputDevice.Dispose()
End If End If
outputDevice = New WaveOutEvent() outputDevice = New WaveOutEvent()
@ -363,9 +363,16 @@ Public Class MusicManager
audioFileWMA = New MediaFoundationReader(song.Song) audioFileWMA = New MediaFoundationReader(song.Song)
_stream = New NAudio.Wave.WaveChannel32(New LoopStream(audioFileWMA, song.IsLoop)) _stream = New NAudio.Wave.WaveChannel32(New LoopStream(audioFileWMA, song.IsLoop))
End If End If
outputDevice.Init(_stream) Try
If Paused = False Then outputDevice.Init(_stream)
outputDevice.Play() 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 End If
_stream.Volume = Volume * MasterVolume _stream.Volume = Volume * MasterVolume
_currentSongName = song.Name _currentSongName = song.Name