音频持续时间 returns 0.0
Audio duration returns 0.0
我试图获取我使用 AVAudioRecorder(.m4a 格式)录制的音频的持续时间,但以下代码打印出“0.0”:
let asset = AVURLAsset(URL: myAudioFileURL)
let audioDuration = asset.duration
print(Float(CMTimeGetSeconds(audioDuration)))
我做错了什么?
谢谢
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)
}
我试图获取我使用 AVAudioRecorder(.m4a 格式)录制的音频的持续时间,但以下代码打印出“0.0”:
let asset = AVURLAsset(URL: myAudioFileURL)
let audioDuration = asset.duration
print(Float(CMTimeGetSeconds(audioDuration)))
我做错了什么? 谢谢
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)
}