Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/EPUBCore/FRBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class FRBook: NSObject {
return smils.smils.count > 0 ? true : false;
}

func title() -> String! {
return metadata.titles[0]
func title() -> String? {
return metadata.titles.first
}

// MARK: - Media Overlay Metadata
Expand Down
28 changes: 22 additions & 6 deletions Source/FolioReaderAudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate {
}
}
}

func _autoPlayNextChapter() {
// if user has stopped playing, dont play the next chapter
if isPlaying() == false { return }
Expand All @@ -151,7 +151,7 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate {
}
}
}

func playNextChapter(){
stopPlayerTimer()
// Wait for "currentPage" to update, then request to play audio
Expand Down Expand Up @@ -212,6 +212,7 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate {
// this is done to mitigate milisecond skips in the audio when changing fragments
if( player.currentTime < currentBeginTime || ( currentEndTime > 0 && player.currentTime > currentEndTime) ){
player.currentTime = currentBeginTime;
updateNowPlayingInfo()
}

player.play();
Expand Down Expand Up @@ -296,12 +297,12 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate {
}

// Get book title
if let title = book.metadata.titles.first {
if let title = book.title() {
songInfo[MPMediaItemPropertyAlbumTitle] = title
}

// Get chapter name
if let chapter = FolioReader.sharedInstance.readerCenter.getCurrentChapterName() {
if let chapter = getCurrentChapterName() {
songInfo[MPMediaItemPropertyTitle] = chapter
}

Expand All @@ -310,17 +311,32 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate {
songInfo[MPMediaItemPropertyArtist] = author.name
}

//
// Set player times
songInfo[MPMediaItemPropertyPlaybackDuration] = player.duration
songInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
// songInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = player.currentTime
songInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime ] = player.currentTime

// Set Audio Player info
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo

registerCommandsIfNeeded()
}

/**
Get Current Chapter Name

This is done here and not in ReaderCenter because even though `currentHref` is accurate,
the `currentPage` in ReaderCenter may not have updated just yet
*/
func getCurrentChapterName() -> String? {
for item in FolioReader.sharedInstance.readerSidePanel.tocItems {
if item.resource.href == currentHref {
return item.title
}
}
return nil
}

/**
Register commands if needed, check if it's registered to avoid register twice.
*/
Expand Down
4 changes: 1 addition & 3 deletions Source/FolioReaderConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ public class FolioReaderConfig: NSObject {

self.localizedHighlightsTitle = NSLocalizedString("Highlights", comment: "")
self.localizedHighlightsDateFormat = "MMM dd, YYYY | HH:mm"
self.localizedPlayMenu = NSLocalizedString("Start Reading", comment: "")
self.localizedPauseMenu = NSLocalizedString("Stop Reading", comment: "")
self.localizedHighlightMenu = NSLocalizedString("Highlight", comment: "")
self.localizedDefineMenu = NSLocalizedString("Define", comment: "")
self.localizedPlayMenu = NSLocalizedString("Play", comment: "")
self.localizedPauseMenu = NSLocalizedString("Pause", comment: "")
self.localizedDefineMenu = NSLocalizedString("Define", comment: "")
self.localizedFontMenuNight = NSLocalizedString("Night", comment: "")
self.localizedFontMenuDay = NSLocalizedString("Day", comment: "")
self.localizedReaderOnePageLeft = NSLocalizedString("1 page left", comment: "")
Expand Down