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) {
|
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
|
// the enqueued block can't retain token, since it may be being dealloc'd right now
|
||||||
let mode = token.mode
|
let mode = token.mode
|
||||||
queue.async {
|
queue.async {
|
||||||
|
@ -70,15 +72,18 @@ final class AudioSessionCoordinator {
|
||||||
|
|
||||||
final class Token {
|
final class Token {
|
||||||
let mode: Mode
|
let mode: Mode
|
||||||
|
fileprivate var consumed = false
|
||||||
|
|
||||||
init(mode: Mode) {
|
init(mode: Mode) {
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
if !consumed {
|
||||||
AudioSessionCoordinator.shared.endPlayback(token: self)
|
AudioSessionCoordinator.shared.endPlayback(token: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
case video
|
case video
|
||||||
|
|
Loading…
Reference in New Issue