Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created January 2, 2025 06:18
Show Gist options
  • Save jubishop/2990f064a1f624b660ddcbf034921d72 to your computer and use it in GitHub Desktop.
Save jubishop/2990f064a1f624b660ddcbf034921d72 to your computer and use it in GitHub Desktop.
private var duration: CMTime? {
guard let timeComponents = rssEpisode.iTunes.duration?.split(separator: ":").reversed(),
timeComponents.count <= 3
else { return CMTime.zero }
var seconds = 0
for (position, value) in timeComponents.enumerated() {
guard let value = Int(value) else { return CMTime.zero }
var multiplier = 1
for _ in 0..<position { multiplier *= 60 }
seconds += multiplier * value
}
return CMTime.inSeconds(Double(seconds))
}
@jubishop
Copy link
Author

jubishop commented Jan 2, 2025

  private var duration: CMTime? {
    guard let timeComponents = rssEpisode.iTunes.duration?.split(separator: ":").reversed(),
      timeComponents.count <= 3
    else { return CMTime.zero }

    var seconds = 0
    var multiplier = 1
    for value in timeComponents {
      guard let value = Int(value) else { return CMTime.zero }
      seconds += multiplier * value
      multiplier *= 60
    }
    return CMTime.inSeconds(Double(seconds))
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment