diff --git a/Tusker/AudioSessionCoordinator.swift b/Tusker/AudioSessionCoordinator.swift index f2cea65710..ef310613e6 100644 --- a/Tusker/AudioSessionCoordinator.swift +++ b/Tusker/AudioSessionCoordinator.swift @@ -34,6 +34,8 @@ final class AudioSessionCoordinator { } func endPlayback(token: Token, completionHandler: (() -> Void)? = nil) { + // mark the token as consumed, so when it's deinited we don't try to end again + token.consumed = true // the enqueued block can't retain token, since it may be being dealloc'd right now let mode = token.mode queue.async { @@ -70,13 +72,16 @@ final class AudioSessionCoordinator { final class Token { let mode: Mode + fileprivate var consumed = false init(mode: Mode) { self.mode = mode } deinit { - AudioSessionCoordinator.shared.endPlayback(token: self) + if !consumed { + AudioSessionCoordinator.shared.endPlayback(token: self) + } } }