Jestem w trakcie budowy mojej pierwszej aplikacji IOS w szybkim tempie i utknąłem w pytaniu: Jak uzyskać długość (czas trwania) pliku muzycznego podczas przesyłania strumieniowego?Swift: AVPlayer - Jak uzyskać długość pliku mp3 z adresu URL?
Zrobiłem wiele badań, a także napisałem kilka kodów do rozwiązania tego problemu, ale wydaje mi się, że mój kod nie jest wystarczająco dobry.
func prepareAudio() {
audioLength = CMTimeGetSeconds(self.player.currentItem.asset.duration)
playerProgressSlider.maximumValue = CFloat(CMTimeGetSeconds(player.currentItem.duration))
playerProgressSlider.minimumValue = 0.0
playerProgressSlider.value = 0.0
showTotalSurahLength()
} // i prepare for get the duration and apply to UISlider here
func showTotalSurahLength(){
calculateSurahLength()
totalLengthOfAudioLabel.text = totalLengthOfAudio
} // get the right total length of audio file
func calculateSurahLength(){
var hour_ = abs(Int(audioLength/3600))
var minute_ = abs(Int((audioLength/60) % 60))
var second_ = abs(Int(audioLength % 60))
var hour = hour_ > 9 ? "\(hour_)" : "0\(hour_)"
var minute = minute_ > 9 ? "\(minute_)" : "0\(minute_)"
var second = second_ > 9 ? "\(second_)" : "0\(second_)"
totalLengthOfAudio = "\(hour):\(minute):\(second)"
} // I calculate the time and cover it
Każdy, kto tu kiedykolwiek zatrzymany z tego problemu, możesz dać mi jakiś sugeruje na to naprawić? Jestem bardzo nowy w Swift i wciąż uczę się doskonalić swoje umiejętności.
Dzięki,
Dzięki Chetan, spróbuję to załatwić Swiftowi :) –