AVAssetReader 采样率
如何使用 AVAssetReader 计算从 iPod 库获取的歌曲的采样率。我想我可以很容易地获得样本的数量(无论如何我已经成功地读取了样本..),但我不知道在哪里可以获得歌曲的长度(以秒为单位)。
请注意,MPMediaItem 没有媒体项长度的属性,也许还有另一种方法通过此 API 来获取项目的长度?
How do I calculate the samplerate of a song obtained from the iPod Library using AVAssetReader. I think I can pretty easily get the amount of samples, ( I am already successfully reading the samples anyways.. ), but I do not know where I can obtain the length ( in seconds ) of the song.
Note that MPMediaItem has no property for the length of the Media Item, maybe there is another way through this API to get the length of the item?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
MPMediaItem
来获取长度。查看MPMediaItemPropertyPlaybackDuration
属性键。文档指出:You can use
MPMediaItem
to get the length. Have a look at theMPMediaItemPropertyPlaybackDuration
property key. The docs state:如果您实际上仍然想知道采样率,那么可以这样做:
一旦您拥有了感兴趣的
AVAssetTrack
,您就可以获取AudioStreamBasicDescription
并检查它以找到原始采样率。错误检查省略...
if you are actually still wondering about the sample rate, it is done like so:
Once you have your
AVAssetTrack
you are interested in, you can get theAudioStreamBasicDescription
and inspect that to find the original sample rate.error checking omitted...