Sto elaborando la mia prima app IOS in swift e rimango bloccato nella domanda: come ottenere la durata (durata) di un file musicale durante lo streaming?Swift: AVPlayer - Come ottenere la lunghezza del file mp3 dall'URL?
Ho fatto molte ricerche e anche una serie di codici per risolvere questo problema ma sembra che il mio codice non sia abbastanza buono.
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
qualcuno qui che mai bloccato con questo problema, potrebbe darmi qualche suggerisce per risolvere il problema? Sono molto nuovo in Swift e continuo a imparare a migliorare le mie capacità.
Grazie,
Grazie Chetan, proverò a coprire questo a Swift :) –