我试图获取使用AVAudioRecorder(.m4a格式)录制的音频的持续时间,但以下代码打印出来" 0.0" :
let asset = AVURLAsset(URL: myAudioFileURL)
let audioDuration = asset.duration
print(Float(CMTimeGetSeconds(audioDuration)))
我做错了什么? 感谢
答案 0 :(得分:0)
do
{
let avAudioPlayer = try AVAudioPlayer (contentsOfURL:recordedAudioURL)
duration = avAudioPlayer.duration
let ms = Int((duration%1)*1000)
let sec = Int(duration%60)
let minutes = Int(duration / 60) % 60
let hours = Int(duration / 3600)
recordedAudioDuration.text = (NSString(format: "Dur: %0.2d:%0.2d:%0.2d.%0.3d",hours,minutes,sec,ms)) as String
}
catch{
print(error)
}