Skip to content
Permalink
Browse files

Add chapter title to now playing info

  • Loading branch information...
GianniCarlo committed Aug 31, 2019
1 parent ebf89db commit aa744cb27071a85bd71b017f4af503b7fc2941d3
@@ -1264,6 +1264,7 @@
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = S7TJSJXWUZ;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
enabled = 1;
@@ -1772,10 +1773,12 @@
CODE_SIGN_ENTITLEMENTS = BookPlayerWatch/BookPlayerWatch.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
IBSC_MODULE = BookPlayerWatch_Extension;
INFOPLIST_FILE = BookPlayerWatch/Info.plist;
MARKETING_VERSION = 3.5.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.watchkitapp;
@@ -1802,10 +1805,12 @@
CODE_SIGN_ENTITLEMENTS = BookPlayerWatch/BookPlayerWatch.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
IBSC_MODULE = BookPlayerWatch_Extension;
INFOPLIST_FILE = BookPlayerWatch/Info.plist;
MARKETING_VERSION = 3.5.1;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.watchkitapp;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1830,10 +1835,12 @@
CODE_SIGN_ENTITLEMENTS = BookPlayerWatch/BookPlayerWatch.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
IBSC_MODULE = BookPlayerWatch_Extension;
INFOPLIST_FILE = BookPlayerWatch/Info.plist;
MARKETING_VERSION = 3.5.1;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.watchkitapp;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1856,10 +1863,12 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "BookPlayerWatch Extension/BookPlayerWatch Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BookPlayerWatch Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 3.5.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.watchkitapp.watchkitextension;
@@ -1884,10 +1893,12 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "BookPlayerWatch Extension/BookPlayerWatch Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BookPlayerWatch Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 3.5.1;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.watchkitapp.watchkitextension;
PRODUCT_NAME = "${TARGET_NAME}";
@@ -1910,10 +1921,12 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "BookPlayerWatch Extension/BookPlayerWatch Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BookPlayerWatch Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 3.5.1;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.watchkitapp.watchkitextension;
PRODUCT_NAME = "${TARGET_NAME}";
@@ -2146,6 +2159,8 @@
CLANG_ENABLE_CODE_COVERAGE = NO;
CODE_SIGN_ENTITLEMENTS = BookPlayer/BookPlayer.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 2;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = S7TJSJXWUZ;
FRAMEWORK_SEARCH_PATHS = (
@@ -2156,8 +2171,10 @@
INFOPLIST_FILE = BookPlayer/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.5.1;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer;
PRODUCT_NAME = BookPlayer;
PROVISIONING_PROFILE_SPECIFIER = "BookPlayer 3 with CarPlay";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
@@ -2173,6 +2190,8 @@
CLANG_ENABLE_CODE_COVERAGE = NO;
CODE_SIGN_ENTITLEMENTS = BookPlayer/BookPlayer.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -2182,8 +2201,10 @@
INFOPLIST_FILE = BookPlayer/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.5.1;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer;
PRODUCT_NAME = BookPlayer;
PROVISIONING_PROFILE_SPECIFIER = "BookPlayer 3 with CarPlay";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
@@ -2343,11 +2364,13 @@
CODE_SIGN_ENTITLEMENTS = BookPlayerWidget/BookPlayerWidget.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = BookPlayerWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 3.5.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.BookPlayerWidget;
@@ -2370,11 +2393,13 @@
CODE_SIGN_ENTITLEMENTS = BookPlayerWidget/BookPlayerWidget.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = BookPlayerWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 3.5.1;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.BookPlayerWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -2395,11 +2420,13 @@
CODE_SIGN_ENTITLEMENTS = BookPlayerWidget/BookPlayerWidget.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = BookPlayerWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 3.5.1;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer.BookPlayerWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -2469,6 +2496,8 @@
CLANG_ENABLE_CODE_COVERAGE = NO;
CODE_SIGN_ENTITLEMENTS = BookPlayer/BookPlayer.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = S7TJSJXWUZ;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -2478,8 +2507,10 @@
INFOPLIST_FILE = BookPlayer/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.5.1;
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer;
PRODUCT_NAME = BookPlayer;
PROVISIONING_PROFILE_SPECIFIER = "BookPlayer 3 with CarPlay";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
@@ -172,7 +172,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.5.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
@@ -189,7 +189,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
@@ -30,58 +30,6 @@ class PlayerControlsViewController: PlayerContainerViewController, UIGestureReco
}
}

private var currentTimeInContext: TimeInterval {
guard let book = self.book, !book.isFault else {
return 0.0
}

guard
self.prefersChapterContext,
book.hasChapters,
let start = book.currentChapter?.start else {
return book.currentTime
}

return book.currentTime - start
}

private var maxTimeInContext: TimeInterval {
guard let book = self.book, !book.isFault else {
return 0.0
}

guard
self.prefersChapterContext,
book.hasChapters,
let duration = book.currentChapter?.duration else {
let time = self.prefersRemainingTime
? self.currentTimeInContext - book.duration
: book.duration
return time
}

let time = self.prefersRemainingTime
? self.currentTimeInContext - duration
: duration

return time
}

private var durationTimeInContext: TimeInterval {
guard let book = self.book, !book.isFault else {
return 0.0
}

guard
self.prefersChapterContext,
book.hasChapters,
let duration = book.currentChapter?.duration else {
return book.duration
}

return duration
}

private var prefersChapterContext = UserDefaults.standard.bool(forKey: Constants.UserDefaults.chapterContextEnabled.rawValue)

private var prefersRemainingTime = UserDefaults.standard.bool(forKey: Constants.UserDefaults.remainingTimeEnabled.rawValue)
@@ -147,9 +95,11 @@ class PlayerControlsViewController: PlayerContainerViewController, UIGestureReco
}

