Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #36 from kjantzer/fix/27-now-playing-info
Browse files Browse the repository at this point in the history
Fixing now playing info elapsed time and current chapter
  • Loading branch information
hebertialmeida committed Jan 15, 2016
2 parents 2417825 + e40dc88 commit 4b2e159
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
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

0 comments on commit 4b2e159

Please sign in to comment.