How to get an MP3 bit rate in SWIFT

∥☆過路亽.° 提交于 2019-12-10 23:08:47

问题


I am searching for a way of getting an mp3 bitrate like 128kbps or 320kbps for mp3 audio from url link.

I have a UITableView that loads a list of files from url list, and I would like to display an audio quality. I have tried using AVAudioPlayer and AVPlayer but no luck. Please help, how can I achieve this?

 do{
       let audioPlayer = try AVAudioPlayer(contentsOf:audioURL)
       print(audioPlayer.settings)
       if #available(iOS 10.0, *) {
                print(audioPlayer.format)
            } else {
                // Fallback on earlier versions
            }
        }catch {
            print("Error getting the audio file")
        }

回答1:


Just using the formula. It was that easy..

var bitrate: Int {      // kbps
        if size > 0 && duration > 0 {
            return size * 8 / 1000 / duration
        }



回答2:


I found a variable name sampleRate of AVAudioFormat class. Did you try to call audioPlayer.format.sampleRate?



来源:https://stackoverflow.com/questions/39715970/how-to-get-an-mp3-bit-rate-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!