if !self.progressSlider.isTracking {
self.currentTimeLabel.text = self.formatTime(self.currentTimeInContext)
self.currentTimeLabel.accessibilityLabel = String(describing: "Current Chapter Time: " + VoiceOverService.secondsToMinutes(self.currentTimeInContext))
self.maxTimeButton.setTitle(self.formatTime(self.maxTimeInContext), for: .normal)
self.currentTimeLabel.text = self.formatTime(book.currentTimeInContext(self.prefersChapterContext))
self.currentTimeLabel.accessibilityLabel = String(describing: "Current Chapter Time: " + VoiceOverService.secondsToMinutes(book.currentTimeInContext(self.prefersChapterContext)))

let maxTimeInContext = book.maxTimeInContext(self.prefersChapterContext, self.prefersRemainingTime)
self.maxTimeButton.setTitle(self.formatTime(maxTimeInContext), for: .normal)
let prefix = self.prefersRemainingTime
? "Remaining Chapter Time: "
: "Chapter duration: "
@@ -169,6 +119,7 @@ class PlayerControlsViewController: PlayerContainerViewController, UIGestureReco
let prefix = self.prefersRemainingTime
? "Remaining Book Time: "
: "Book duration: "
let maxTimeInContext = book.maxTimeInContext(self.prefersChapterContext, self.prefersRemainingTime)
self.maxTimeButton.accessibilityLabel = String(describing: prefix + VoiceOverService.secondsToMinutes(maxTimeInContext))
}

@@ -272,7 +223,8 @@ class PlayerControlsViewController: PlayerContainerViewController, UIGestureReco
}

if self.prefersRemainingTime {
self.maxTimeButton.setTitle(self.formatTime(newTimeToDisplay - self.durationTimeInContext), for: .normal)
let durationTimeInContext = book.durationTimeInContext(self.prefersChapterContext)
self.maxTimeButton.setTitle(self.formatTime(newTimeToDisplay - durationTimeInContext), for: .normal)
}
}
}
@@ -63,13 +63,12 @@ class PlayerManager: NSObject {
DispatchQueue.main.async(execute: {
// Set book metadata for lockscreen and control center
self.nowPlayingInfo = [
MPMediaItemPropertyTitle: book.title as Any,
MPMediaItemPropertyArtist: book.author as Any,
MPMediaItemPropertyPlaybackDuration: audioplayer.duration,
MPNowPlayingInfoPropertyDefaultPlaybackRate: self.speed,
MPNowPlayingInfoPropertyPlaybackProgress: audioplayer.currentTime / audioplayer.duration
MPNowPlayingInfoPropertyDefaultPlaybackRate: self.speed
]

self.setNowPlayingBookTitle()
self.setNowPlayingBookTime()

self.nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: book.artwork.size,
requestHandler: { (_) -> UIImage in
book.artwork
@@ -119,7 +118,7 @@ class PlayerManager: NSObject {
] as [String: Any])
}

self.nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = audioplayer.currentTime
self.setNowPlayingBookTime()

MPNowPlayingInfoCenter.default().nowPlayingInfo = self.nowPlayingInfo

@@ -137,6 +136,7 @@ class PlayerManager: NSObject {
if let currentChapter = book.currentChapter,
book.currentTime > currentChapter.end || book.currentTime < currentChapter.start {
book.updateCurrentChapter()
self.setNowPlayingBookTitle()
NotificationCenter.default.post(name: .chapterChange, object: nil, userInfo: nil)
}

@@ -242,6 +242,37 @@ class PlayerManager: NSObject {
MPRemoteCommandCenter.shared().skipForwardCommand.preferredIntervals = [newValue] as [NSNumber]
}
}

func setNowPlayingBookTitle() {
guard let currentBook = self.currentBook, self.audioPlayer != nil else {
return
}

if currentBook.hasChapters, let currentChapter = currentBook.currentChapter {
self.nowPlayingInfo[MPMediaItemPropertyTitle] = currentChapter.title
self.nowPlayingInfo[MPMediaItemPropertyArtist] = currentBook.title
self.nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = currentBook.author
} else {
self.nowPlayingInfo[MPMediaItemPropertyTitle] = currentBook.title
self.nowPlayingInfo[MPMediaItemPropertyArtist] = currentBook.author
self.nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = nil
}
}

func setNowPlayingBookTime() {
guard let currentBook = self.currentBook, self.audioPlayer != nil else {
return
}

let prefersChapterContext = UserDefaults.standard.bool(forKey: Constants.UserDefaults.chapterContextEnabled.rawValue)
let currentTimeInContext = currentBook.currentTimeInContext(prefersChapterContext)
let maxTimeInContext = currentBook.maxTimeInContext(prefersChapterContext, false)

self.nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = self.speed
self.nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentTimeInContext
self.nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = maxTimeInContext
self.nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackProgress] = currentTimeInContext / maxTimeInContext
}
}

// MARK: - Seek Controls
@@ -345,9 +376,7 @@ extension PlayerManager {
// Set last Play date
currentBook.updatePlayDate()

self.nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = 1.0
self.nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = audioplayer.currentTime
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
self.setNowPlayingBookTitle()

DispatchQueue.main.async {
CarPlayManager.shared.setNowPlayingInfo(with: currentBook)
@@ -381,7 +410,7 @@ extension PlayerManager {
audioplayer.pause()

self.nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = 0.0
self.nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = audioplayer.currentTime
self.setNowPlayingBookTime()
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo

UserDefaults.standard.set(Date(), forKey: "\(Constants.UserDefaults.lastPauseTime)_\(currentBook.identifier!)")

0 comments on commit aa744cb

Please sign in to comment.
You can’t perform that action at this time.