Skip to content

Commit

Permalink
Fix track duration for iTunes
Browse files Browse the repository at this point in the history
  • Loading branch information
xzzz9097 committed Sep 25, 2018
1 parent 0fdd666 commit 9344dc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Muse/Sources/Controllers/iTunesHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import iTunesLibrary
@objc optional var artist: String { get }
@objc optional var album: String { get }
@objc optional var duration: Double { get }
@objc optional var time: String { get }
@objc optional var artworks: [iTunesArtworkProtocol] { get }
@objc optional var loved: Bool { get }

Expand Down Expand Up @@ -149,7 +150,7 @@ class iTunesHelper: PlayerHelper, LikablePlayerHelper, InternalPlayerHelper, Lik

var trackDuration: Double {
// Return current track duration
return application?.currentTrack?.duration ?? 0
return Double(MMSSString: application?.currentTrack?.time ?? "") ?? 0
}

func internalScrub(to doubleValue: Double?, touching: Bool) {
Expand Down
13 changes: 13 additions & 0 deletions Muse/Sources/Extensions/Double+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ extension Double {
return "\(minutesString):\(secondsString)"
}

/**
Initializes a 'Double' from a MM:SS formatted 'String'
*/
init?(MMSSString: String) {
let digits = MMSSString.split(separator: ":").flatMap { Double($0) }

if digits.count == 2, let minutes = digits.first, let seconds = digits.last {
self = minutes * 60 + seconds
} else {
return nil
}
}

}

0 comments on commit 9344dc3

Please sign in to comment.