From b2ab7a9bbe7afd0a98670c15a143f48f4c156ad4 Mon Sep 17 00:00:00 2001 From: Kevin Jantzer Date: Wed, 13 Jan 2016 11:05:29 -0800 Subject: [PATCH 1/3] Updated icons and added next/prev buttons for #26 Next and prev buttons are buggy due to #30 --- Source/FolioReaderAudioPlayer.swift | 4 ++-- Source/FolioReaderConfig.swift | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/FolioReaderAudioPlayer.swift b/Source/FolioReaderAudioPlayer.swift index 4d2472be9..5858897e5 100644 --- a/Source/FolioReaderAudioPlayer.swift +++ b/Source/FolioReaderAudioPlayer.swift @@ -133,7 +133,7 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate { } } } - + func _autoPlayNextChapter() { // if user has stopped playing, dont play the next chapter if isPlaying() == false { return } @@ -151,7 +151,7 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate { } } } - + func playNextChapter(){ stopPlayerTimer() // Wait for "currentPage" to update, then request to play audio diff --git a/Source/FolioReaderConfig.swift b/Source/FolioReaderConfig.swift index 02dd1ec1e..7ada9e704 100755 --- a/Source/FolioReaderConfig.swift +++ b/Source/FolioReaderConfig.swift @@ -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: "") From e6bde996a1015687db199b2b5640c3dfb52ec6b9 Mon Sep 17 00:00:00 2001 From: Kevin Jantzer Date: Fri, 15 Jan 2016 09:01:14 -0800 Subject: [PATCH 2/3] Adjusting book.title method --- Source/EPUBCore/FRBook.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/EPUBCore/FRBook.swift b/Source/EPUBCore/FRBook.swift index aada8106e..c8d6a9e32 100755 --- a/Source/EPUBCore/FRBook.swift +++ b/Source/EPUBCore/FRBook.swift @@ -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 From e40dc885d1e81c0e4dc11ac75e7b1b2b594f69e0 Mon Sep 17 00:00:00 2001 From: Kevin Jantzer Date: Fri, 15 Jan 2016 09:05:43 -0800 Subject: [PATCH 3/3] Fixing now playing info elapsed time and current chapter Chapter name was not updating when playing and chapters changed. --- Source/FolioReaderAudioPlayer.swift | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Source/FolioReaderAudioPlayer.swift b/Source/FolioReaderAudioPlayer.swift index 5858897e5..63ffa3a7d 100644 --- a/Source/FolioReaderAudioPlayer.swift +++ b/Source/FolioReaderAudioPlayer.swift @@ -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(); @@ -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 } @@ -310,10 +311,10 @@ 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 @@ -321,6 +322,21 @@ class FolioReaderAudioPlayer: NSObject, AVAudioPlayerDelegate { 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. */