如何在android中获取音乐文件(MP3)的采样率和频率?
我正在 Android 中开发音频播放器。所以我想添加播放歌曲的详细信息,即艺术家姓名、持续时间、比特率和采样频率。 我可以使用 MediaStore.Audio.Media 库获取音乐文件的艺术家姓名和持续时间。但我无法获取同一文件的比特率和采样频率。那么我怎样才能得到相同的呢?
据我所知,这可以通过使用本机库来完成。但不知道怎么办?那么有人可以帮助我吗?
I am developing audio player in android. So i want to add the details of the playing song i.e. Artist Name, Duration, Bit rate and sampling frequency.
I can get Artist Name and duration of a music file by using MediaStore.Audio.Media library
. But i am unable to get Bit rate and sampling frequency of the same file. So how can i get the same?
As i know, it can be done by using native library. But don't know how? So anyone can help me on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过将文件大小除以音频长度(以秒为单位)来估算它,例如,来自我的库中随机 AAC 编码的 M4A:
由于大多数音频文件都有一组已知的有效比特率级别,因此您可以使用它来步进将比特率调整到适合显示的级别。
You can approximate it by dividing the file size by the length of the audio in seconds, for instance, from a random AAC encoded M4A in my library:
Since most audio files have a known set of valid bitrate levels, you can use that to step the bit rate to the appropriate level for display.
我知道问题已经解决,但我有更好的方法来获得准确的答案
I know it's been resolved but i got much better way to get accurate answer
MediaMetadataRetriever 提供
METADATA_KEY_DURATION
,您可以将其除以比特率的文件大小。MediaMetadataRetriever offers
METADATA_KEY_DURATION
which you can divide with the file size for bitrate.