@@ -15,19 +15,19 @@ public protocol _AudioNavigatorDelegate: _MediaNavigatorDelegate {}
15
15
/// * Readium Audiobook
16
16
/// * ZAB (Zipped Audio Book)
17
17
///
18
- /// **WARNING:** This API is experimental and may change or be removed in a future release without
19
- /// notice. Use with caution.
20
- open class _AudioNavigator : _MediaNavigator , _AudioSessionUser , Loggable {
18
+ /// **WARNING:** This API is experimental and may change or be removed in a
19
+ /// future release without notice. Use with caution.
20
+ open class _AudioNavigator : _MediaNavigator , AudioSessionUser , Loggable {
21
21
public weak var delegate : _AudioNavigatorDelegate ?
22
22
23
- private let publication : Publication
23
+ public let publication : Publication
24
24
private let initialLocation : Locator ?
25
- public let audioConfiguration : _AudioSession . Configuration
25
+ public let audioConfiguration : AudioSession . Configuration
26
26
27
27
public init (
28
28
publication: Publication ,
29
29
initialLocation: Locator ? = nil ,
30
- audioConfig: _AudioSession . Configuration = . init(
30
+ audioConfig: AudioSession . Configuration = . init(
31
31
category: . playback,
32
32
mode: . default,
33
33
routeSharingPolicy: . longForm,
@@ -47,7 +47,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
47
47
}
48
48
49
49
deinit {
50
- _AudioSession . shared. end ( for: self )
50
+ AudioSession . shared. end ( for: self )
51
51
}
52
52
53
53
/// Current playback info.
@@ -106,7 +106,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
106
106
return
107
107
}
108
108
109
- let session = _AudioSession . shared
109
+ let session = AudioSession . shared
110
110
switch player. timeControlStatus {
111
111
case . paused:
112
112
session. user ( self , didChangePlaying: false )
@@ -135,7 +135,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
135
135
}
136
136
137
137
self . shouldPlayNextResource { playNext in
138
- if playNext, self . goToNextResource ( ) {
138
+ if playNext, self . goForward ( ) {
139
139
self . play ( )
140
140
}
141
141
}
@@ -281,28 +281,30 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
281
281
return go ( to: locator, animated: animated, completion: completion)
282
282
}
283
283
284
- @discardableResult
285
- public func goForward( animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
286
- false
284
+ /// Indicates whether the navigator can go to the next content portion
285
+ /// (e.g. page or audiobook resource).
286
+ public var canGoForward : Bool {
287
+ publication. readingOrder. indices. contains ( resourceIndex + 1 )
287
288
}
288
289
289
- @discardableResult
290
- public func goBackward( animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
291
- false
290
+ /// Indicates whether the navigator can go to the next content portion
291
+ /// (e.g. page or audiobook resource).
292
+ public var canGoBackward : Bool {
293
+ publication. readingOrder. indices. contains ( resourceIndex - 1 )
292
294
}
293
295
294
296
@discardableResult
295
- public func goToNextResource ( animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
297
+ public func goForward ( animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
296
298
goToResourceIndex ( resourceIndex + 1 , animated: animated, completion: completion)
297
299
}
298
300
299
301
@discardableResult
300
- public func goToPreviousResource ( animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
302
+ public func goBackward ( animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
301
303
goToResourceIndex ( resourceIndex - 1 , animated: animated, completion: completion)
302
304
}
303
305
304
306
@discardableResult
305
- public func goToResourceIndex( _ index: Int , animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
307
+ private func goToResourceIndex( _ index: Int , animated: Bool = false , completion: @escaping ( ) -> Void = { } ) -> Bool {
306
308
guard publication. readingOrder. indices ~= index else {
307
309
return false
308
310
}
@@ -339,7 +341,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
339
341
}
340
342
341
343
public func play( ) {
342
- _AudioSession . shared. start ( with: self , isPlaying: false )
344
+ AudioSession . shared. start ( with: self , isPlaying: false )
343
345
344
346
if player. currentItem == nil , let location = initialLocation {
345
347
go ( to: location)
@@ -355,7 +357,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
355
357
player. seek ( to: CMTime ( seconds: time, preferredTimescale: 1000 ) )
356
358
}
357
359
358
- public func seek( relatively delta: Double ) {
360
+ public func seek( by delta: Double ) {
359
361
seek ( to: currentTime + delta)
360
362
}
361
363
}
0 commit comments