forked from shadowfacts/Tusker
Don't let let audio session tokens be double consumed
This commit is contained in:
parent
8322d3a36c
commit
ce99352e90
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue