Fixes sound duration issue

main
Laurent 3 years ago
parent 47d17734c1
commit 406732e4b9
  1. 6
      LeCountdown/Sound/Sound.swift
  2. 8
      LeCountdown/Sound/SoundPlayer.swift
  3. 2
      LeCountdown/Subscription/AppGuard.swift
  4. 2
      LeCountdown/Utils/Preferences.swift
  5. 14
      LeCountdown/Views/HomeView.swift

@ -217,9 +217,9 @@ enum Sound: Int, CaseIterable, Identifiable, Localized {
static func computeSoundDurationsIfNecessary() {
Task {
for sound in Sound.allCases {
if Preferences.soundDurations[sound.rawValue] == nil {
if Preferences.soundDurations[sound.fileName] == nil {
if let duration = try? await sound.duration() {
Preferences.soundDurations[sound.rawValue] = duration
Preferences.soundDurations[sound.fileName] = duration
}
}
}
@ -227,7 +227,7 @@ enum Sound: Int, CaseIterable, Identifiable, Localized {
}
var formattedDuration: String {
if let duration = Preferences.soundDurations[self.rawValue] {
if let duration = Preferences.soundDurations[self.fileName] {
return duration.minuteSecond
} else {
return ""

@ -59,7 +59,7 @@ enum SoundPlayerError : Error {
player.prepareToPlay()
player.volume = 1.0
player.delegate = self
self._player = player
Logger.log("Plays \(url) on player: \(String(describing: self._player))")
@ -78,4 +78,10 @@ enum SoundPlayerError : Error {
Conductor.maestro.deactivateAudioSessionIfPossible()
}
func audioPlayerDecodeErrorDidOccur(_ player: AVAudioPlayer, error: Error?) {
if let error {
Logger.error(error)
}
}
}

@ -124,7 +124,7 @@ extension Notification.Name {
}
var isAuthorized: Bool {
return false //self.currentPlan != .none
return self.currentPlan != .none
}
var currentPlan: StorePlan {

@ -23,7 +23,7 @@ enum PreferenceKey: String {
class Preferences {
@UserDefault(PreferenceKey.countdowns.rawValue, defaultValue: [:]) static var savedCountdowns: [String : DateInterval]
@UserDefault(PreferenceKey.soundDurations.rawValue, defaultValue: [:]) static var soundDurations: [Int : TimeInterval]
@UserDefault(PreferenceKey.soundDurations.rawValue, defaultValue: [:]) static var soundDurations: [String : TimeInterval]
@UserDefault(PreferenceKey.lastSoundPlayed.rawValue, defaultValue: [:]) static var lastSelectedSound: [String : Int]
@UserDefault(PreferenceKey.tips.rawValue, defaultValue: nil) static var lastShownTip: Int?
@UserDefault(PreferenceKey.timerSiriTips.rawValue, defaultValue: []) static var timerSiriTips: Set<String>

@ -94,15 +94,11 @@ struct RegularHomeView: View {
}
fileprivate func _setColumnVisibility() {
do {
let count = try viewContext.count(entityName: "AbstractTimer")
if count > 0 {
self.columnVisibility = .detailOnly
} else {
self.columnVisibility = .automatic
}
} catch {
Logger.error(error)
let count = viewContext.count(entityName: "AbstractTimer")
if count > 0 {
self.columnVisibility = .detailOnly
} else {
self.columnVisibility = .automatic
}
}

Loading…
Cancel
Save