Skip to content

Commit 4113b1a

Browse files
authored
Add an audiobook player in the Test App (#290)
1 parent 192fd36 commit 4113b1a

30 files changed

+1423
-742
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. Take a look
66

77
## [Unreleased]
88

9+
* Support for Xcode 15.
10+
911
### Added
1012

1113
#### Navigator
@@ -27,6 +29,7 @@ All notable changes to this project will be documented in this file. Take a look
2729

2830
#### Navigator
2931

32+
* `AudioSession` and `NowPlayingInfo` are now stable!
3033
* You need to provide the configuration of the Audio Session to the constructor of `PublicationSpeechSynthesizer`, instead of `AVTTSEngine`.
3134

3235

Sources/Navigator/Audiobook/AudioNavigator.swift

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ public protocol _AudioNavigatorDelegate: _MediaNavigatorDelegate {}
1515
/// * Readium Audiobook
1616
/// * ZAB (Zipped Audio Book)
1717
///
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 {
2121
public weak var delegate: _AudioNavigatorDelegate?
2222

23-
private let publication: Publication
23+
public let publication: Publication
2424
private let initialLocation: Locator?
25-
public let audioConfiguration: _AudioSession.Configuration
25+
public let audioConfiguration: AudioSession.Configuration
2626

2727
public init(
2828
publication: Publication,
2929
initialLocation: Locator? = nil,
30-
audioConfig: _AudioSession.Configuration = .init(
30+
audioConfig: AudioSession.Configuration = .init(
3131
category: .playback,
3232
mode: .default,
3333
routeSharingPolicy: .longForm,
@@ -47,7 +47,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
4747
}
4848

4949
deinit {
50-
_AudioSession.shared.end(for: self)
50+
AudioSession.shared.end(for: self)
5151
}
5252

5353
/// Current playback info.
@@ -106,7 +106,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
106106
return
107107
}
108108

109-
let session = _AudioSession.shared
109+
let session = AudioSession.shared
110110
switch player.timeControlStatus {
111111
case .paused:
112112
session.user(self, didChangePlaying: false)
@@ -135,7 +135,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
135135
}
136136

137137
self.shouldPlayNextResource { playNext in
138-
if playNext, self.goToNextResource() {
138+
if playNext, self.goForward() {
139139
self.play()
140140
}
141141
}
@@ -281,28 +281,30 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
281281
return go(to: locator, animated: animated, completion: completion)
282282
}
283283

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)
287288
}
288289

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)
292294
}
293295

294296
@discardableResult
295-
public func goToNextResource(animated: Bool = false, completion: @escaping () -> Void = {}) -> Bool {
297+
public func goForward(animated: Bool = false, completion: @escaping () -> Void = {}) -> Bool {
296298
goToResourceIndex(resourceIndex + 1, animated: animated, completion: completion)
297299
}
298300

299301
@discardableResult
300-
public func goToPreviousResource(animated: Bool = false, completion: @escaping () -> Void = {}) -> Bool {
302+
public func goBackward(animated: Bool = false, completion: @escaping () -> Void = {}) -> Bool {
301303
goToResourceIndex(resourceIndex - 1, animated: animated, completion: completion)
302304
}
303305

304306
@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 {
306308
guard publication.readingOrder.indices ~= index else {
307309
return false
308310
}
@@ -339,7 +341,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
339341
}
340342

341343
public func play() {
342-
_AudioSession.shared.start(with: self, isPlaying: false)
344+
AudioSession.shared.start(with: self, isPlaying: false)
343345

344346
if player.currentItem == nil, let location = initialLocation {
345347
go(to: location)
@@ -355,7 +357,7 @@ open class _AudioNavigator: _MediaNavigator, _AudioSessionUser, Loggable {
355357
player.seek(to: CMTime(seconds: time, preferredTimescale: 1000))
356358
}
357359

358-
public func seek(relatively delta: Double) {
360+
public func seek(by delta: Double) {
359361
seek(to: currentTime + delta)
360362
}
361363
}

Sources/Navigator/CBZ/CBZNavigatorViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open class CBZNavigatorViewController: UIViewController, VisualNavigator, Loggab
1919

2020
public weak var delegate: CBZNavigatorDelegate?
2121

22-
private let publication: Publication
22+
public let publication: Publication
2323
private let initialIndex: Int
2424

2525
private let pageViewController: UIPageViewController

0 commit comments

Comments
 (0)