如何获得一个MP3比特率在SWIFT

时间:2023-01-24 11:51:14

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

我正在寻找一种从url链接中获取mp3音频的方法,比如128kbps或320kbps。

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?

我有一个UITableView,它从url列表加载文件列表,我想显示音频质量。我试过使用AVAudioPlayer和AVPlayer,但是没有运气。请帮忙,我怎样才能做到这一点?

 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")
        }

2 个解决方案

#1


1  

Just using the formula. It was that easy..

只是用公式。它是那么容易. .

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

#2


0  

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

我找到了AVAudioFormat类的变量名样本。是否尝试调用audioPlayer.format.sampleRate?

#1


1  

Just using the formula. It was that easy..

只是用公式。它是那么容易. .

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

#2


0  

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

我找到了AVAudioFormat类的变量名样本。是否尝试调用audioPlayer.format.sampleRate?