From b873be1e293d87c5f0d9a0e5ce89ae6e1520cc70 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 19 Apr 2023 15:00:55 +0200 Subject: [PATCH] Throws exception if player returns false when playing at time --- LeCountdown/Sound/DelaySoundPlayer.swift | 4 ++++ LeCountdown/Sound/SoundPlayer.swift | 1 + 2 files changed, 5 insertions(+) diff --git a/LeCountdown/Sound/DelaySoundPlayer.swift b/LeCountdown/Sound/DelaySoundPlayer.swift index 15dd023..9e26f8b 100644 --- a/LeCountdown/Sound/DelaySoundPlayer.swift +++ b/LeCountdown/Sound/DelaySoundPlayer.swift @@ -48,6 +48,10 @@ import AVFoundation let time: TimeInterval = self._player.deviceCurrentTime + duration let result = self._player.play(atTime: time) FileLogger.log("play \(String(describing: self._player.url)) >atTime: \(time), result = \(result), isMainThread = \(Thread.isMainThread)") + + if !result { + throw SoundPlayerError.playReturnedFalse + } } func stop() { diff --git a/LeCountdown/Sound/SoundPlayer.swift b/LeCountdown/Sound/SoundPlayer.swift index d7e6e5e..ed289c7 100644 --- a/LeCountdown/Sound/SoundPlayer.swift +++ b/LeCountdown/Sound/SoundPlayer.swift @@ -31,6 +31,7 @@ struct SoundFile { enum SoundPlayerError : Error { case missingResourceError(file: SoundFile) case badFileName(name: String) + case playReturnedFalse } @objc class SoundPlayer: NSObject, AVAudioPlayerDelegate {